~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlggz/forms.py

  • Committer: timo
  • Date: 2010-06-03 14:21:21 UTC
  • mto: This revision was merged to the branch mainline in revision 218.
  • Revision ID: timo@athin-20100603142121-65pr9u44g3lsmxoi
add first version of wlggz app

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
import settings
 
16
import re
 
17
 
 
18
class EditGGZForm(forms.ModelForm):
 
19
    password = forms.CharField(label=_(u'GGZ password'), 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
        print "instance: %s, kwargs: %s" % (instance, kwargs)
 
29
        super(EditGGZForm, self).__init__(instance=instance, *args,**kwargs)
 
30
 
 
31
    def clean_password(self):
 
32
        pw = self.cleaned_data['password']
 
33
        print "pw:   %s" % (pw)
 
34
        pw_hash = hashlib.sha1(pw).digest()
 
35
        pw_base64 = base64.standard_b64encode(pw_hash)
 
36
        print "sha1: %s" % (pw_hash)
 
37
        print "base: %s" % (pw_base64)
 
38
        return pw_base64
 
39
 
 
40
 
 
41
    def save(self):
 
42
        super(EditGGZForm, self).save()
 
43