Exemplo n.º 1
0
def sign_validation(request):
    """This method test if a form is valide return to a dictionary

    Args:
       request (request): views request

    Returns:
        dictionary: "methode": "", "value": ""
    """
    result_dict = {"methode": "", "value": ""}
    form = CustomUserCreationForm(request.POST)
    if form.is_valid():
        form.clean_password2()
        form.clean_email()
        form.clean_pseudo()
        user = form.save()
        login(request, user)
        result_dict["methode"] = "redirect"
        result_dict["value"] = "account"
        result_dict["user_is_connect"] = True
        return result_dict
    else:
        result_dict["user_is_connect"] = False
        result_dict["methode"] = "render"
        result_dict["value"] = "auth/sign_in.html"
        result_dict["form"] = form
        return result_dict
Exemplo n.º 2
0
def login_post(request):
    redirect_to = make_redirect_to(request)
    form_has_no_captcha = False
    if 'captcha_0' in request.POST or cache_get(request):
        form = SecureAuthenticationForm(data=request.POST, label_suffix="")
    else:
        form_has_no_captcha = True
        form = AuthenticationForm(data=request.POST, label_suffix="")
    try:
        if form.is_valid():
            cache_delete(request)
            auth_login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
        else:
            cache_set(request)
            if form_has_no_captcha:
                form = SecureAuthenticationForm(data=request.POST,
                                                label_suffix="")
            return render_login(request,
                                CustomUserCreationForm(label_suffix=""), form,
                                redirect_to)
    except ValueError:
        cache_set(request)
        if form_has_no_captcha:
            form = SecureAuthenticationForm(data=request.POST, label_suffix="")
        return render_login(request, CustomUserCreationForm(label_suffix=""),
                            form, redirect_to)
Exemplo n.º 3
0
def create_user(request):
    redirect_to = make_redirect_to(request)
    form = CustomUserCreationForm(request.POST, label_suffix="")
    if form.is_valid():
        new_user = form.save()
        user = authenticate(username=new_user.username,
                            password=form.cleaned_data['password1'])
        auth_login(request, user)
        return HttpResponseRedirect(redirect_to)
    else:
        return render_login(request, form, AuthenticationForm(label_suffix=""), redirect_to)
Exemplo n.º 4
0
def create_user(request):
    redirect_to = make_redirect_to(request)
    form = CustomUserCreationForm(request.POST, label_suffix="")
    if form.is_valid():
        new_user = form.save()
        user = authenticate(username=new_user.username,
                            password=form.cleaned_data['password1'])
        langs = get_user_languages_from_cookie(request)
        for l in langs:
            UserLanguage.objects.get_or_create(user=user, language=l)        
        auth_login(request, user)
        return HttpResponseRedirect(redirect_to)
    else:
        return render_login(request, form, AuthenticationForm(label_suffix=""), redirect_to)
Exemplo n.º 5
0
def create_user(request):
    redirect_to = make_redirect_to(request)
    form = CustomUserCreationForm(request.POST, label_suffix="")
    if form.is_valid():
        new_user = form.save()
        user = authenticate(username=new_user.username,
                            password=form.cleaned_data['password1'])
        langs = get_user_languages_from_cookie(request)
        for l in langs:
            UserLanguage.objects.get_or_create(user=user, language=l)
        auth_login(request, user)
        return HttpResponseRedirect(redirect_to)
    else:
        return render_login(request, form, AuthenticationForm(label_suffix=""), redirect_to)
Exemplo n.º 6
0
def login_post(request):
    redirect_to = make_redirect_to(request)
    form = AuthenticationForm(data=request.POST, label_suffix="")
    try:
        if form.is_valid():
            auth_login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
        else:
            return render_login(request,
                                CustomUserCreationForm(label_suffix=""), form,
                                redirect_to)
    except ValueError:
        return render_login(request, CustomUserCreationForm(label_suffix=""),
                            form, redirect_to)
Exemplo n.º 7
0
def login(request):
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    if cache_get(request):
        form = SecureAuthenticationForm(label_suffix="")
    else:
        form = AuthenticationForm(label_suffix="")
    return render_login(request, CustomUserCreationForm(label_suffix=""), form,
                        redirect_to)
Exemplo n.º 8
0
def login(request):
    redirect_to = post_or_get_value(request, REDIRECT_FIELD_NAME, '')
    if login_form_needs_captcha(request):
        form = SecureAuthenticationForm(label_suffix="")
    else:
        form = AuthenticationForm(label_suffix="")
    return render_login(request, CustomUserCreationForm(label_suffix=""), form,
                        redirect_to)
Exemplo n.º 9
0
def confirm_create_user(request, account_type, email):
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            if account_type == 'facebook':
                return facebook_login(request,
                                      next=redirect_to,
                                      confirmed=True,
                                      email=email)
            if account_type == 'google':
                return google_login(request,
                                    next=redirect_to,
                                    confirmed=True,
                                    email=email)
            if account_type == 'twitter':
                return twitter_login(request,
                                     next=redirect_to,
                                     confirmed=True,
                                     email=email)
            if account_type == 'openid':
                pass
            if account_type == 'ted':
                provider = get_authentication_provider('ted')
                return provider.view(request, confirmed=True, email=email)
            if account_type == 'udacity':
                request.session['openid_provider'] = 'Udacity'
                return begin_openid(
                    request,
                    user_url='https://www.udacity.com/openid/server',
                    redirect_to=reverse('socialauth_udacity_complete',
                                        args=(email, )),
                    confirmed=True)
    else:
        initial = {}
        if email:
            initial['email'] = email
        form = EmailForm(initial=initial)
    return render_login(request,
                        CustomUserCreationForm(label_suffix=""),
                        AuthenticationForm(label_suffix=""),
                        redirect_to,
                        email_form=form,
                        confirm_type=account_type)
Exemplo n.º 10
0
def confirm_create_user(request, account_type, email):
    redirect_to = post_or_get_value(request, REDIRECT_FIELD_NAME, '')
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            if account_type == 'facebook':
                return facebook_login(request,
                                      next=redirect_to,
                                      confirmed=True,
                                      email=email,
                                      form_data=form.cleaned_data)
            if account_type == 'google':
                return google_login(request,
                                    next=redirect_to,
                                    confirmed=True,
                                    email=email)
            if account_type == 'twitter':
                return twitter_login(request,
                                     next=redirect_to,
                                     confirmed=True,
                                     email=email)
            if account_type == 'ted':
                provider = get_authentication_provider('ted')
                return provider.view(request, confirmed=True, email=email)
    else:
        initial = {}
        if email:
            initial['email'] = email
        openid_url = request.GET.get('openid_url', '')
        if openid_url:
            initial['url'] = openid_url
        form = EmailForm(initial=initial)
    return render_login(request,
                        CustomUserCreationForm(label_suffix=""),
                        AuthenticationForm(label_suffix=""),
                        redirect_to,
                        email_form=form,
                        confirm_type=account_type)
Exemplo n.º 11
0
def login(request):
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    return render_login(request, CustomUserCreationForm(label_suffix=""),
                        AuthenticationForm(label_suffix=""), redirect_to)
Exemplo n.º 12
0
def manage(request):
    # init variables
    dict = {}
    zipped_subm = []
    zipped_reviewers = []
    zipped_reviewers_pcount = []
    zipped_papers = []
    zipped_program = []
    conference_id = 1

    # Create formset factories.
    submissions_factory = modelformset_factory(Paper, extra=0, can_delete='True', form=SubmissionsForm)
    assign_reviewers_factory = modelformset_factory(Paper, extra=0, can_delete='True', form=AssignReviewersForm)
    paper_factory = modelformset_factory(Paper, extra=0, can_delete='False', form=ManagePapersForm)

    # Create formsets from factories.
    subm_formset = submissions_factory(None)
    reviewers_formset = assign_reviewers_factory(None, queryset=Paper.objects.all().filter(decision_include=1)) #queryset=Paper.objects.none()
    paper_formset = paper_factory(None, queryset=Paper.objects.all().filter(decision_include=1))

    # Create forms.
    add_reviewer_form = CustomUserCreationForm(None)
    edit_conference_form = ConferenceDatesForm(None, instance=Conference.objects.get(id=conference_id))

    if request.method == 'POST':

        # if submission form is submitted, save instances.
        if 'submission-form-submit' in request.POST:
            subm_formset = submissions_factory(request.POST)
            if subm_formset.is_valid():
                instances = subm_formset.save()
                for instance in instances:
                    instance.save()

        # if assign-reviewers form is submitted, save instances.
        elif 'reviewers-form-submit' in request.POST:

            # exclude(paper_file='') - exclude those papers where paper_file=None
            reviewers_formset = assign_reviewers_factory(request.POST, queryset=Paper.objects.all().filter(decision_include=1))
            if reviewers_formset.is_valid():
                instances = reviewers_formset.save()
                for instance in instances:
                    instance.save()
                return redirect('/manage/#assign-reviewers')

        # if add-reviewer form is submitted, create a new user and assign a reviewer profile.
        elif 'add-reviewer' in request.POST:
            add_reviewer_form = CustomUserCreationForm(request.POST)
            if add_reviewer_form.is_valid():
                u = add_reviewer_form.save()
                u.is_reviewer = True
                u.save()
                rp = ReviewerProfile.objects.create(user=u)

        elif 'deadlines-form' in request.POST:
            edit_conference_form = ConferenceDatesForm(request.POST, instance=Conference.objects.get(id=conference_id))
            if edit_conference_form.is_valid():
                edit_conference_form.save()

        elif 'paper-form-submit' in request.POST:
            paper_formset = paper_factory(request.POST, queryset=Paper.objects.all().filter(decision_include='1'))
            if paper_formset.is_valid():
                instances = paper_formset.save()
                for instance in instances:

                    # If corrections are needed...
                    if instance.decision_publicize == '2':
                        a=1
                        # instance.prev_decision_publicize = instance.decision_publicize
                        # instance.prev_paper_file = instance.paper_file
                        # instance.prev_theses_file = instance.theses_file
                        # instance.save()
                        # instance.decision_publicize = '0'
                        # instance.paper_file = None
                        # instance.theses_file = None
                        # for rev in instance.review.all():
                        #    instance.review.remove(rev)

                    # If paper is denied ...
                    elif instance.decision_publicize == '3':
                        a=2

                    # If paper is not denied and no corrections are needed, just save the paper and all is good.
                    instance.save()
                return redirect('/manage/#papers')


        # Update submission order in program
        elif 'order' in request.POST:
            list = request.POST.getlist('order')[0].split('&')
            for i,item in enumerate(list):
                list[i]=item.split('=')[1]
            for i, item in enumerate(list):
                p=Paper.objects.get(id=item)
                p.prog_num = i
                p.save()
            a=2

    # Create tuples of form and paper form sumbmissions tab.
    for i, subm_form in enumerate(subm_formset):
        paper=Paper.objects.all()[i]
        zipped_subm.append((paper, subm_form))

    # Create tuples of form and paper for assign-reviewers tab.
    for i, reviewers_form in enumerate(reviewers_formset):
        paper=Paper.objects.all().filter(decision_include=1)[i]
        zipped_reviewers.append((paper, reviewers_form))

    # Create tuples of reviewer and the paper count assigned to reviewer
    for i, reviewer in enumerate(ReviewerProfile.objects.all()):
        count = Paper.objects.all().filter(reviewer=reviewer).count()
        zipped_reviewers_pcount.append((reviewer, count))

    # Create tuples of decision_publicize and paper
    for i, paper_form in enumerate(paper_formset):
        paper_points = 0
        paper_avg = 0
        paper=Paper.objects.all().filter(decision_include=1)[i]
        j=0
        for rev in Review.objects.all().filter(paper_id=paper):
            try:
                paper_points += rev.review_paper.avg_points
                j+=1
            except:
                pass
        if j:
            paper_avg = paper_points/j
        zipped_papers.append((paper,paper_form, paper_avg))

    for i, paper in enumerate(Paper.objects.all().order_by('prog_num')):
        if paper.decision_publicize == '1' or paper.decision_publicize_corr == '1':
            zipped_program.append(paper)


    reviews = Review.objects.all()

    # other dicts.
    dict['papers'] = Paper.objects.all()
    dict['study_prog_dict'] = STUDY_PROG_LVL
    dict['DICT_REVIEW_TOTAL'] = settings.DICT_REVIEW_TOTAL
    dict['DICT_REVIEW_RECOM'] = settings.DICT_REVIEW_RECOM
    dict['reviewers'] = ReviewerProfile.objects.all()
    dict['zipped_reviewers_pcount'] = zipped_reviewers_pcount
    dict['reviews'] = reviews

    # dict for sumbissions tab.
    dict['subm_formset'] = subm_formset
    dict['zipped_subm'] = zipped_subm

    # dict for assign-reviewers tab.
    dict['zipped_reviewers'] = zipped_reviewers
    dict['reviewers_formset'] = reviewers_formset

    # dict for papers tab.
    dict['paper_formset'] = paper_formset
    dict['zipped_papers'] = zipped_papers

    # dict for add-reviewer tab.
    dict['add_reviewer_form'] = add_reviewer_form

    # dict for deadlines tab.
    dict['edit_conference_form'] = edit_conference_form

    # dict for program
    dict['zipped_program'] = zipped_program

    return render(request, 'manage/manage.html', dict)