def setUp(self): area= Tree.objects.create(name='广州',tree_type=Tree.get_type(0)) car=Tree.objects.create(name='君威2014款',tree_type=Tree.get_type(1)) service=Tree.objects.create(name='玻璃贴膜',tree_type=Tree.get_type(2)) brand=Tree.objects.create(name='3M',tree_type=Tree.get_type(3)) foil_type= Tree.objects.create(name='整车',tree_type=Tree.get_type(6)) foil_model_front=Tree.objects.create(name='前挡类型',tree_type=Tree.get_type(7)) supplier=Supplier.objects.create( name='s1', area=area, address='address1', coordinate_x=120.01234, coordinate_y=30.1234, #photo=# ImageField(blank=True,null=True,upload_to='photos/suppliers') phone='1234567', time_open=time(10,0,0), time_close=time(19,0,0), description='description of s1', owner=UserManager.create_user('phiree', email=None, password=None) ) service=Service.objects.create(supplier=supplier,service_type=service,car=car)
def create_registered_client(self, name, email, password): client = Client() manager = UserManager() manager.model = User user = manager.create_user(name, email, password) user.save() client.login(username=name, password=password) return client
def create(self, validated_data): manager = UserManager() manager.model = User user = manager.create_user( username=validated_data.pop('username'), email=validated_data.pop('email'), password=validated_data.pop('password'), **validated_data ) return user
def setUp(self): self.client = client.Client() manager = UserManager() manager.model = get_user_model() self.user = manager.create_user("mm285", "*****@*****.**", "123456") self.user.is_active = False self.user.save() self.user_auth_token = UserAuthToken(user=self.user) self.user_auth_token.save()
def create_authorised_client(self, name, email, password): client = Client() manager = UserManager() manager.model = User user = manager.create_user(name, email, password) user.user_permissions.add(Permission.objects.get(codename="send_mails_to")) user.user_permissions.add(Permission.objects.get(codename="add_privately")) self.assert_(user.has_perm('participantdatabase.send_mails_to')) self.assert_(user.has_perm('participantdatabase.add_privately')) user.save() client.login(username=name, password=password) return client
def post(self, request, *args, **kwargs): data = json.loads(request.body) assert 'username' in data assert 'password' in data assert 'email' in data try: User.objects.get(username=data['username']) except User.DoesNotExist: pass else: return HttpResponse(json.dumps({"status": "error", "msg": "duplicated"})) UserManager.create_user( username=data['username'], email=data['email'], password=['password'] ) AdvancedPerInfo.objects.create( user=user, default_chunksize=MIN_CHUNK_SIZE, default_path=['home', user.username] ) return HttpResponse(json.dumps({"status": "OK"}))
def create_user(self, *args, **kwargs): """ """ self.model = DragonUser user = UserManager.create_user(self, *args, **kwargs) if user.user_type == 'admin': return user try: profileType = globals()[capitalize(self.user_type) + 'Profile'] except KeyError: raise KeyError('No profile type for user of type: %s' % user.user_type) else: myProfile = profileType.objects.filter(user_id=self.id) if not len(myProfile): myProfile.create(user=self.id) return user
def setUp(self): self.client = Client() # when creating a System and a Local Computer self.system = System.objects.create(name="a_name") self.local_computer = LocalComputer.objects.create(name="local_computer", secret_uuid="my_uuid") # and a user um = UserManager() um.model = User self.user = um.create_user("bob", "*****@*****.**", "hello") self.client = Client() self.client.login(username="******", password="******")
def create_user_using_manager(username,password): """ same as create_user but using user manager """ manager = UserManager() return manager.create_user(username=username, password=password)
from qa.models import Question, Answer from django.contrib.auth.models import User, UserManager u1 = UserManager.create_user(John, email = '*****@*****.**', password = '') u2 = UserManager.create_user(Bill, email = '*****@*****.**', password = '') u3 = UserManager.create_user(Jane, email = '*****@*****.**', password = '') u4 = UserManager.create_user(Helen, email = '*****@*****.**', password = '') u5 = UserManager.create_user(Patrick, email = '*****@*****.**', password = '') q1 = Question.objects.create( title = 'Computer', text = 'How connect Internet?', rating = 3, author = u1, ) q2 = Question.objects.create( title = 'TV', text = 'How move TV?', rating = 4, author = u2, ) q3 = Question.objects.create( title = 'Sun', text = 'Where wake up sun?', rating = 5, author = u3, ) q4 = Question.objects.create( title = 'Water', text = 'How clean water?', rating = 4,
def create_user(self, username, email, password, **extra_fields): UserManager.create_user(self, username=username, email=email, password=password, **extra_fields)
def add_user(request): UserManager.create_user()
cursor = db.cursor() cursor.execute(u'''select distinct user_redaksjon as redaksjon, user_redbeskrivelse as oppgaver from user where user_isactive = 1'''); for row in cursor: Redaksjon(name=fixEncoding(row['redaksjon']), oppgaver=fixEncoding(row['oppgaver'])).save() # print fixEncoding(row['oppgaver']) cursor.execute(u'''select user_id, user_intid, user_username, user_name, user_access, user_isactive, user_isfunk, user_ispang, user_tittel, user_redaksjon, user_email, user_phone from user where user_isactive=1''') for row in cursor: u = manager.create_user(username=row['user_username'], email=row['user_email'], password=row['user_username']) profile = u.userprofile; first, last = fixEncoding(row['user_name']).split(' ', 1) u.first_name = first u.last_name = last u.group = journalist profile.redaksjon = Redaksjon.objects.get(name=fixEncoding(row['user_redaksjon'])) if profile.redaksjon.name == "Teknisk": u.is_superuser = True u.is_staff = True if row['user_isfunk'] == 1: profile.funk = True else:
def setUp(self): self.client = Client() self.user = UserManager.create_user("Itai")
def setUp(self): self.client = Client() self.allow_database_queries = True self.user = UserManager.create_user("Itai")