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 @@