<commit_before>from django import http
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.urls import reverse_lazy, reverse
from django.views import generic

from . import forms
from . import models


class QuoteListView(generic.TemplateView):
    template_name = 'quotes/all_quote_list.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['title'] = 'All Quotes'
        return context


class Dashboard(generic.TemplateView):
    template_name = 'quotes/dashboard.html'


class QuoteCreateView(generic.CreateView):
    template_name = 'quotes/quote_edit.html'
    model = models.Quote
    form_class = forms.QuoteForm
    success_url = reverse_lazy('quotes:quotes_list')

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['user'] = self.request.user
        return kwargs


class QuoteEditView(generic.UpdateView):
    template_name = 'quotes/quote_edit.html'
    model = models.Quote
    form_class = forms.QuoteForm
    success_url = reverse_lazy('quotes:quotes_list')

    def get(self, request, *args, **kwargs):
        response = super().get(request, *args, **kwargs)

        if self.request.user.id != self.object.user.id:
            raise PermissionDenied

        return response

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['user'] = self.request.user
        return kwargs


class UserQuoteListView(generic.DetailView):
    model = User
    slug_field = "username"
    template_name = 'quotes/quote_list.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        full_name = self.object.get_full_name()
        name = full_name if full_name else self.object.username

        title = "My Quotes" if self.request.user.is_authenticated() else "{name}'s quotes".format(name=name)
        context['title'] = title

        if self.request.user.is_authenticated():
            context['form'] = forms.AngularQuoteForm(user=self.request.user)

        return context


class HomePageView(generic.TemplateView):
    template_name = 'quotes/homepage.html'

    def dispatch(self, request, *args, **kwargs):
        if self.request.user.is_authenticated():
            return http.HttpResponseRedirect(reverse('quotes:profile', args=[request.user.username]))

        return super().dispatch(request, *args, **kwargs)
<commit_msg>Fix redirection after editing quote<commit_after>from django import http
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.urls import reverse_lazy, reverse
from django.views import generic

from . import forms
from . import models


class QuoteListView(generic.TemplateView):
    template_name = 'quotes/all_quote_list.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['title'] = 'All Quotes'
        return context


class Dashboard(generic.TemplateView):
    template_name = 'quotes/dashboard.html'


class QuoteCreateView(generic.CreateView):
    template_name = 'quotes/quote_edit.html'
    model = models.Quote
    form_class = forms.QuoteForm
    success_url = reverse_lazy('quotes:quotes_list')

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['user'] = self.request.user
        return kwargs


class QuoteEditView(generic.UpdateView):
    template_name = 'quotes/quote_edit.html'
    model = models.Quote
    form_class = forms.QuoteForm

    def get(self, request, *args, **kwargs):
        response = super().get(request, *args, **kwargs)

        if self.request.user.id != self.object.user.id:
            raise PermissionDenied

        return response

    def get_success_url(self):
        return reverse('quotes:profile', args=[self.request.user.username])

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['user'] = self.request.user
        return kwargs


class UserQuoteListView(generic.DetailView):
    model = User
    slug_field = "username"
    template_name = 'quotes/quote_list.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        full_name = self.object.get_full_name()
        name = full_name if full_name else self.object.username

        title = "My Quotes" if self.request.user.is_authenticated() else "{name}'s quotes".format(name=name)
        context['title'] = title

        if self.request.user.is_authenticated():
            context['form'] = forms.AngularQuoteForm(user=self.request.user)

        return context


class HomePageView(generic.TemplateView):
    template_name = 'quotes/homepage.html'

    def dispatch(self, request, *args, **kwargs):
        if self.request.user.is_authenticated():
            return http.HttpResponseRedirect(reverse('quotes:profile', args=[request.user.username]))

        return super().dispatch(request, *args, **kwargs)

{'fraction_non_alphanumeric': 0.10957551826258638, 'fraction_numerical': 0.0, 'mean_word_length': 3.455584872471416, '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': '2600181', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1453, 'n_words': 311}