def get(self, request): user = None lgroup = None project = None if not isinstance(request.user, AnonymousUser): user_qs = User.objects.filter( user_last_name__iexact=request.user.last_name) if user_qs.exists(): user = user_qs[0] lgroup = user.group if lgroup is None: try: lgroup = self.get_group(request.user) except: pass user.group = lgroup user.save() else: #add this logged user to the database lgroup = self.get_group(request.user) u = User(user_last_name=request.user.last_name, user_first_name=request.user.first_name, group=lgroup) u.save() ini_dict = {'project': project, 'user': user, 'group': lgroup} form = self.form_class_init(request, **ini_dict) return self.response(request, form)
def check_user(self, data): if data['user'].user_last_name == "OTHER": user = User(user_first_name=data['user_text_name'].capitalize(), user_last_name=data['user_text_surname'].upper()) user.save() data['user'] = user return data
def populate_users(): with codecs.open('./personnel.csv', 'r', 'utf-8') as csvfile: reader = csv.reader(csvfile) for row in reader: lgroup = get_group(row[0].upper()) user = User(user_last_name=row[0].upper(), user_first_name=row[1].capitalize(), group=lgroup) user.save() print(row) user = User(user_last_name='OTHER', user_first_name='Name') user.save()