def search(self, query=None, *args, **kwargs): """ Uses haystack to query resumes. Returns a SearchQuerySet """ sqs = super(ResumeManager, self).search(query=None, *args, **kwargs) if self.user.is_anonymous(): sqs = sqs.filter(activation_dt__lte=now_localized()) sqs = sqs.filter(expiration_dt__gte=now_localized()) return sqs
def approve(request, id, template_name="resumes/approve.html"): if not request.user.profile.is_superuser: raise Http403 resume = get_object_or_404(Resume, pk=id) if request.method == "POST": resume.activation_dt = now_localized() resume.allow_anonymous_view = True resume.status = True resume.status_detail = 'active' if not resume.creator: resume.creator = request.user resume.creator_username = request.user.username if not resume.owner: resume.owner = request.user resume.owner_username = request.user.username resume.save() messages.add_message(request, messages.SUCCESS, 'Successfully approved %s' % resume) return HttpResponseRedirect(reverse('resume', args=[resume.slug])) return render_to_response(template_name, {'resume': resume}, context_instance=RequestContext(request))
def add(request, form_class=ResumeForm, template_name="resumes/add.html"): can_add_active = has_perm(request.user, 'resumes.add_resume') if request.method == "POST": form = form_class(request.POST or None, user=request.user) if form.is_valid(): resume = form.save(commit=False) # set it to pending if the user does not have add permission if not can_add_active: resume.status = 0 resume.status_detail = 'pending' # set up the expiration time based on requested duration now = now_localized() resume.expiration_dt = now + timedelta(days=resume.requested_duration) resume = update_perms_and_save(request, form, resume) # we need to save instance first since we need the id for the file path if request.FILES: resume.resume_file = request.FILES['resume_file'] resume.resume_file.file.seek(0) resume.save() log_defaults = { 'event_id' : 351000, 'event_data': '%s (%d) added by %s' % (resume._meta.object_name, resume.pk, request.user), 'description': '%s added' % resume._meta.object_name, 'user': request.user, 'request': request, 'instance': resume, } EventLog.objects.log(**log_defaults) if request.user.is_authenticated(): messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % resume) # send notification to administrators recipients = get_notice_recipients('module', 'resumes', 'resumerecipients') if recipients: if notification: extra_context = { 'object': resume, 'request': request, } notification.send_emails(recipients,'resume_added', extra_context) if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('resume.thank_you')) else: return HttpResponseRedirect(reverse('resume', args=[resume.slug])) else: form = form_class(user=request.user) return render_to_response(template_name, {'form':form}, context_instance=RequestContext(request))
def auto_update_paid_object(self, request, payment): """ Update the object after online payment is received. """ if not request.user.profile.is_superuser: self.status_detail = 'paid - pending approval' self.activation_dt = now_localized() self.expiration_dt = self.activation_dt + timedelta(days=self.requested_duration) self.save()
def add(request, form_class=ResumeForm, template_name="resumes/add.html"): can_add_active = has_perm(request.user, "resumes.add_resume") if request.method == "POST": form = form_class(request.POST, user=request.user) if form.is_valid(): resume = form.save(commit=False) # set it to pending if the user does not have add permission if not can_add_active: resume.status = 0 resume.status_detail = "pending" # set up the expiration time based on requested duration now = now_localized() resume.expiration_dt = now + timedelta(days=resume.requested_duration) resume = update_perms_and_save(request, form, resume) log_defaults = { "event_id": 351000, "event_data": "%s (%d) added by %s" % (resume._meta.object_name, resume.pk, request.user), "description": "%s added" % resume._meta.object_name, "user": request.user, "request": request, "instance": resume, } EventLog.objects.log(**log_defaults) if request.user.is_authenticated(): messages.add_message(request, messages.SUCCESS, "Successfully added %s" % resume) # send notification to administrators recipients = get_notice_recipients("module", "resumes", "resumerecipients") if recipients: if notification: extra_context = {"object": resume, "request": request} notification.send_emails(recipients, "resume_added", extra_context) if not request.user.is_authenticated(): return HttpResponseRedirect(reverse("resume.thank_you")) else: return HttpResponseRedirect(reverse("resume", args=[resume.slug])) else: form = form_class(user=request.user) return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))
def add(request, form_class=ResumeForm, template_name="resumes/add.html"): can_add_active = has_perm(request.user, 'resumes.add_resume') if request.method == "POST": form = form_class(request.POST or None, user=request.user) if form.is_valid(): resume = form.save(commit=False) # set it to pending if the user does not have add permission if not can_add_active: resume.status = 0 resume.status_detail = 'pending' # set up the expiration time based on requested duration now = now_localized() resume.expiration_dt = now + timedelta(days=resume.requested_duration) resume = update_perms_and_save(request, form, resume) # we need to save instance first since we need the id for the file path if request.FILES: resume.resume_file = request.FILES['resume_file'] resume.resume_file.file.seek(0) resume.save() EventLog.objects.log(instance=resume) if request.user.is_authenticated(): messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % resume) # send notification to administrators recipients = get_notice_recipients('module', 'resumes', 'resumerecipients') if recipients: if notification: extra_context = { 'object': resume, 'request': request, } notification.send_emails(recipients,'resume_added', extra_context) if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('resume.thank_you')) else: return HttpResponseRedirect(reverse('resume', args=[resume.slug])) else: form = form_class(user=request.user) return render_to_response(template_name, {'form':form}, context_instance=RequestContext(request))
def approve(request, id, template_name="jobs/approve.html"): can_view_jobs = has_perm(request.user, 'jobs.view_job') can_change_jobs = has_perm(request.user, 'jobs.change_job') if not all([can_view_jobs, can_change_jobs]): raise Http403 job = get_object_or_404(Job, pk=id) if request.method == "POST": job.activation_dt = now_localized() job.allow_anonymous_view = True job.status = True job.status_detail = 'active' if not job.creator: job.creator = request.user job.creator_username = request.user.username if not job.owner: job.owner = request.user job.owner_username = request.user.username job.save() # send email notification to user recipients = [job.creator.email] if recipients: extra_context = { 'object': job, 'request': request, } #try: send_email_notification( 'job_approved_user_notice', recipients, extra_context) #except: # pass messages.add_message(request, messages.SUCCESS, 'Successfully approved %s' % job) return HttpResponseRedirect(reverse('job', args=[job.slug])) return render_to_response(template_name, {'job': job}, context_instance=RequestContext(request))
def approve(request, id, template_name="jobs/approve.html"): can_view_jobs = has_perm(request.user, 'jobs.view_job') can_change_jobs = has_perm(request.user, 'jobs.change_job') if not all([can_view_jobs, can_change_jobs]): raise Http403 job = get_object_or_404(Job, pk=id) if request.method == "POST": job.activation_dt = now_localized() job.allow_anonymous_view = True job.status = True job.status_detail = 'active' if not job.creator: job.creator = request.user job.creator_username = request.user.username if not job.owner: job.owner = request.user job.owner_username = request.user.username job.save() # send email notification to user recipients = [job.creator.email] if recipients: extra_context = { 'object': job, 'request': request, } #try: send_email_notification('job_approved_user_notice', recipients, extra_context) #except: # pass messages.add_message(request, messages.SUCCESS, 'Successfully approved %s' % job) return HttpResponseRedirect(reverse('job', args=[job.slug])) return render_to_response(template_name, {'job': job}, context_instance=RequestContext(request))
def add(request, form_class=JobForm, template_name="jobs/add.html", object_type=Job, success_redirect='job'): require_payment = get_setting('module', 'jobs', 'jobsrequirespayment') can_add_active = has_perm(request.user, 'jobs.add_job') content_type = get_object_or_404( ContentType, app_label=object_type._meta.app_label, model=object_type._meta.module_name ) if request.user.profile.is_superuser: category_form_class = CategoryForm else: category_form_class = CategoryForm2 if request.method == "POST": form = form_class(request.POST, user=request.user) categoryform = category_form_class( content_type, request.POST, prefix='category') # adjust the fields depending on user type if not require_payment: del form.fields['payment_method'] del form.fields['list_type'] if form.is_valid() and categoryform.is_valid(): job = form.save(commit=False) pricing = form.cleaned_data['pricing'] # set it to pending if the user is anonymous or not an admin if not can_add_active: #job.status = 1 job.status_detail = 'pending' # list types and duration if not job.requested_duration: job.requested_duration = 30 if not job.list_type: job.list_type = 'regular' # set up all the times now = now_localized() job.activation_dt = now if not job.post_dt: job.post_dt = now # set the expiration date job.expiration_dt = job.activation_dt + timedelta( days=job.requested_duration) # semi-anon job posts don't get a slug field on the form # see __init__ method in JobForm if not job.slug: #job.slug = get_job_unique_slug(slugify(job.title)) job.slug = '%s-%s' % (slugify(job.title), Job.objects.count()) job = update_perms_and_save(request, form, job) # create invoice job_set_inv_payment(request.user, job, pricing) #setup categories category = Category.objects.get_for_object(job, 'category') sub_category = Category.objects.get_for_object( job, 'sub_category') ## update the category of the job category_removed = False category = categoryform.cleaned_data['category'] if category != '0': Category.objects.update(job, category, 'category') else: # remove category_removed = True Category.objects.remove(job, 'category') Category.objects.remove(job, 'sub_category') if not category_removed: # update the sub category of the job sub_category = categoryform.cleaned_data['sub_category'] if sub_category != '0': Category.objects.update(job, sub_category, 'sub_category') else: # remove Category.objects.remove(job,'sub_category') #save relationships job.save() messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % job) # send notification to administrators recipients = get_notice_recipients( 'module', 'jobs', 'jobrecipients') if recipients: if notification: extra_context = { 'object': job, 'request': request, } notification.send_emails(recipients, 'job_added', extra_context) # send user to the payment page if payment is required if require_payment: if job.payment_method.lower() in ['credit card', 'cc']: if job.invoice and job.invoice.balance > 0: return HttpResponseRedirect(reverse( 'payment.pay_online', args=[job.invoice.id, job.invoice.guid]) ) # send user to thank you or view page if request.user.profile.is_superuser: return HttpResponseRedirect( reverse(success_redirect, args=[job.slug])) else: return HttpResponseRedirect(reverse('job.thank_you')) else: # Redirect user w/perms to create pricing if none exist pricings = JobPricing.objects.all() if not pricings and has_perm(request.user, 'jobs.add_jobpricing'): messages.add_message(request, messages.WARNING, 'You need to add a %s Pricing before you can add a %s.' % (get_setting('module', 'jobs', 'label_plural'),get_setting('module', 'jobs', 'label'))) return HttpResponseRedirect(reverse('job_pricing.add')) form = form_class(user=request.user) initial_category_form_data = { 'app_label': 'jobs', 'model': 'job', 'pk': 0, #not used for this view but is required for the form } categoryform = category_form_class( content_type, initial=initial_category_form_data, prefix='category') # adjust the fields depending on user type if not require_payment: del form.fields['payment_method'] del form.fields['list_type'] return render_to_response(template_name, {'form': form, 'categoryform':categoryform}, context_instance=RequestContext(request))
def add(request, form_class=JobForm, template_name="jobs/add.html", object_type=Job, success_redirect='job'): require_payment = get_setting('module', 'jobs', 'jobsrequirespayment') can_add_active = has_perm(request.user, 'jobs.add_job') content_type = get_object_or_404(ContentType, app_label=object_type._meta.app_label, model=object_type._meta.module_name) if request.user.profile.is_superuser: category_form_class = CategoryForm else: category_form_class = CategoryForm2 if request.method == "POST": form = form_class(request.POST, user=request.user) categoryform = category_form_class(content_type, request.POST, prefix='category') # adjust the fields depending on user type if not require_payment: del form.fields['payment_method'] del form.fields['list_type'] if form.is_valid() and categoryform.is_valid(): job = form.save(commit=False) pricing = form.cleaned_data['pricing'] # set it to pending if the user is anonymous or not an admin if not can_add_active: #job.status = 1 job.status_detail = 'pending' # list types and duration if not job.requested_duration: job.requested_duration = 30 if not job.list_type: job.list_type = 'regular' # set up all the times now = now_localized() job.activation_dt = now if not job.post_dt: job.post_dt = now # set the expiration date job.expiration_dt = job.activation_dt + timedelta( days=job.requested_duration) # semi-anon job posts don't get a slug field on the form # see __init__ method in JobForm if not job.slug: #job.slug = get_job_unique_slug(slugify(job.title)) job.slug = '%s-%s' % (slugify(job.title), Job.objects.count()) job = update_perms_and_save(request, form, job) # create invoice job_set_inv_payment(request.user, job, pricing) #setup categories category = Category.objects.get_for_object(job, 'category') sub_category = Category.objects.get_for_object(job, 'sub_category') ## update the category of the job category_removed = False category = categoryform.cleaned_data['category'] if category != '0': Category.objects.update(job, category, 'category') else: # remove category_removed = True Category.objects.remove(job, 'category') Category.objects.remove(job, 'sub_category') if not category_removed: # update the sub category of the job sub_category = categoryform.cleaned_data['sub_category'] if sub_category != '0': Category.objects.update(job, sub_category, 'sub_category') else: # remove Category.objects.remove(job, 'sub_category') #save relationships job.save() messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % job) # send notification to administrators recipients = get_notice_recipients('module', 'jobs', 'jobrecipients') if recipients: if notification: extra_context = { 'object': job, 'request': request, } notification.send_emails(recipients, 'job_added', extra_context) # send user to the payment page if payment is required if require_payment: if job.payment_method.lower() in ['credit card', 'cc']: if job.invoice and job.invoice.balance > 0: return HttpResponseRedirect( reverse('payments.views.pay_online', args=[job.invoice.id, job.invoice.guid])) # send user to thank you or view page if request.user.profile.is_superuser: return HttpResponseRedirect( reverse(success_redirect, args=[job.slug])) else: return HttpResponseRedirect(reverse('job.thank_you')) else: # Redirect user w/perms to create pricing if none exist pricings = JobPricing.objects.all() if not pricings and has_perm(request.user, 'jobs.add_jobpricing'): messages.add_message( request, messages.WARNING, 'You need to add a %s Pricing before you can add a %s.' % (get_setting('module', 'jobs', 'label_plural'), get_setting('module', 'jobs', 'label'))) return HttpResponseRedirect(reverse('job_pricing.add')) form = form_class(user=request.user) initial_category_form_data = { 'app_label': 'jobs', 'model': 'job', 'pk': 0, #not used for this view but is required for the form } categoryform = category_form_class(content_type, initial=initial_category_form_data, prefix='category') # adjust the fields depending on user type if not require_payment: del form.fields['payment_method'] del form.fields['list_type'] return render_to_response(template_name, { 'form': form, 'categoryform': categoryform }, context_instance=RequestContext(request))
def add(request, form_class=ResumeForm, template_name="resumes/add.html"): can_add_active = has_perm(request.user, 'resumes.add_resume') if request.method == "POST": form = form_class(request.POST, user=request.user) if form.is_valid(): resume = form.save(commit=False) # set it to pending if the user does not have add permission if not can_add_active: resume.status = 0 resume.status_detail = 'pending' # set up the expiration time based on requested duration now = now_localized() resume.expiration_dt = now + timedelta( days=resume.requested_duration) resume = update_perms_and_save(request, form, resume) log_defaults = { 'event_id': 351000, 'event_data': '%s (%d) added by %s' % (resume._meta.object_name, resume.pk, request.user), 'description': '%s added' % resume._meta.object_name, 'user': request.user, 'request': request, 'instance': resume, } EventLog.objects.log(**log_defaults) if request.user.is_authenticated(): messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % resume) # send notification to administrators recipients = get_notice_recipients('module', 'resumes', 'resumerecipients') if recipients: if notification: extra_context = { 'object': resume, 'request': request, } notification.send_emails(recipients, 'resume_added', extra_context) if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('resume.thank_you')) else: return HttpResponseRedirect( reverse('resume', args=[resume.slug])) else: form = form_class(user=request.user) return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))