Beispiel #1
0
def user_dashboard(request):
    if not request.user.is_valid_speaker():
        return redirect('user_profile_update')
    logout_next = reverse('login')
    return render(request, 'users/user_dashboard.html', {
        'logout_next': logout_next,
        **proposals_state()._asdict(),
        **reviews_state()._asdict(),
    })
Beispiel #2
0
def coc_agree(request):
    if request.method == 'POST':
        form = CocAgreementForm(data=request.POST)
        if form.is_valid():
            try:
                agreement = CocRecord.objects.get(
                    user=request.user, coc_version=settings.COC_VERSION)
            except CocRecord.DoesNotExist:
                agreement = CocRecord(user=request.user,
                                      coc_version=settings.COC_VERSION)

            agreement.save()

            # The query param indicating redirect target (setup by CocAgreementMixin) can be removed after set_language.
            # Redirect to dashboard intead if this situation happened.
            redirect_to = request.GET.get('next', reverse('user_dashboard'))
            return redirect(redirect_to)
    else:
        form = CocAgreementForm()

    # Get code of conduct
    lang = get_language()
    content = render_to_string(
        'contents/%s/about/code-of-conduct.html' % lang[:2], {}, request)
    tree = lxml.html.document_fromstring(content)
    main = tree.xpath('//main')[0]

    # Remove the title
    # Since the HTML structure has changed
    # need to find the direct child from main which contains h1 as its descendant
    # and remove it
    for h1 in main.xpath('//h1'):
        target = h1
        parent = h1.getparent()

        while parent != main and parent is not None:
            target = parent
            parent = parent.getparent()

        if parent == main:
            main.remove(target)

    coc = etree.tostring(main, encoding='utf-8').decode('utf-8')

    return render(request, 'users/coc_agreement.html', {
        'form': form,
        'coc': coc,
        **reviews_state()._asdict(),
    })
Beispiel #3
0
def user_profile_update(request):
    logout_next = reverse('index')
    if request.method == 'POST':
        form = UserProfileUpdateForm(
            data=request.POST, files=request.FILES,
            instance=request.user,
        )
        if form.is_valid():
            form.save()
            messages.success(request, gettext(
                'Your profile has been updated successfully.',
            ))
            return redirect('user_dashboard')
    else:
        form = UserProfileUpdateForm(instance=request.user)
    return render(request, 'users/user_profile_update.html', {
        'form': form, 'logout_next': logout_next,
        **reviews_state()._asdict(),
    })
Beispiel #4
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context.update(**reviews_state()._asdict())
     return context
Beispiel #5
0
 def get_context_data(self, **kwargs):
     data = super().get_context_data(**kwargs)
     data.update(**reviews_state()._asdict())
     return data