<commit_before>from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render,  redirect
from django.core.urlresolvers import reverse
from django.views.generic import FormView
from django.contrib.sites.models import Site
from django.contrib import messages

from ummeli.opportunities.models import Job, UmmeliOpportunity, StatusUpdate, SkillsUpdate
from ummeli.vlive.forms import EmailCVForm, FaxCVForm
from ummeli.vlive.community.forms import StatusUpdateForm


current_site = Site.objects.get_current()


def community_jobs(request):
    posts = UmmeliOpportunity.objects.filter(is_community=True).order_by('-created')

    paginator = Paginator(posts, 15)  # Show 15 contacts per page
    page = request.GET.get('page', 'none')

    try:
        paged_posts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        paged_posts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        paged_posts = paginator.page(paginator.num_pages)
    return render(request, 'opportunities/jobs/community_jobs.html',
                  {'articles': paged_posts})


def community_job(request, slug):
    form = None
    if not UmmeliOpportunity.objects.filter(slug=slug):
        return redirect(reverse('community_jobs'))  # Sorry, this ad has been removed.
    article = UmmeliOpportunity.objects.get(slug=slug)

    if request.method == 'POST':
        if(request.POST.get('send_via') == 'email'):
            form = EmailCVForm(data=request.POST)
        else:
            form = FaxCVForm(data=request.POST)

        user_profile = request.user.get_profile()

        if form.is_valid() and not user_profile.missing_fields():
            send_via = form.cleaned_data['send_via']
            send_to = form.cleaned_data['send_to']

            if send_via == 'email':
                user_profile.email_cv(send_to,  article.description)
                return redirect(reverse('community_jobs'))
            else:
                user_profile.fax_cv(send_to, article.description)
                return redirect(reverse('community_jobs'))

    return render(request, 'opportunities/jobs/community_job.html',
                  {'job': article, 'form':  form})


class StatusUpdateView(FormView):
    """
    Renders and handles user status update view/form.
    """
    form_class = StatusUpdateForm
    template_name = "profile/community/status_edit.html"

    def get_context_data(self, *args, **kwargs):
        context = super(StatusUpdateView, self).get_context_data(*args, **kwargs)
        context.update({
            'statuses': StatusUpdate.objects.order_by('-created')[:5],
        })
        return context

    def form_valid(self, form):
        title = form.cleaned_data['title']
        s = StatusUpdate.objects.create(title=title,
                                        owner=self.request.user,
                                        state='published',
                                        is_community=True)
        s.sites.add(current_site)
        s.save()
        return redirect(reverse('status_update'))


def advertise_skills_post(request):
    if request.method == 'POST':
        s = SkillsUpdate.objects.create(title=request.user.username,
                                        owner=request.user,
                                        is_community=True,
                                        state='published')
        s.sites.add(current_site)
        s.save()
        msg = 'You skills have been posted.'
        messages.success(request, msg)
    return redirect(reverse('index'))<commit_msg>added messages for community views<commit_after>from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render,  redirect
from django.core.urlresolvers import reverse
from django.views.generic import FormView
from django.contrib.sites.models import Site
from django.contrib import messages

from ummeli.opportunities.models import Job, UmmeliOpportunity, StatusUpdate, SkillsUpdate
from ummeli.vlive.forms import EmailCVForm, FaxCVForm
from ummeli.vlive.community.forms import StatusUpdateForm


current_site = Site.objects.get_current()


def community_jobs(request):
    posts = UmmeliOpportunity.objects.filter(is_community=True).order_by('-created')

    paginator = Paginator(posts, 15)  # Show 15 contacts per page
    page = request.GET.get('page', 'none')

    try:
        paged_posts = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        paged_posts = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        paged_posts = paginator.page(paginator.num_pages)
    return render(request, 'opportunities/jobs/community_jobs.html',
                  {'articles': paged_posts})


def community_job(request, slug):
    form = None
    if not UmmeliOpportunity.objects.filter(slug=slug):
        return redirect(reverse('community_jobs'))  # Sorry, this ad has been removed.
    article = UmmeliOpportunity.objects.get(slug=slug)

    if request.method == 'POST':
        if(request.POST.get('send_via') == 'email'):
            form = EmailCVForm(data=request.POST)
        else:
            form = FaxCVForm(data=request.POST)

        user_profile = request.user.get_profile()

        if form.is_valid() and not user_profile.missing_fields():
            send_via = form.cleaned_data['send_via']
            send_to = form.cleaned_data['send_to']

            if send_via == 'email':
                user_profile.email_cv(send_to,  article.description)
                msg = 'You email has been sent.'
                messages.success(request, msg)
                return redirect(reverse('community_jobs'))
            else:
                user_profile.fax_cv(send_to, article.description)
                msg = 'You fax has been sent.'
                messages.success(request, msg)
                return redirect(reverse('community_jobs'))

    return render(request, 'opportunities/jobs/community_job.html',
                  {'job': article, 'form':  form})


class StatusUpdateView(FormView):
    """
    Renders and handles user status update view/form.
    """
    form_class = StatusUpdateForm
    template_name = "profile/community/status_edit.html"

    def get_context_data(self, *args, **kwargs):
        context = super(StatusUpdateView, self).get_context_data(*args, **kwargs)
        context.update({
            'statuses': StatusUpdate.objects.order_by('-created')[:5],
        })
        return context

    def form_valid(self, form):
        title = form.cleaned_data['title']
        s = StatusUpdate.objects.create(title=title,
                                        owner=self.request.user,
                                        state='published',
                                        is_community=True)
        s.sites.add(current_site)
        s.save()
        msg = 'You status has been updated.'
        messages.success(self.request, msg)
        return redirect(reverse('status_update'))


def advertise_skills_post(request):
    if request.method == 'POST':
        s = SkillsUpdate.objects.create(title=request.user.username,
                                        owner=request.user,
                                        is_community=True,
                                        state='published')
        s.sites.add(current_site)
        s.save()
        msg = 'You skills have been posted.'
        messages.success(request, msg)
    return redirect(reverse('index'))
{'fraction_non_alphanumeric': 0.09961038961038961, 'fraction_numerical': 0.0025974025974025974, 'mean_word_length': 2.430289532293987, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3287728', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2053, 'n_words': 463}