From 1b427df778eb31d8d249ba38d8da523714587533 Mon Sep 17 00:00:00 2001 From: CHOUHAN-MOHIT <92783072+CHOUHAN-MOHIT@users.noreply.github.com> Date: Wed, 31 Aug 2022 20:27:25 +0530 Subject: [PATCH 1/3] add an option text field in add job form and some other fixes, 1. add an optional text field in the form. when the user selects other in position the text field will appear to specify the position. 2. some modifications to make it more responsive. --- applications/job_posting/views.py | 22 +++++++-- templates/job_posting/post.html | 78 ++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 22 deletions(-) diff --git a/applications/job_posting/views.py b/applications/job_posting/views.py index 739279d6..0a224d89 100644 --- a/applications/job_posting/views.py +++ b/applications/job_posting/views.py @@ -101,10 +101,24 @@ def post(request): join_date = request.POST.get('join_date') if request.POST.get('join_date') else None person = User.objects.get(username=str(request.user)) - insert = Posting.objects.create(type=type, position=position, company=company, location=location, desc=desc, - stipend=stipend, exp_req=exp_req, last_date=last_date, join_date=join_date, - tenure=tenure, link=link, posting_date=date.today(), - person=person, active=True) + if position == "Other": + position = request.POST.get('jobrole') + + Posting.objects.create( + type=type, + position=position, + company=company, + location=location, + desc=desc, + stipend=stipend, + exp_req=exp_req, + last_date=last_date, + join_date=join_date, + tenure=tenure, + link=link, + posting_date=date.today(), + person=person, + active=True ) messages.success(request, "Job opportunity added successfully!") except Exception as e: diff --git a/templates/job_posting/post.html b/templates/job_posting/post.html index 88e399cd..829585cb 100644 --- a/templates/job_posting/post.html +++ b/templates/job_posting/post.html @@ -42,45 +42,50 @@
-
+
-
+
- + - - + + + + - + - + + -
+
+ + +
-
+
-
+
@@ -102,17 +107,23 @@
-
+
- +
+ + + .00 +
+
-
+
-
+
@@ -139,6 +150,37 @@
+{% block javascript %} + +{% endblock javascript %} {% include 'globals/footer.html' %} From 0324a5945ac5297e5944cb803c89ac2243d5d0a9 Mon Sep 17 00:00:00 2001 From: CHOUHAN-MOHIT <92783072+CHOUHAN-MOHIT@users.noreply.github.com> Date: Thu, 1 Sep 2022 17:07:47 +0530 Subject: [PATCH 2/3] changes in model change the model name from posting to job. also changed some attributes name like from position to job_role , from type to job_type etc. made changes in views.py to incorporate above changes. also some changes for better code readability. --- applications/job_posting/admin.py | 8 +- applications/job_posting/models.py | 14 +- applications/job_posting/urls.py | 6 +- applications/job_posting/views.py | 136 +++++++++--------- static/job_posting/home.css | 46 ++++++ .../job_posting/{post.html => add_job.html} | 28 ++-- .../job_posting/{home.html => index.html} | 105 ++++---------- 7 files changed, 172 insertions(+), 171 deletions(-) create mode 100644 static/job_posting/home.css rename templates/job_posting/{post.html => add_job.html} (88%) rename templates/job_posting/{home.html => index.html} (85%) diff --git a/applications/job_posting/admin.py b/applications/job_posting/admin.py index 9a196b3f..14e9548c 100644 --- a/applications/job_posting/admin.py +++ b/applications/job_posting/admin.py @@ -1,9 +1,9 @@ from django.contrib import admin # Register your models here. -from .models import (Posting) +from .models import (Job) -class PostingAdmin(admin.ModelAdmin): - list_display = ('position', 'company', 'type', 'last_date') +class JobAdmin(admin.ModelAdmin): + list_display = ('job_role', 'org_name', 'job_type', 'last_date') -admin.site.register(Posting, PostingAdmin) +admin.site.register(Job, JobAdmin) diff --git a/applications/job_posting/models.py b/applications/job_posting/models.py index bf9646cd..d38a060f 100644 --- a/applications/job_posting/models.py +++ b/applications/job_posting/models.py @@ -2,21 +2,21 @@ from django.contrib.auth.models import User -class Posting(models.Model): - position = models.CharField(max_length=20, null=False) - company = models.CharField(max_length=25, null=False) - type = models.CharField(max_length=20) +class Job(models.Model): + job_role = models.CharField(max_length=20, null=False)#position + org_name = models.CharField(max_length=25, null=False)#company + job_type = models.CharField(max_length=20)#type link = models.URLField(max_length=1000) stipend = models.IntegerField(null=True, blank=True) exp_req = models.IntegerField(null=True, blank=True) tenure = models.IntegerField(null=True, blank=True) last_date = models.DateField(null=True, blank=True) join_date = models.DateField(null=True, blank=True) - desc = models.CharField(max_length=300, help_text="Brief Description of job profile", null=True, blank=True) - person = models.ForeignKey(User, on_delete=models.CASCADE) + job_desc = models.CharField(max_length=300, help_text="Brief Description of job profile", null=True, blank=True)#desc + added_by = models.ForeignKey(User, on_delete=models.CASCADE)#person posting_date = models.DateField() location = models.CharField(max_length=30, null=False) active = models.BooleanField(null=False, default=True) def __str__(self): - return self.position + " by " + self.company + return self.position + " at " + self.company diff --git a/applications/job_posting/urls.py b/applications/job_posting/urls.py index 5a260ee3..dc7e35a0 100644 --- a/applications/job_posting/urls.py +++ b/applications/job_posting/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path('', views.index, name='index'), - path('post/', views.post, name='post'), - path('filter/', views.filter, name='filter'), - re_path(r'^del/(?P[0-9]+)/$', views.del1, name='del1'), + path('post/', views.post_opportunity, name='post'), + path('filter/', views.filter_jobs, name='filter'), + re_path(r'^del/(?P[0-9]+)/$', views.delete_job, name='delete'), ] diff --git a/applications/job_posting/views.py b/applications/job_posting/views.py index 0a224d89..67caf0e9 100644 --- a/applications/job_posting/views.py +++ b/applications/job_posting/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from .models import Posting +from .models import Job from datetime import date from django.contrib import messages from django.shortcuts import redirect @@ -15,101 +15,106 @@ def is_superuser(user): @login_required def index(request): - posts = Posting.objects.all().filter(active=True).order_by('-posting_date') - total = len(posts) - page = request.GET.get('page', 1) - if posts: - paginator = Paginator(posts, 10) + jobs = Job.objects.all().filter(active=True).order_by('-posting_date') + total_jobs = len(jobs) + + page_no = request.GET.get('page', 1) + if jobs: + paginator = Paginator(jobs, 10) try: - ls2 = paginator.page(page) + current_page = paginator.page(page_no) except PageNotAnInteger: - ls2 = paginator.page(1) + current_page = paginator.page(1) except EmptyPage: - ls2 = paginator.page(paginator.num_pages) - if request.user.is_superuser: - ls = [] - for i in posts: - ls.append(i.person) - ls1 = zip(ls2, ls) - return render(request, "job_posting/home.html", {'ls1': ls1, 'ls2': ls2, 'total': total}) - else: - ls = [] - for i in posts: - ls.append(i.person) - ls1 = zip(ls2, ls) - return render(request, "job_posting/home.html", {'ls1': ls1, 'ls2': ls2, 'total': total}) + current_page = paginator.page(paginator.num_pages) + + # if request.user.is_superuser: + # ls = [] + # for i in jobs: + # ls.append(i.person) + # ls1 = zip(current_page, ls) + # return render(request, "job_posting/index.html", {'ls1': ls1, 'current_page': current_page, 'total': total}) + # else: + # ls = [] + # for i in jobs: + # ls.append(i.person) + # ls1 = zip(current_page, ls) + + return render(request, "job_posting/index.html", {'job_list': current_page, 'current_page': current_page, 'total': total_jobs}) else: - ls1 = [] - return render(request, "job_posting/home.html", {'ls1': ls1, 'total': total}) + empty_list = [] + return render(request, "job_posting/index.html", {'job_list': empty_list, 'total': total_jobs}) @login_required -def filter(request): +def filter_jobs(request): viewname = "filter" - position = request.POST.get('position') + job_role = request.POST.get('job_role') page = request.GET.get('page', 1) - type = request.POST.get('type') - - if position != 'all' and type != 'all': - posts = Posting.objects.filter(position=position, type=type, active=True).order_by('-posting_date') - elif position != 'all' and type == 'all': - posts = Posting.objects.filter(position=position, active=True).order_by('-posting_date') - elif position == 'all' and type != 'all': - posts = Posting.objects.filter(type=type, active=True).order_by('-posting_date') + job_type = request.POST.get('job_type') + + #if user choose other in role here than no jobs will be shown :( + if job_role != 'all' and type != 'all': + jobs = Job.objects.filter(job_role=job_role, job_type=job_type, active=True).order_by('-posting_date') + elif job_role != 'all' and type == 'all': + jobs = Job.objects.filter(job_role=job_role, active=True).order_by('-posting_date') + elif job_role == 'all' and type != 'all': + jobs = Job.objects.filter(type=type, active=True).order_by('-posting_date') else: return redirect('jobs:index', permanent=True) - if posts: - messages.success(request, "Found " + str(posts.count()) + " posts matching your query!") - paginator = Paginator(posts, 10) + if jobs: + messages.success(request, "Found " + str(jobs.count()) + " jobs matching your query!") + + paginator = Paginator(jobs, 10) try: - ls2 = paginator.page(page) + current_page = paginator.page(page) except PageNotAnInteger: - ls2 = paginator.page(1) + current_page = paginator.page(1) except EmptyPage: - ls2 = paginator.page(paginator.num_pages) + current_page = paginator.page(paginator.num_pages) - ls = [] - for i in posts: - ls.append(i.person) - ls1 = zip(ls2, ls) - return render(request, "job_posting/home.html", {'ls1': ls1, 'ls2': ls2, 'viewname': viewname}) + # ls = [] + # for i in posts: + # ls.append(i.person) + # ls1 = zip(ls2, ls) + return render(request, "job_posting/index.html", {'job_list': current_page, 'current_page': current_page, 'viewname': viewname}) else: - ls1 = [] - messages.error(request, "No posts matching your current requirements.") - return render(request, "job_posting/home.html", {'ls1': ls1, 'viewname': viewname}) + empty_list = [] + messages.error(request, "No jobs matching your current requirements.") + return render(request, "job_posting/index.html", {'job_list': empty_list ,'viewname': viewname}) @login_required -def post(request): +def post_opportunity(request): if request.method == 'POST': try: - type = request.POST.get('type') - position = request.POST.get('position') - company = request.POST.get('company') + job_type = request.POST.get('job_type') + job_role = request.POST.get('job_role') + org_name = request.POST.get('org_name') location = request.POST.get('location') raw_link = request.POST.get('link') link = raw_link if raw_link.startswith('https://') or raw_link.startswith( 'http://') else 'https://' + raw_link - desc = request.POST.get('desc') + job_desc = request.POST.get('job_desc') stipend = int(request.POST.get('stipend')) if request.POST.get('stipend') else None exp_req = int(request.POST.get('exp_req')) if request.POST.get('exp_req') else None tenure = int(request.POST.get('tenure')) if request.POST.get('tenure') else None last_date = request.POST.get('last_date') if request.POST.get('last_date') else None join_date = request.POST.get('join_date') if request.POST.get('join_date') else None - person = User.objects.get(username=str(request.user)) + added_by = User.objects.get(username=str(request.user)) - if position == "Other": - position = request.POST.get('jobrole') + if job_role == "Other": + job_role = request.POST.get('other_jobrole') - Posting.objects.create( - type=type, - position=position, - company=company, + Job.objects.create( + job_type=job_type, + job_role=job_role, + org_name=org_name, location=location, - desc=desc, + job_desc=job_desc, stipend=stipend, exp_req=exp_req, last_date=last_date, @@ -117,17 +122,16 @@ def post(request): tenure=tenure, link=link, posting_date=date.today(), - person=person, + added_by=added_by, active=True ) messages.success(request, "Job opportunity added successfully!") except Exception as e: messages.error(request, "Some error occurred, try again.") - print("Exception while adding new job: ", e) return redirect('jobs:index', permanent=True) - return render(request, "job_posting/post.html") + return render(request, "job_posting/add_job.html") @login_required @@ -135,9 +139,9 @@ def post(request): is_superuser, redirect_field_name=None, login_url=reverse_lazy('home') ) -def del1(request, i_id=None): - if i_id: - job_post = Posting.objects.get(id=i_id) +def delete_job(request, job_id=None): + if job_id: + job_post = Job.objects.get(id=job_id) job_post.active = False job_post.save() messages.success(request, "Job opportunity removed successfully!") diff --git a/static/job_posting/home.css b/static/job_posting/home.css new file mode 100644 index 00000000..c64cc4a2 --- /dev/null +++ b/static/job_posting/home.css @@ -0,0 +1,46 @@ +.icon { + color: #324b7e !important; + margin-right: 8px !important; +} + +.heading { + color: rgba(0, 0, 0, 0.5) !important; + margin-bottom: 7px; + font-size: 13px; +} + +.detail { + color: rgb(0, 0, 0); + font-size: 15px; +} + +.type { + padding: 4px 7px; + width: max-content; + background-color: #324b7e; + border-radius: 15px; + color: rgb(255, 255, 255); +} + +#more p { + margin-bottom: 4px; + white-space: pre-wrap; +} + +#more .colapse:not(.show) { + display: block; + height: 1.5rem; + overflow: hidden; +} + +#more .colapse.collapsing { + height: 1.5rem; +} + +#more a.collapsed::after { + content: 'Read More'; +} + +#more a:not(.collapsed)::after { + content: 'Read Less'; +} \ No newline at end of file diff --git a/templates/job_posting/post.html b/templates/job_posting/add_job.html similarity index 88% rename from templates/job_posting/post.html rename to templates/job_posting/add_job.html index 829585cb..b9d6af85 100644 --- a/templates/job_posting/post.html +++ b/templates/job_posting/add_job.html @@ -44,7 +44,7 @@
- @@ -55,8 +55,8 @@
- + @@ -74,15 +74,15 @@
- - + +
- - + +
@@ -100,8 +100,8 @@
- -
@@ -162,20 +162,20 @@ // var text = e.options[e.selectedIndex].text; // let val = e.selectedIndex; document.getElementById("joblabel").style.display = 'none'; - document.getElementById("jobrole").style.display = 'none'; - document.getElementById("jobrole").required = false; + document.getElementById("other_jobrole").style.display = 'none'; + document.getElementById("other_jobrole").required = false; if(val == "Other") { document.getElementById("joblabel").style.display = 'block'; - document.getElementById("jobrole").style.display = 'block'; + document.getElementById("other_jobrole").style.display = 'block'; document.getElementById("jobrole").required = true; } else { document.getElementById("joblabel").style.display = 'none'; - document.getElementById("jobrole").style.display = 'none'; - document.getElementById("jobrole").required = false; + document.getElementById("other_jobrole").style.display = 'none'; + document.getElementById("other_jobrole").required = false; } } diff --git a/templates/job_posting/home.html b/templates/job_posting/index.html similarity index 85% rename from templates/job_posting/home.html rename to templates/job_posting/index.html index 93b33c0d..e6bbd74f 100644 --- a/templates/job_posting/home.html +++ b/templates/job_posting/index.html @@ -6,56 +6,7 @@ {% endblock %} {% block css %} - + {% endblock %} {% block body %} @@ -76,25 +27,25 @@ {% if viewname != 'filter' %}
{% csrf_token %}
- - - - - + + + + - + - + + - - @@ -138,17 +89,17 @@ {% endfor %} - {% if ls1 %} + {% if job_list %}
- {% for i,j in ls1 %} + {% for i in job_list %}
@@ -156,7 +107,7 @@ Apply {% if request.user.is_superuser %} - Remove {% endif %}
@@ -170,24 +121,24 @@
-
+
{% if i.stipend != None %} ₹ {{ i.stipend }}/ Month {% else %} - Unknown + Unknown {% endif %}
{% if i.exp_req %} -
+
@@ -225,7 +176,7 @@ {% endif %}
- {% if i.desc %} + {% if i.job_desc %}
@@ -234,7 +185,7 @@

{{ i.desc }}

+ aria-exapanded="false">{{ i.job_desc }}

  • «
  • + {% if current_page.has_previous %} +
  • «
  • {% else %}
  • «
  • {% endif %} - {% for i in ls2.paginator.page_range %} - {% if ls2.number == i %} + {% for i in current_page.paginator.page_range %} + {% if current_page.number == i %}
  • {{ i }} (current)
  • {% else %}
  • {{ i }}
  • {% endif %} {% endfor %} - {% if ls2.has_next %} -
  • »
  • + {% if current_page.has_next %} +
  • »
  • {% else %}
  • »
  • {% endif %} From fd1c620086e8f32a15a63be891159e0c9992597b Mon Sep 17 00:00:00 2001 From: CHOUHAN-MOHIT <92783072+CHOUHAN-MOHIT@users.noreply.github.com> Date: Mon, 12 Sep 2022 23:59:17 +0530 Subject: [PATCH 3/3] job filter approach and some additional changes 1. job filter is now more effective and readable. 2. all the data now will be stored in camel case. 3. some additional changes in add job form. --- applications/job_posting/models.py | 2 +- applications/job_posting/urls.py | 2 +- applications/job_posting/views.py | 28 ++++++++++----- templates/job_posting/add_job.html | 58 +++++++++++++++--------------- templates/job_posting/index.html | 14 ++++---- 5 files changed, 57 insertions(+), 47 deletions(-) diff --git a/applications/job_posting/models.py b/applications/job_posting/models.py index d38a060f..8a442127 100644 --- a/applications/job_posting/models.py +++ b/applications/job_posting/models.py @@ -19,4 +19,4 @@ class Job(models.Model): active = models.BooleanField(null=False, default=True) def __str__(self): - return self.position + " at " + self.company + return self.job_role + " at " + self.org_name diff --git a/applications/job_posting/urls.py b/applications/job_posting/urls.py index dc7e35a0..753457c8 100644 --- a/applications/job_posting/urls.py +++ b/applications/job_posting/urls.py @@ -8,5 +8,5 @@ path('', views.index, name='index'), path('post/', views.post_opportunity, name='post'), path('filter/', views.filter_jobs, name='filter'), - re_path(r'^del/(?P[0-9]+)/$', views.delete_job, name='delete'), + re_path(r'^del/(?P[0-9]+)/$', views.delete_job, name='delete'), ] diff --git a/applications/job_posting/views.py b/applications/job_posting/views.py index 67caf0e9..ab56dd63 100644 --- a/applications/job_posting/views.py +++ b/applications/job_posting/views.py @@ -53,15 +53,23 @@ def filter_jobs(request): page = request.GET.get('page', 1) job_type = request.POST.get('job_type') + jobs = Job.objects.filter(active=True).order_by('-posting_date') + + if job_role != "all": + jobs = jobs.filter(job_role = job_role) + + if job_type != "all": + jobs = jobs.filter(job_type = job_type) + #if user choose other in role here than no jobs will be shown :( - if job_role != 'all' and type != 'all': - jobs = Job.objects.filter(job_role=job_role, job_type=job_type, active=True).order_by('-posting_date') - elif job_role != 'all' and type == 'all': - jobs = Job.objects.filter(job_role=job_role, active=True).order_by('-posting_date') - elif job_role == 'all' and type != 'all': - jobs = Job.objects.filter(type=type, active=True).order_by('-posting_date') - else: - return redirect('jobs:index', permanent=True) + # if job_role != 'all' and type != 'all': + # jobs = Job.objects.filter(job_role=job_role, job_type=job_type, active=True).order_by('-posting_date') + # elif job_role != 'all' and type == 'all': + # jobs = Job.objects.filter(job_role=job_role, active=True).order_by('-posting_date') + # elif job_role == 'all' and type != 'all': + # jobs = Job.objects.filter(type=type, active=True).order_by('-posting_date') + # else: + # return redirect('jobs:index', permanent=True) if jobs: messages.success(request, "Found " + str(jobs.count()) + " jobs matching your query!") @@ -108,6 +116,10 @@ def post_opportunity(request): if job_role == "Other": job_role = request.POST.get('other_jobrole') + + job_role = job_role.title() + org_name = org_name.title() + location = location.title() Job.objects.create( job_type=job_type, diff --git a/templates/job_posting/add_job.html b/templates/job_posting/add_job.html index b9d6af85..cb70bb63 100644 --- a/templates/job_posting/add_job.html +++ b/templates/job_posting/add_job.html @@ -33,7 +33,7 @@
    - {% csrf_token %} + {% csrf_token %}
    @@ -42,8 +42,8 @@
    -
    - + -
    - - + -
    - +
    +
    - +
    - +
    -
    - +
    +
    -
    - - +
    + +
    -
    -
    +
    +
    @@ -118,24 +116,24 @@ -->
    -
    +
    -
    +
    -
    -
    +
    +
    -
    +
    @@ -145,6 +143,7 @@
    +
    @@ -156,23 +155,22 @@ function print_alert(val) { - - var e = document.getElementsByName("position"); - // var value = e.value; - // var text = e.options[e.selectedIndex].text; - // let val = e.selectedIndex; document.getElementById("joblabel").style.display = 'none'; document.getElementById("other_jobrole").style.display = 'none'; document.getElementById("other_jobrole").required = false; if(val == "Other") { + document.getElementById("dropdown1").className = "mx-auto col-sm-4 mb-3"; + document.getElementById("dropdown2").className = "mx-auto col-sm-4 mb-3"; document.getElementById("joblabel").style.display = 'block'; document.getElementById("other_jobrole").style.display = 'block'; - document.getElementById("jobrole").required = true; + document.getElementById("other_jobrole").required = true; } else { + document.getElementById("dropdown1").className = "mx-auto col-12 col-sm-6 mb-3"; + document.getElementById("dropdown2").className = "mx-auto col-12 col-sm-6 mb-3"; document.getElementById("joblabel").style.display = 'none'; document.getElementById("other_jobrole").style.display = 'none'; document.getElementById("other_jobrole").required = false; diff --git a/templates/job_posting/index.html b/templates/job_posting/index.html index e6bbd74f..2a574c06 100644 --- a/templates/job_posting/index.html +++ b/templates/job_posting/index.html @@ -41,7 +41,7 @@ - + @@ -98,8 +98,8 @@
    @@ -121,7 +121,7 @@ @@ -133,7 +133,7 @@ {% if i.stipend != None %} ₹ {{ i.stipend }}/ Month {% else %} - Unknown + Unknown {% endif %}
    @@ -169,7 +169,7 @@ {% if i.tenure %} @@ -180,7 +180,7 @@