<s> """<STR_LIT>""" <EOL> from optparse import make_option <EOL> from django . conf import settings <EOL> from django . core . management . base import NoArgsCommand , CommandError <EOL> DEFAULT_FAKE_EMAIL = '<STR_LIT>' <EOL> from django_extensions . management . utils import signalcommand <EOL> class Command ( NoArgsCommand ) : <EOL> option_list = NoArgsCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = DEFAULT_FAKE_EMAIL , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = '''<STR_LIT>''' % ( DEFAULT_FAKE_EMAIL , ) <EOL> requires_model_validation = False <EOL> @ signalcommand <EOL> def handle_noargs ( self , ** options ) : <EOL> if not settings . DEBUG : <EOL> raise CommandError ( '<STR_LIT>' ) <EOL> try : <EOL> from django . contrib . auth import get_user_model <EOL> except ImportError : <EOL> from django_extensions . future_1_5 import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> email = options . get ( '<STR_LIT>' , DEFAULT_FAKE_EMAIL ) <EOL> include_regexp = options . get ( '<STR_LIT>' , None ) <EOL> exclude_regexp = options . get ( '<STR_LIT>' , None ) <EOL> include_groups = options . get ( '<STR_LIT>' , None ) <EOL> exclude_groups = options . get ( '<STR_LIT>' , None ) <EOL> no_admin = options . get ( '<STR_LIT>' , False ) <EOL> no_staff = options . get ( '<STR_LIT>' , False ) <EOL> User = get_user_model ( ) <EOL> users = User . objects . all ( ) <EOL> if no_admin : <EOL> users = users . exclude ( is_superuser = True ) <EOL> if no_staff : <EOL> users = users . exclude ( is_staff = True ) <EOL> if exclude_groups : <EOL> groups = Group . objects . filter ( name__in = exclude_groups . split ( "<STR_LIT:U+002C>" ) ) <EOL> if groups : <EOL> users = users . exclude ( groups__in = groups ) <EOL> else : <EOL> raise CommandError ( "<STR_LIT>" % exclude_groups ) <EOL> if include_groups : <EOL> groups = Group . objects . filter ( name__in = include_groups . split ( "<STR_LIT:U+002C>" ) ) <EOL> if groups : <EOL> users = users . filter ( groups__in = groups ) <EOL> else : <EOL> raise CommandError ( "<STR_LIT>" % include_groups ) <EOL> if exclude_regexp : <EOL> users = users . exclude ( username__regex = exclude_regexp ) <EOL> if include_regexp : <EOL> users = users . filter ( username__regex = include_regexp ) <EOL> for user in users : <EOL> user . email = email % { '<STR_LIT:username>' : user . username , <EOL> '<STR_LIT>' : user . first_name , <EOL> '<STR_LIT>' : user . last_name } <EOL> user . save ( ) <EOL> print ( '<STR_LIT>' % users . count ( ) ) </s>
