symposion_app/symposion/views.py
Hiroshi Miura a95825ede8 python3 compatibility
- Things are suggested in python3 porting guide.
https://docs.djangoproject.com/en/1.8/topics/python3/

     1. adding ```from django.utils.encoding import
     python_2_unicode_compatible```

     2. ``` __str__``` instead of ```__unicode__```
     https://docs.djangoproject.com/en/1.8/topics/python3/#str-and-unicode-methods

     3. Adding ```from __future__ import unicode_literals``` at the top
     of your Python modules
     https://docs.djangoproject.com/en/1.8/topics/python3/#unicode-literals

     4. Removing the `u` prefix before unicode strings;
     https://docs.djangoproject.com/en/1.8/topics/python3/#unicode-literals

- also closed #66

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
2015-08-03 23:32:25 +09:00

58 lines
1.6 KiB
Python

from __future__ import unicode_literals
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")