You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
897 B
27 lines
897 B
5 years ago
|
from django.shortcuts import render, render_to_response
|
||
|
from django.views import generic
|
||
|
from django.views.generic.edit import CreateView
|
||
|
# Create your views here.
|
||
|
from accounts.models import Accounts, Players
|
||
|
|
||
|
|
||
|
class RegisterAccountView(CreateView):
|
||
|
model = Accounts
|
||
|
fields = ['name', 'password', 'email']
|
||
|
template_name = 'register_account.html'
|
||
|
|
||
|
def form_valid(self, form):
|
||
|
import hashlib
|
||
|
self.object = form.save(commit=False)
|
||
|
hashed_password = hashlib.sha1(self.object.password.encode('utf-8')).hexdigest()
|
||
|
self.object.password = hashed_password
|
||
|
self.object.save()
|
||
|
|
||
|
return render_to_response(self.template_name, self.get_context_data())
|
||
|
|
||
|
class IndexView(generic.ListView):
|
||
|
template_name = 'index.html'
|
||
|
context_object_name = 'best_players'
|
||
|
|
||
|
def get_queryset(self):
|
||
|
return Players.objects.order_by('-level')[:10]
|