<commit_before>import os
from django import forms
from django.shortcuts import redirect
from django.shortcuts import render
from django.views.generic import DetailView, ListView, TemplateView
from django.views.generic.edit import CreateView
from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy
from django.template import Context
from django.template.loader import render_to_string, get_template
from django.core.mail import EmailMessage
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
from mezzanine.conf import settings
from organization.job.models import JobOffer, JobResponse
from organization.job.forms import JobResponseForm

extention = ['.pdf', '.PDF', '.doc', '.docx']

class JobOfferDetailView(CreateView):

    model = JobResponse
    template_name='job/job_offer_detail.html'
    context_object_name = 'job_offer'
    form_class = JobResponseForm

    def get_context_data(self, **kwargs):
        context = super(JobOfferDetailView, self).get_context_data(**kwargs)
        job_offer = JobOffer.objects.get(slug=self.kwargs['slug'])
        if job_offer :
             context['job_offer'] = job_offer
        return context

    def get_initial(self):
        initial = super(JobOfferDetailView, self).get_initial()
        job_offer = JobOffer.objects.get(slug=self.kwargs['slug'])
        if job_offer :
            initial['job_offer'] = job_offer
        return initial

    def get_success_url(self):
        return reverse_lazy('organization-job-offer-detail', kwargs={'slug':self.kwargs['slug']})

    def form_valid(self, form):
        # check extension uploaded files
        name_cv, ext_cv = os.path.splitext(form.cleaned_data['curriculum_vitae'].name)
        name_cl, ext_cl = os.path.splitext(form.cleaned_data['cover_letter'].name)
        if ext_cv not in extention or ext_cl not in extention :
            messages.info(self.request, _("Only .pdf, .doc, .docx files allowed."))
            return super(JobOfferDetailView, self).form_invalid(form)

        job_offer = JobOffer.objects.get(slug=self.kwargs['slug'])
        email_application_notification(self.request, job_offer, form.cleaned_data)
        messages.info(self.request, _("You have successfully submitted your application."))
        return super(JobOfferDetailView, self).form_valid(form)


class JobOfferListView(ListView):

    model = JobOffer
    template_name='job/job_offer_list.html'<commit_msg>Reduce object calls<commit_after>import os
import mimetypes
from django import forms
from django.shortcuts import redirect
from django.shortcuts import render
from django.views.generic import DetailView, ListView, TemplateView
from django.views.generic.edit import CreateView
from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy
from django.template import Context
from django.template.loader import render_to_string, get_template
from django.core.mail import EmailMessage
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from mezzanine.conf import settings
from organization.job.models import JobOffer, JobResponse
from organization.job.forms import JobResponseForm

extention = ['.pdf', '.PDF', '.doc', '.docx']


class JobOfferDetailView(CreateView):

    model = JobResponse
    template_name='job/job_offer_detail.html'
    context_object_name = 'job_offer'
    form_class = JobResponseForm

    def get_context_data(self, **kwargs):
        context = super(JobOfferDetailView, self).get_context_data(**kwargs)
        context['job_offer'] = self.job_offer
        return context

    def get_initial(self):
        initial = super(JobOfferDetailView, self).get_initial()
        self.job_offer = get_object_or_404(JobOffer, slug=self.kwargs['slug'])
        initial['job_offer'] = self.job_offer
        return initial

    def get_success_url(self):
        return reverse_lazy('organization-job-offer-detail', kwargs={'slug':self.kwargs['slug']})

    def form_valid(self, form):
        # check extension uploaded files
        name_cv, ext_cv = os.path.splitext(form.cleaned_data['curriculum_vitae'].name)
        name_cl, ext_cl = os.path.splitext(form.cleaned_data['cover_letter'].name)
        if ext_cv not in extention or ext_cl not in extention :
            messages.info(self.request, _("Only .pdf, .doc, .docx files allowed."))
            return super(JobOfferDetailView, self).form_invalid(form)

        email_application_notification(self.request, self.job_offer, form.cleaned_data)
        messages.info(self.request, _("You have successfully submitted your application."))
        return super(JobOfferDetailView, self).form_valid(form)


class JobOfferListView(ListView):

    model = JobOffer
    template_name='job/job_offer_list.html'
{'fraction_non_alphanumeric': 0.09256604546385419, 'fraction_numerical': 0.0012287528158918697, 'mean_word_length': 4.245972073039742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2818680', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1403, 'n_words': 334}