def index(request): """ Method: GET 1. Recruiter: Will display the recent tickets created by loggedin user and sending the priority types, ticket types to the page 2. Admin: Sending the priority types, ticket types to the page 3. For other users, displaying 404 page Method: POST 1. Validates a post data along with ticket attachments, sends errors as json to browser 2. Creating a ticket with its attachments in open state 3. Sending the email to the created user with respected ticket message """ if request.method == "GET": if request.user.is_agency_recruiter or request.user.is_recruiter: tickets = Ticket.objects.filter( user=request.user).order_by("-created_on") template_name = "recruiter/tickets/ticket.html" data = { "tickets": tickets, "priorities": PRIORITY_TYPES, "ticket_types": TICKET_TYPES, } elif request.user.is_staff: template_name = "dashboard/tickets/ticket.html" data = {"priorities": PRIORITY_TYPES, "ticket_types": TICKET_TYPES} else: template_name = "recruiter/recruiter_404.html" data = { "message": "Sorry, No Ticket Found", "reason": """The URL may be misspelled or the ticket you're looking for is no longer available.""", } return render(request, template_name, data) validate_ticket = TicketForm(request.POST, request.FILES) if validate_ticket.is_valid(): ticket = validate_ticket.save(commit=False) ticket.user = request.user ticket.status = "Open" ticket.save() for key, value in request.FILES.items(): attachment = Attachment.objects.create(attached_file=value, uploaded_by=request.user) ticket.attachments.add(attachment) temp = loader.get_template("email/new_ticket.html") subject = "Service Request | Peeljobs" rendered = temp.render({"ticket": ticket}) user_active = True if ticket.user.is_active else False mto = [ticket.user.email] send_email.delay(mto, subject, rendered) data = {"error": False, "response": "New Ticket Created Successfully"} else: errors = validate_ticket.errors for key in request.POST.keys(): if "attachment_" in key: errors[key] = "This field is required" data = {"error": True, "response": errors} return HttpResponse(json.dumps(data))
def save_job_post(validate_post, request): validate_post.agency_amount = validate_post.agency_amount or "" validate_post.user = request.user validate_post.published_on = datetime.now() validate_post.vacancies = request.POST.get("vacancies") or 0 validate_post.pincode = request.POST.get("pincode", "") if request.POST.get("major_skill"): skill = Skill.objects.filter(id=request.POST.get("major_skill")) if skill: validate_post.major_skill = skill[0] company = Company.objects.filter(name__iexact=request.POST["company_name"]) if company: job_post_company = company[0] job_post_company.name = request.POST["company_name"] job_post_company.slug = slugify(request.POST["company_name"]) job_post_company.address = request.POST["company_address"] job_post_company.profile = request.POST["company_description"] job_post_company.website = request.POST["company_website"] if "company_logo" in request.FILES: file_path = get_aws_file_path( request.FILES.get("company_logo"), "company/logo/", slugify(request.POST["company_name"]), ) job_post_company.profile_pic = file_path job_post_company.save() else: job_post_company = Company.objects.create( name=request.POST["company_name"], address=request.POST["company_address"], profile=request.POST["company_description"], slug=slugify(request.POST["company_name"]), company_type="Company", email=request.user.email, created_from="job_post", website=request.POST["company_website"], ) if request.FILES.get("company_logo"): file_path = get_aws_file_path( request.FILES.get("company_logo"), "company/logo/", slugify(request.POST["company_name"]), ) job_post_company.profile_pic = file_path job_post_company.save() validate_post.company = job_post_company validate_post.save() validate_post.slug = get_absolute_url(validate_post) validate_post.save() if request.user.is_admin and request.user.is_agency_recruiter: for recruiter in request.POST.getlist("agency_recruiters"): user = User.objects.get(id=recruiter) c = {"job_post": validate_post, "user": user} t = loader.get_template("email/assign_jobpost.html") subject = "PeelJobs New JobPost" rendered = t.render(c) user_active = True if user.is_active else False mto = [user.email] send_email.delay(mto, subject, rendered)
def add_other_functional_area(job_post, data, user): temp = loader.get_template("recruiter/email/add_other_fields.html") subject = "PeelJobs New JobPost" mto = [settings.DEFAULT_FROM_EMAIL] for functional_area in data: for value in functional_area.values(): other_areas = value.replace(" ", "").split(",") for value in other_areas: if value != "": functional_area = FunctionalArea.objects.filter( name__iexact=value) if functional_area: job_post.functional_area.add(functional_area[0]) else: functional_area = FunctionalArea.objects.create( name=value, status="InActive") job_post.functional_area.add(functional_area) c = { "job_post": job_post, "user": user, "item": value, "type": "Functional Area", "value": functional_area.name, } rendered = temp.render(c) send_email.delay(mto, subject, rendered)
def add_other_locations(post, data, user): temp = loader.get_template("recruiter/email/add_other_fields.html") subject = "PeelJobs New JobPost" mto = [settings.DEFAULT_FROM_EMAIL] for location in data.getlist("other_location"): locations = [loc.strip() for loc in location.split(",") if loc.strip()] for location in locations: locations = City.objects.filter(name__iexact=location) if locations: post.location.add(locations[0]) else: location = City.objects.create( name=location, status="Disabled", slug=slugify(location), state=State.objects.get(id=16), ) post.location.add(location) c = { "job_post": post, "user": user, "item": "Location", "type": "Location", "value": location.name, } rendered = temp.render(c) send_email.delay(mto, subject, rendered)
def add_other_industry(job_post, data, user): temp = loader.get_template("recruiter/email/add_other_fields.html") subject = "PeelJobs New JobPost" mto = [settings.DEFAULT_FROM_EMAIL] for industry in data: for value in industry.values(): o_industries = value.replace(" ", "").split(",") for value in o_industries: if value != "": industry = Industry.objects.filter(name__iexact=value) if industry: job_post.industry.add(industry[0]) else: industry = Industry.objects.create(name=value, status="InActive", slug=slugify(value)) job_post.industry.add(industry) c = { "job_post": job_post, "user": user, "item": value, "type": "Industry", "value": industry.name, } rendered = temp.render(c) send_email.delay(mto, subject, rendered)
def add_other_qualifications(job_post, data, user): temp = loader.get_template("recruiter/email/add_other_fields.html") subject = "PeelJobs New JobPost" mto = [settings.DEFAULT_FROM_EMAIL] for qualification in data: for value in qualification.values(): other_skills = value.replace(" ", "").split(",") for value in other_skills: if value != "": qualification = Qualification.objects.filter( name__iexact=value) if qualification: job_post.edu_qualification.add(qualification[0]) else: qualification = Qualification.objects.create( name=value, status="InActive", slug=slugify(value)) job_post.edu_qualification.add(qualification) c = { "job_post": job_post, "user": user, "item": value, "type": "Qualification", "value": qualification.name, } rendered = temp.render(c) send_email.delay(mto, subject, rendered)
def add_other_skills(job_post, data, user): temp = loader.get_template("recruiter/email/add_other_fields.html") subject = "PeelJobs New JobPost" mto = [settings.DEFAULT_FROM_EMAIL] for skill in data: for value in skill.values(): other_skills = value.replace(" ", "").split(",") for value in other_skills: if value != "": skills = Skill.objects.filter(name__iexact=value) if skills: job_post.skills.add(skills[0]) else: skill = Skill.objects.create( name=value, status="InActive", slug=slugify(value), skill_type="Technical", ) c = { "job_post": job_post, "user": user, "item": value, "type": "Skill", "value": skill.name, } rendered = temp.render(c) send_email.delay(mto, subject, rendered) job_post.skills.add(skill)
def digest(request, form_class=DigestRangeForm, template_name='dashboard/digest.html', *args, **kwargs): now = datetime.datetime.now() start_date = None end_date = None mimetype = None if 'submit' in request.GET: form = form_class(request.GET) if form.is_valid(): start_date = datetime.datetime.strptime(form.cleaned_data['start_date'], TIME_FORMAT) end_date = datetime.datetime.strptime(form.cleaned_data['end_date'], TIME_FORMAT) # Enforce max 7 days. if end_date - start_date > datetime.timedelta(days=7): start_date = end_date - datetime.timedelta(days=7) else: form = form_class(initial=dict( start_date=now - datetime.timedelta(days=1), end_date=now, )) template_context = dict( form=form, ) if start_date and end_date: user = request.user template_context = digests.daily_context(user, start_date, end_date) if request.GET.get('submit') == 'html': template_name = 'dashboard/digest_html.html' return render_to_response(template_name, template_context, RequestContext(request)) if request.GET.get('submit') == 'plaintext': template_name = 'dashboard/digest_plaintext.txt' return render_to_response(template_name, template_context, RequestContext(request), mimetype='text/plain') if request.GET.get('submit') == 'email': send_email.delay(user.id, start_date, end_date) return HttpResponse('Email will be sent if any activity detected.', mimetype='text/plain') else: return render_to_response(template_name, template_context, RequestContext(request))
def ticket_comment(request, ticket_id): """ 1. Check for a ticket existed or not with the id mentioned in the url 2. check the loogedin is ticket_created user or admin, If not returns a 404 page 3. Then checking for form validations along with comment attachments 4. If successfull, then comment will be created for a ticket 5. A Notification email has been sent to the ticket_created user with the comment message """ ticket = Ticket.objects.filter(id=ticket_id).first() if ticket: if request.user.is_staff or request.user == ticket.user: validate_comment = CommentForm(request.POST, request.FILES) if validate_comment.is_valid(): comment = Comment.objects.create( comment=request.POST.get("comment"), ticket=ticket, commented_by=request.user, ) if request.FILES: for key, value in request.FILES.items(): attachment = Attachment.objects.create( attached_file=value, uploaded_by=request.user) comment.attachments.add(attachment) if request.user.is_superuser: temp = loader.get_template("email/new_ticket.html") subject = "Acknowledgement For Your Request | Peeljobs" rendered = temp.render({ "ticket": ticket, "comment": comment }) mto = ticket.user.email user_active = True if ticket.user.is_active else False send_email.delay(mto, subject, rendered) return HttpResponse( json.dumps({ "error": False, "response": "Comment added Successfully" })) else: return HttpResponse( json.dumps({ "error": True, "response": validate_comment.errors })) reason = "The URL may be misspelled or the ticket you're looking for is no longer available." return render( request, "recruiter/recruiter_404.html", { "message_type": "404", "message": "Sorry, No Ticket Found", "reason": reason }, status=404, )
def contact(request): if request.method == "POST": validate_simplecontactform = SimpleContactForm(request.POST) if validate_simplecontactform.is_valid(): payload = { "secret": "6LdZcgkTAAAAAGkY3zbzO4lWhqCStbWUef_6MWW-", "response": request.POST.get("g-recaptcha-response"), "remoteip": request.META.get("REMOTE_ADDR"), } r = requests.get( "https://www.google.com/recaptcha/api/siteverify", params=payload ) if json.loads(r.text)["success"]: validate_simplecontactform.save() c = { "email": request.POST.get("email"), "subject": request.POST.get("subject"), "first_name": request.POST.get("first_name"), "mobile": request.POST.get("phone"), "enquiry_type": request.POST.get("enquery_type"), "comment": request.POST.get("comment"), } subject = "New Request ContactUs | PeelJobs" mto = settings.SUPPORT_EMAILS t = loader.get_template("email/contactus_email.html") rendered = t.render(c) send_email.delay(mto, subject, rendered) subject = "Thanks for contacting us | PeelJobs" mto = settings.SUPPORT_EMAILS t = loader.get_template("email/user_contactus.html") rendered = t.render(c) send_email.delay(mto, subject, rendered) data = { "error": False, "response": "Thanks for contacting Us, we will reach you soon!", } return HttpResponse(json.dumps(data)) data = {"error": True, "captcha_response": "Choose Correct Captcha"} return HttpResponse(json.dumps(data)) data = {"error": True, "response": validate_simplecontactform.errors} return HttpResponse(json.dumps(data)) if request.is_mobile: return render( request, "mobile/contact-us.html", {"enquery_types": ENQUERY_TYPES} ) return render(request, "pages/contact-us.html", {"enquery_types": ENQUERY_TYPES})
def new_ticket(request): """ Method: GET 1. Recruiter: Will display create ticket page and sending the priority types, ticket types to the page Method: POST 1. Validates a post data along with ticket attachments, sends errors as json to browser 2. Creating a ticket with its attachments in open state 3. Sending the email to the created user with respected ticket message """ if request.method == "GET": return render( request, "recruiter/tickets/new_ticket.html", { "priorities": PRIORITY_TYPES, "ticket_types": TICKET_TYPES }, ) validate_ticket = TicketForm(request.POST, request.FILES) if validate_ticket.is_valid(): ticket = validate_ticket.save(commit=False) ticket.user = request.user ticket.status = "Open" ticket.save() for key, value in request.FILES.items(): attachment = Attachment.objects.create(attached_file=value, uploaded_by=request.user) ticket.attachments.add(attachment) temp = loader.get_template("email/new_ticket.html") subject = "Service Request | Peeljobs" rendered = temp.render({"ticket": ticket}) user_active = True if ticket.user.is_active else False mto = ticket.user.email send_email.delay(mto, subject, rendered) data = {"error": False, "response": "New Ticket Created Successfully"} else: errors = validate_ticket.errors data = {"error": True, "response": errors} return HttpResponse(json.dumps(data))
def ticket_status(request, ticket_id): """ 1. Check for a ticket existed or not with the id mentioned in the url 2. check the loogedin is ticket_created user or admin, If not returns a 404 page 3. If successfull, then changing the ticket status """ tickets = Ticket.objects.filter(id=ticket_id) if tickets: ticket = tickets[0] if request.user.is_staff or request.user == ticket.user: if request.POST.get("ticket_status"): ticket.status = request.POST.get("ticket_status") ticket.save() temp = loader.get_template("email/new_ticket.html") subject = "Your Ticket Status | Peeljobs" rendered = temp.render({"ticket": ticket, "status": True}) mto = ticket.user.email user_active = True if ticket.user.is_active else False send_email.delay(mto, subject, rendered) data = { "error": False, "response": "Ticket status changed Successfully", } else: data = {"error": True, "response": "Please select status"} return HttpResponse(json.dumps(data)) message = "Sorry, No Ticket Found" reason = "The URL may be misspelled or the ticket you're looking for is no longer available." return render( request, "recruiter/recruiter_404.html", { "message_type": "404", "message": message, "reason": reason }, status=404, )
def new_job(request, job_type): if request.method == "GET": if request.GET.get("q"): companies = Company.objects.filter( name__icontains=request.GET.get("q"), is_active=True).distinct()[:10] companies_names = companies.values_list("name", flat=True) if request.GET.get("register_name"): company = Company.objects.filter( name=request.GET.get("register_name")).first() if company: return JsonResponse( {"company": CompanySerializer(company).data}) data = {"response": companies_names} return JsonResponse(data) if request.user.is_active: if (request.user.is_company_recruiter and not request.user.is_admin and not request.user.has_perm("jobposts_edit")): message = "You Don't have permission to create a new job" reason = "Please contact your agency admin" return JsonResponse( { "message": message, "reason": reason }, status=status.HTTP_400_BAD_REQUEST, ) countries = Country.objects.all().order_by("name") skills = Skill.objects.all().exclude( status="InActive").order_by("name") functional_area = (FunctionalArea.objects.all().exclude( status="InActive").order_by("name")) industries = (Industry.objects.all().exclude( status="InActive").order_by("name")) qualifications = (Qualification.objects.all().exclude( status="InActive").order_by("name")) cities = City.objects.filter().exclude(status="Disabled") recruiters = User.objects.filter(company=request.user.company) if request.user.agency_admin or request.user.has_perm( "jobposts_edit"): jobposts = JobPost.objects.filter( job_type=job_type, user__company=request.user.company) else: jobposts = JobPost.objects.filter(job_type=job_type, user=request.user) clients = AgencyCompany.objects.filter( company=request.user.company) show_clients = True show_recruiters = True if request.user.is_agency_recruiter: show_clients = False if not clients else True show_recruiters = False if not recruiters else True return JsonResponse( { "job_types": JOB_TYPE, "functional_area": FunctionalAreaSerializer(functional_area, many=True).data, "qualifications": QualificationSerializer(qualifications, many=True).data, "years": YEARS, "months": MONTHS, "industries": IndustrySerializer(industries, many=True).data, "countries": CountrySerializer(countries, many=True).data, "skills": SkillSerializer(skills, many=True).data, "jobposts": JobPostSerializer(jobposts, many=True).data, "cities": CitySerializer(cities, many=True).data, "status": job_type, "agency_invoice_types": AGENCY_INVOICE_TYPE, "agency_job_types": AGENCY_JOB_TYPE, "recruiters": UserSerializer(recruiters, many=True).data, "clients": AgencyCompanySerializer(clients, many=True).data, "show_clients": show_clients, "show_recruiters": show_recruiters, "user_details": UserSerializer(request.user).data, }, status=status.HTTP_200_OK, ) else: message = "Sorry, Your account is not verified" reason = "Please verify your email id" return JsonResponse( { "message": message, "reason": reason }, status=status.HTTP_404_NOT_FOUND, ) validate_form = JobPostForm(request.POST, request.FILES, user=request.user) errors = retreving_form_errors(request, validate_form) if not errors: validate_post = validate_form.save(commit=False) save_job_post(validate_post, request) validate_form.save_m2m() adding_other_fields_data(request.POST, validate_post, request.user) c = {"job_post": validate_post, "user": request.user} t = loader.get_template("email/jobpost_notification.html") subject = "PeelJobs New JobPost" rendered = t.render(c) mto = settings.SUPPORT_EMAILS send_email.delay(mto, subject, rendered) data = { "error": False, "response": "New Post created", "post": validate_post.id, } return JsonResponse(data, status=status.HTTP_200_OK) data = {"error": True, "response": errors} return JsonResponse(data, status=status.HTTP_400_BAD_REQUEST)