Skip to content

Refactor/job posting #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions applications/job_posting/admin.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 7 additions & 7 deletions applications/job_posting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions applications/job_posting/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<i_id>[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<job_id>[0-9]+)/$', views.delete_job, name='delete'),
]
162 changes: 96 additions & 66 deletions applications/job_posting/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,115 +15,145 @@ 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
@user_passes_test(
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!")
Expand Down
46 changes: 46 additions & 0 deletions static/job_posting/home.css
Original file line number Diff line number Diff line change
@@ -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';
}
Loading