<commit_before># -*- coding: utf-8 -*-

u"""
.. module:: offers
"""

from django.contrib import messages
from django.contrib.admin.models import ADDITION
from django.contrib.admin.models import CHANGE
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.shortcuts import render
from django.utils.text import slugify
from django.views.generic import View

from volontulo.forms import CreateOfferForm
from volontulo.forms import OfferApplyForm
from volontulo.lib.email import send_mail
from volontulo.models import Offer
from volontulo.models import UserProfile
from volontulo.utils import OFFERS_STATUSES
from volontulo.utils import save_history
from volontulo.views import logged_as_admin


def offers_list(request):
    u"""View, that show list of offers.

    It's used for volunteers to show active ones and for admins to show
    all of them.
    """
    if logged_as_admin(request):
        offers = Offer.objects.all()
    else:
        offers = Offer.objects.filter(status='ACTIVE')
    return render(request, "offers/offers_list.html", context={
        'offers': offers,
    })


class OffersCreate(View):
    u"""Class view supporting creation of new offer."""

    @staticmethod
    def get(request):
        u"""Method responsible for rendering form for new offer."""
        user = UserProfile.objects.get(user=request.user)
        organization = user.organization

        form = CreateOfferForm()
        context = {
            'offer_form': form,
            'organization': organization,
            'statuses': OFFERS_STATUSES,
            'user': user,
            'offer': Offer(),
        }

        return render(
            request,
            'offers/offer_form.html',
            context
        )

    @staticmethod
    def post(request):
        u"""Method resposible for saving new offer."""
        user = UserProfile.objects.get(user=request.user)
        organization = user.organization
        form = CreateOfferForm(request.POST)

        if form.is_valid():
            offer = form.save()
            save_history(request, offer, action=ADDITION)
            ctx = {
                'domain': request.build_absolute_uri().replace(
                    request.get_full_path(),
                    ''
                ),
                'address_sufix': reverse(
                    'show_offer',
                    args=[organization.id, offer.id]
                ),
                'offer': offer
            }
            send_mail(
                'offer_creation',
                ['<EMAIL>'],
                ctx
            )
            messages.add_message(
                request,
                messages.SUCCESS,
                u"Dziękujemy za dodanie oferty."
            )
            return redirect(
                reverse(
                    'show_offer',
                    args=[organization.id, offer.id]
                ),
            )
        messages.add_message(
            request,
            messages.ERROR,
            u"Formularz zawiera niepoprawnie wypełnione pola"
        )
        return render(
            request,
            'offers/offer_form.html',
            {
                'offer_form': form,
                'organization': organization,
                'statuses': OFFERS_STATUSES,
                'user': user,
                'offer': Offer()
            }
        )


class OffersEdit(View):
    u"""Class view supporting change of a offer."""

    @staticmethod
    def get(request, slug, offer_id):
        u"""Method responsible for rendering form for offer to be changed."""
        offer = Offer.objects.get(pk=offer_id)
        organization = offer.organization
        user = UserProfile.objects.get(user=request.user)
        form = CreateOfferForm()

        context = {
            'offer_form': form,
            'organization': organization,
            'statuses': OFFERS_STATUSES,
            'user': user,
            'offer': offer,
        }

        return render(
            request,
            'offers/offer_form.html',
            context
        )

    @staticmethod
    def post(request, slug, offer_id):
        u"""Method resposible for saving changed offer."""
        offer = Offer.objects.get(pk=offer_id)<commit_msg>#176 - pylint should ignore unused arguments<commit_after># -*- coding: utf-8 -*-

u"""
.. module:: offers
"""

from django.contrib import messages
from django.contrib.admin.models import ADDITION
from django.contrib.admin.models import CHANGE
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.shortcuts import render
from django.utils.text import slugify
from django.views.generic import View

from volontulo.forms import CreateOfferForm
from volontulo.forms import OfferApplyForm
from volontulo.lib.email import send_mail
from volontulo.models import Offer
from volontulo.models import UserProfile
from volontulo.utils import OFFERS_STATUSES
from volontulo.utils import save_history
from volontulo.views import logged_as_admin


def offers_list(request):
    u"""View, that show list of offers.

    It's used for volunteers to show active ones and for admins to show
    all of them.
    """
    if logged_as_admin(request):
        offers = Offer.objects.all()
    else:
        offers = Offer.objects.filter(status='ACTIVE')
    return render(request, "offers/offers_list.html", context={
        'offers': offers,
    })


class OffersCreate(View):
    u"""Class view supporting creation of new offer."""

    @staticmethod
    def get(request):
        u"""Method responsible for rendering form for new offer."""
        user = UserProfile.objects.get(user=request.user)
        organization = user.organization

        form = CreateOfferForm()
        context = {
            'offer_form': form,
            'organization': organization,
            'statuses': OFFERS_STATUSES,
            'user': user,
            'offer': Offer(),
        }

        return render(
            request,
            'offers/offer_form.html',
            context
        )

    @staticmethod
    def post(request):
        u"""Method resposible for saving new offer."""
        user = UserProfile.objects.get(user=request.user)
        organization = user.organization
        form = CreateOfferForm(request.POST)

        if form.is_valid():
            offer = form.save()
            save_history(request, offer, action=ADDITION)
            ctx = {
                'domain': request.build_absolute_uri().replace(
                    request.get_full_path(),
                    ''
                ),
                'address_sufix': reverse(
                    'show_offer',
                    args=[organization.id, offer.id]
                ),
                'offer': offer
            }
            send_mail(
                'offer_creation',
                ['<EMAIL>'],
                ctx
            )
            messages.add_message(
                request,
                messages.SUCCESS,
                u"Dziękujemy za dodanie oferty."
            )
            return redirect(
                reverse(
                    'show_offer',
                    args=[organization.id, offer.id]
                ),
            )
        messages.add_message(
            request,
            messages.ERROR,
            u"Formularz zawiera niepoprawnie wypełnione pola"
        )
        return render(
            request,
            'offers/offer_form.html',
            {
                'offer_form': form,
                'organization': organization,
                'statuses': OFFERS_STATUSES,
                'user': user,
                'offer': Offer()
            }
        )


class OffersEdit(View):
    u"""Class view supporting change of a offer."""

    @staticmethod
    def get(request, slug, offer_id):  # pylint: disable=unused-argument
        u"""Method responsible for rendering form for offer to be changed."""
        offer = Offer.objects.get(pk=offer_id)
        organization = offer.organization
        user = UserProfile.objects.get(user=request.user)
        form = CreateOfferForm()

        context = {
            'offer_form': form,
            'organization': organization,
            'statuses': OFFERS_STATUSES,
            'user': user,
            'offer': offer,
        }

        return render(
            request,
            'offers/offer_form.html',
            context
        )

    @staticmethod
    def post(request, slug, offer_id):  # pylint: disable=unused-argument
        u"""Method resposible for saving changed offer."""
        offer = Offer.objects.get(pk=offer_id)
{'fraction_non_alphanumeric': 0.09149440867502541, 'fraction_numerical': 0.0012425166610188637, 'mean_word_length': 1.821542383683875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4707679', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2263, 'n_words': 588}