<commit_before>from django.shortcuts               import render
from django.http                    import HttpResponse, HttpResponseRedirect, Http404
from django.contrib.auth.decorators import login_required
from django.contrib.formtools.wizard.views import SessionWizardView
from django.utils.decorators        import method_decorator
from django.views.generic.edit      import CreateView, UpdateView, DeleteView
from django.views.generic           import ListView, DetailView, RedirectView
from django.core.urlresolvers       import reverse
from registration.backends.simple.views import RegistrationView
from itertools import chain

from sysrev.models import *
from sysrev.forms  import *


class SRRegistrationView(RegistrationView):
    def get_success_url(self, user=None):
        return "/"

class ProfileView(UpdateView):
    template_name = "sysrev/profile_form.html"
    form_class    = ProfileForm
    model         = User
    success_url   = "#"

    def get_object(self, queryset=None):
        return self.request.user

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ProfileView, self).dispatch(*args, **kwargs)







class ReviewListView(ListView):
    model = Review

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

        in_progress_reviews = Review.objects.order_by('-last_modified').filter(participants=self.request.user, completed=False)
        completed_reviews   = Review.objects.order_by('-last_modified').filter(participants=self.request.user, completed=True)
        reviews             = list(chain(in_progress_reviews, completed_reviews))

        for i in range(0, len(reviews)):
            reviews[i] = {"review":  reviews[i],
                          "count":   reviews[i].paper_pool_counts(),
                          "percent": reviews[i].paper_pool_percentages()}

        context["reviews"] = reviews
        return context

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ReviewListView, self).dispatch(*args, **kwargs)



class ReviewDetailView(DetailView):
    model = Review

    def get_context_data(self, object=None):
        context = {}
        try:
            if self.request.user in object.participants.all():
                context["review"]  = object
                context["count"]   = object.paper_pool_counts()
                context["percent"] = object.paper_pool_percentages()
                context["final_papers"] = Paper.objects.filter(review=object, pool="F")
                context["rejected_papers"] = Paper.objects.filter(review=object, pool="R")
            else:
                raise Http404("Review not found")
        except Review.DoesNotExist:
            raise Http404("Review not found")
        return context

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ReviewDetailView, self).dispatch(*args, **kwargs)


class ReviewUpdateView(UpdateView):
    model  = Review
    fields = ['title', 'description', 'participants', 'query']


class ReviewDeleteView(DeleteView):
    model       = Review
    success_url = "/"






class WorkView(RedirectView):
    def get(self, request, *args, **kwargs):
        try:
            review = Review.objects.get(pk=self.kwargs['pk'])
            papers = Paper.objects.filter(review=review)
            counts = review.paper_pool_counts()
            pk = ""
            if counts["abstract"] > 0:
                pk = papers.filter(pool="A").first().pk
            elif counts["document"] > 0:
                pk = papers.filter(pool="D").first().pk
            else:
                # TODO: redirect to final pool page
                pass
            self.url = request.path[:-5] + str(pk) + "/"
            return super(WorkView, self).get(request, args, **kwargs)
        except Review.DoesNotExist:
            raise Http404("Paper not found")<commit_msg>Fix update view redirect<commit_after>from django.shortcuts               import render
from django.http                    import HttpResponse, HttpResponseRedirect, Http404
from django.contrib.auth.decorators import login_required
from django.contrib.formtools.wizard.views import SessionWizardView
from django.utils.decorators        import method_decorator
from django.views.generic.edit      import CreateView, UpdateView, DeleteView
from django.views.generic           import ListView, DetailView, RedirectView
from django.core.urlresolvers       import reverse
from registration.backends.simple.views import RegistrationView
from itertools import chain

from sysrev.models import *
from sysrev.forms  import *


class SRRegistrationView(RegistrationView):
    def get_success_url(self, user=None):
        return "/"


class ProfileView(UpdateView):
    template_name = "sysrev/profile_form.html"
    form_class    = ProfileForm
    model         = User
    success_url   = "#"

    def get_object(self, queryset=None):
        return self.request.user

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ProfileView, self).dispatch(*args, **kwargs)







class ReviewListView(ListView):
    model = Review

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

        in_progress_reviews = Review.objects.order_by('-last_modified').filter(participants=self.request.user, completed=False)
        completed_reviews   = Review.objects.order_by('-last_modified').filter(participants=self.request.user, completed=True)
        reviews             = list(chain(in_progress_reviews, completed_reviews))

        for i in range(0, len(reviews)):
            reviews[i] = {"review":  reviews[i],
                          "count":   reviews[i].paper_pool_counts(),
                          "percent": reviews[i].paper_pool_percentages()}

        context["reviews"] = reviews
        return context

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ReviewListView, self).dispatch(*args, **kwargs)



class ReviewDetailView(DetailView):
    model = Review

    def get_context_data(self, object=None):
        context = {}
        try:
            if self.request.user in object.participants.all():
                context["review"]  = object
                context["count"]   = object.paper_pool_counts()
                context["percent"] = object.paper_pool_percentages()
                context["final_papers"] = Paper.objects.filter(review=object, pool="F")
                context["rejected_papers"] = Paper.objects.filter(review=object, pool="R")
            else:
                raise Http404("Review not found")
        except Review.DoesNotExist:
            raise Http404("Review not found")
        return context

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ReviewDetailView, self).dispatch(*args, **kwargs)


class ReviewUpdateView(UpdateView):
    model  = Review
    fields = ['title', 'description', 'participants', 'query']

    def get_success_url(self):
        return self.request.path[:-7]


class ReviewDeleteView(DeleteView):
    model       = Review
    success_url = "/"






class WorkView(RedirectView):
    def get(self, request, *args, **kwargs):
        try:
            review = Review.objects.get(pk=self.kwargs['pk'])
            papers = Paper.objects.filter(review=review)
            counts = review.paper_pool_counts()
            pk = ""
            if counts["abstract"] > 0:
                pk = papers.filter(pool="A").first().pk
            elif counts["document"] > 0:
                pk = papers.filter(pool="D").first().pk
            else:
                # TODO: redirect to final pool page
                pass
            self.url = request.path[:-5] + str(pk) + "/"
            return super(WorkView, self).get(request, args, **kwargs)
        except Review.DoesNotExist:
            raise Http404("Paper not found")
{'fraction_non_alphanumeric': 0.1085453198320573, 'fraction_numerical': 0.004075080266732527, 'mean_word_length': 2.663048394391678, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, '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': '756262', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2152, 'n_words': 472}