<s> from django import forms <EOL> from beta . models import BetaKey <EOL> class BetaForm ( forms . Form ) : <EOL> key = forms . CharField ( label = "<STR_LIT>" ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . request = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if self . request is None : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> super ( BetaForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . beta_key = None <EOL> def clean_key ( self ) : <EOL> try : <EOL> self . beta_key = BetaKey . objects . get ( key = self . cleaned_data . get ( '<STR_LIT:key>' ) ) <EOL> except BetaKey . DoesNotExist : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> if self . beta_key . is_used : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> def save ( self ) : <EOL> self . request . session [ '<STR_LIT>' ] = True <EOL> self . beta_key . is_used = True <EOL> self . beta_key . save ( ) <EOL> class MoarKeysForm ( forms . Form ) : <EOL> keys_num = forms . IntegerField ( label = "<STR_LIT>" , <EOL> min_value = <NUM_LIT:1> , max_value = <NUM_LIT:10> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( MoarKeysForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . new_keys = [ ] <EOL> def save ( self ) : <EOL> n = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> while n : <EOL> k = BetaKey . objects . create ( ) <EOL> self . new_keys . append ( k . key ) <EOL> n -= <NUM_LIT:1> </s>
