Files @ f3614fcf5285
Branch filter:

Location: symposion_app/symposion/views.py

Patrick Altman
Merge branch 'master' of https://github.com/pyohio/symposion into pyohio-master

Conflicts:
README.md
symposion/boxes/urls.py
symposion/cms/urls.py
symposion/proposals/actions.py
symposion/proposals/urls.py
symposion/proposals/views.py
symposion/reviews/tests.py
symposion/reviews/urls.py
symposion/reviews/views.py
symposion/schedule/forms.py
symposion/schedule/models.py
symposion/schedule/views.py
symposion/speakers/fixture_gen.py
symposion/sponsorship/urls.py
symposion/templates/cms/file_create.html
symposion/templates/cms/file_index.html
symposion/templates/conference/user_list.html
symposion/templates/dashboard.html
symposion/templates/emails/proposal_new_message/message.html
symposion/templates/emails/proposal_updated/message.html
symposion/templates/emails/speaker_addition/message.html
symposion/templates/emails/speaker_invite/message.html
symposion/templates/proposals/_pending_proposal_row.html
symposion/templates/proposals/_proposal_fields.html
symposion/templates/proposals/_proposal_row.html
symposion/templates/proposals/proposal_cancel.html
symposion/templates/proposals/proposal_detail.html
symposion/templates/proposals/proposal_edit.html
symposion/templates/proposals/proposal_speaker_manage.html
symposion/templates/proposals/proposal_submit.html
symposion/templates/reviews/_review_table.html
symposion/templates/reviews/base.html
symposion/templates/reviews/result_notification.html
symposion/templates/reviews/result_notification_prepare.html
symposion/templates/reviews/review_admin.html
symposion/templates/reviews/review_assignment.html
symposion/templates/reviews/review_detail.html
symposion/templates/reviews/review_review.html
symposion/templates/reviews/review_stats.html
symposion/templates/schedule/_edit_grid.html
symposion/templates/schedule/_grid.html
symposion/templates/schedule/_slot_edit.html
symposion/templates/schedule/presentation_detail.html
symposion/templates/schedule/schedule_list.html
symposion/templates/speakers/speaker_create.html
symposion/templates/speakers/speaker_edit.html
symposion/templates/speakers/speaker_profile.html
symposion/templates/sponsorship/add.html
symposion/templates/sponsorship/apply.html
symposion/templates/sponsorship/detail.html
symposion/templates/sponsorship/list.html
symposion/templates/teams/team_detail.html
import hashlib
import random

from django.shortcuts import render, redirect

from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required

import account.views

import symposion.forms


class SignupView(account.views.SignupView):

    form_class = symposion.forms.SignupForm
    form_kwargs = {
        "prefix": "signup",
    }

    def create_user(self, form, commit=True):
        user_kwargs = {
            "first_name": form.cleaned_data["first_name"],
            "last_name": form.cleaned_data["last_name"]
        }
        return super(SignupView, self).create_user(form, commit=commit,
                                                   **user_kwargs)

    def generate_username(self, form):
        def random_username():
            h = hashlib.sha1(form.cleaned_data["email"]).hexdigest()[:25]
            # don't ask
            n = random.randint(1, (10 ** (5 - 1)) - 1)
            return "%s%d" % (h, n)
        while True:
            try:
                username = random_username()
                User.objects.get(username=username)
            except User.DoesNotExist:
                break
        return username


class LoginView(account.views.LoginView):

    form_class = account.forms.LoginEmailForm
    form_kwargs = {
        "prefix": "login",
    }


@login_required
def dashboard(request):
    if request.session.get("pending-token"):
        return redirect("speaker_create_token",
                        request.session["pending-token"])
    return render(request, "dashboard.html")