~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlggz/forms.py

  • Committer: Holger Rapp
  • Date: 2009-02-19 15:31:42 UTC
  • Revision ID: sirver@h566336-20090219153142-dc8xuabldnw5t395
Initial commit of new widelands homepage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python -tt
2
 
# encoding: utf-8
3
 
#
4
 
# Created by Timo Wingender <timo.wingender@gmx.de> on 2010-06-02.
5
 
#
6
 
# Last Modified: $Date$
7
 
#
8
 
 
9
 
from django import forms
10
 
from models import GGZAuth
11
 
from django.utils.translation import ugettext_lazy as _
12
 
 
13
 
import hashlib
14
 
import base64
15
 
 
16
 
 
17
 
class EditGGZForm(forms.ModelForm):
18
 
    password = forms.CharField(label=_(u'Online Gaming Password'),
19
 
                               widget=forms.PasswordInput(render_value=False), required=True)
20
 
 
21
 
    class Meta:
22
 
        model = GGZAuth
23
 
        fields = ['password', ]
24
 
 
25
 
    def __init__(self, *args, **kwargs):
26
 
        instance = kwargs.pop('instance')
27
 
 
28
 
        super(EditGGZForm, self).__init__(instance=instance, *args, **kwargs)
29
 
 
30
 
    def clean_password(self):
31
 
        pw = self.cleaned_data['password']
32
 
        pw_hash = hashlib.sha1(pw).digest()
33
 
        pw_base64 = base64.standard_b64encode(pw_hash)
34
 
        return pw_base64
35
 
 
36
 
    def save(self, *args, **kwargs):
37
 
        super(EditGGZForm, self).save(*args, **kwargs)