Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        f = UserInfoForm(request.POST, instance=request.user)
        pref = UserPreferencesForm(request.POST, instance=get_user_preferences(request.user))
        passwd = None
        valid = f.is_valid() and pref.is_valid()

        if "changing_password" in request.POST:
            passwd = PasswordChangeForm(user=request.user, data=request.POST)

            if passwd.is_valid():
                new_password = passwd.cleaned_data['new_password']
                # Bind the password change to the main form change. If there's an error there, don't change the password
                f.instance.set_password(new_password)
            else:
                valid = False

        if valid:
            pref.save()
            f.save()
            messages.success(request, 'Account information updated')
            return redirect('profile')
        else:
            ctx = {
                'form': f,
                'pref_form': pref,
                'pass_form': passwd if passwd else PasswordChangeForm(user=request.user),
            }
            return render_to_response(self.template, ctx, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def scan_history(request, hide_zero='', template='plag/dynamic/scan_history.html'):
    ctx = {}

    finds = AccountPlagiarismScans.get_historical_finds(request.user.id, True if hide_zero else False)

    user_pref = get_user_preferences(request.user)
    if user_pref and user_pref.results_per_page:
        results_per_page = user_pref.results_per_page
    else:
        results_per_page = const.RESULTS_PER_PAGE

    # https://docs.djangoproject.com/en/1.7/topics/pagination/
    paginator = Paginator(finds, results_per_page)

    page = request.GET.get('page')
    try:
        results = paginator.page(page)
    except PageNotAnInteger:
        results = paginator.page(1)
    except EmptyPage:
        results = paginator.page(paginator.num_pages)

    ctx.update({'results': results})
    ctx.update({'hide_zero': hide_zero})

    return render_to_response(template, ctx, context_instance=RequestContext(request))
Ejemplo n.º 3
0
    def get(self, request, *args, **kwargs):
        ctx = {
            'form': UserInfoForm(instance=request.user),
            'pref_form': UserPreferencesForm(instance=get_user_preferences(request.user)),
            'pass_form': PasswordChangeForm(user=request.user),
        }

        return render_to_response(self.template, ctx, context_instance=RequestContext(request))