<s> import sys <EOL> from datetime import datetime <EOL> from django . conf import settings <EOL> from django . db import models <EOL> from django . db . models . signals import post_save <EOL> from django . utils . translation import get_language_from_request , ugettext_lazy as _ <EOL> from django . contrib . auth . models import User , AnonymousUser <EOL> from emailconfirmation . models import EmailAddress , EmailConfirmation <EOL> from emailconfirmation . signals import email_confirmed <EOL> from timezones . fields import TimeZoneField <EOL> class Account ( models . Model ) : <EOL> user = models . ForeignKey ( User , unique = True , verbose_name = _ ( "<STR_LIT:user>" ) ) <EOL> timezone = TimeZoneField ( _ ( "<STR_LIT>" ) ) <EOL> language = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:10> , <EOL> choices = settings . LANGUAGES , <EOL> default = settings . LANGUAGE_CODE <EOL> ) <EOL> def __unicode__ ( self ) : <EOL> return self . user . username <EOL> class OtherServiceInfo ( models . Model ) : <EOL> user = models . ForeignKey ( User , verbose_name = _ ( "<STR_LIT:user>" ) ) <EOL> key = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> ) <EOL> value = models . TextField ( _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> unique_together = [ ( "<STR_LIT:user>" , "<STR_LIT:key>" ) ] <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . key , self . user ) <EOL> def other_service ( user , key , default_value = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = OtherServiceInfo . objects . get ( user = user , key = key ) . value <EOL> except OtherServiceInfo . DoesNotExist : <EOL> value = default_value <EOL> return value <EOL> def update_other_services ( user , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for key , value in kwargs . items ( ) : <EOL> info , created = OtherServiceInfo . objects . get_or_create ( user = user , key = key ) <EOL> info . value = value <EOL> info . save ( ) <EOL> def create_account ( sender , instance = None , ** kwargs ) : <EOL> if instance is None : <EOL> return <EOL> account , created = Account . objects . get_or_create ( user = instance ) <EOL> post_save . connect ( create_account , sender = User ) <EOL> def superuser_email_address ( sender , instance = None , ** kwargs ) : <EOL> if instance is None : <EOL> return <EOL> if "<STR_LIT>" in sys . argv or "<STR_LIT>" in sys . argv : <EOL> defaults = { <EOL> "<STR_LIT:user>" : instance , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True , <EOL> } <EOL> EmailAddress . objects . get_or_create ( email = instance . email , ** defaults ) <EOL> post_save . connect ( superuser_email_address , sender = User ) <EOL> class AnonymousAccount ( object ) : <EOL> def __init__ ( self , request = None ) : <EOL> self . user = AnonymousUser ( ) <EOL> self . timezone = settings . TIME_ZONE <EOL> if request is not None : <EOL> self . language = get_language_from_request ( request ) <EOL> else : <EOL> self . language = settings . LANGUAGE_CODE <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class PasswordReset ( models . Model ) : <EOL> user = models . ForeignKey ( User , verbose_name = _ ( "<STR_LIT:user>" ) ) <EOL> temp_key = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:100> ) <EOL> timestamp = models . DateTimeField ( _ ( "<STR_LIT>" ) , default = datetime . now ) <EOL> reset = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . user . username , <EOL> self . temp_key , <EOL> self . reset <EOL> ) <EOL> def mark_user_active ( sender , instance = None , ** kwargs ) : <EOL> user = kwargs . get ( "<STR_LIT>" ) . user <EOL> user . is_active = True <EOL> user . save ( ) <EOL> email_confirmed . connect ( mark_user_active , sender = EmailConfirmation ) </s>
