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..8a442127 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.job_role + " at " + self.org_name diff --git a/applications/job_posting/urls.py b/applications/job_posting/urls.py index 5a260ee3..753457c8 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 739279d6..ab56dd63 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,105 +15,135 @@ 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') - else: - return redirect('jobs:index', permanent=True) - - if posts: - messages.success(request, "Found " + str(posts.count()) + " posts matching your query!") - paginator = Paginator(posts, 10) + 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 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)) - - 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) + added_by = User.objects.get(username=str(request.user)) + + 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, + job_role=job_role, + org_name=org_name, + location=location, + job_desc=job_desc, + stipend=stipend, + exp_req=exp_req, + last_date=last_date, + join_date=join_date, + tenure=tenure, + link=link, + posting_date=date.today(), + 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 @@ -121,9 +151,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 55% rename from templates/job_posting/post.html rename to templates/job_posting/add_job.html index 88e399cd..cb70bb63 100644 --- a/templates/job_posting/post.html +++ b/templates/job_posting/add_job.html @@ -33,7 +33,7 @@
-
{% csrf_token %} + {% csrf_token %}
@@ -42,89 +42,98 @@
-
- - +
-
- - + - - + + + + - - - - + + + +
+
+ + +
-
- - +
+ +
-
- +
+
-
- +
+
-
- - +
+ +
-
-
+
+
- +
+ + + .00 +
+
-
+
-
+
-
-
+
+
-
+
@@ -134,11 +143,42 @@
+
+{% block javascript %} + +{% endblock javascript %} {% include 'globals/footer.html' %} diff --git a/templates/job_posting/home.html b/templates/job_posting/index.html similarity index 84% rename from templates/job_posting/home.html rename to templates/job_posting/index.html index 93b33c0d..2a574c06 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,12 +121,12 @@
-
+
@@ -187,7 +138,7 @@
{% if i.exp_req %} -
+
@@ -218,23 +169,23 @@ {% if i.tenure %} {% endif %}
- {% if i.desc %} + {% if i.job_desc %}

{{ 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 %}