def add_teacher_form(request): context = { 'AddTeacherForm': TeacherSignupForm, } if request.method == 'GET': return render(request, 'Manager/Teacher Related/add_teacher_form.html', context) else: email = request.POST.get("email") user_name = request.POST.get("username") password = randomPassword(10) html = f'Please use below autogenerated password to login with your email. Password is </br> <h1> { password} </h1>.' user = Account(email=email, password=make_password(password), is_teacher=True, is_staff=True) user.save() EmailAuto(recipient_list=[ email, ], html_message=html) teacher = Teacher(user=user, username=user_name) teacher.save() messages.success(request, f"Teacher '{ user.email }' created successfully. ") return redirect('manager_dashboard')
def post(self, request): a = Account() a.accountName = str(request.POST["name"]) a.accountEmail = str(request.POST["email"]) a.accountTitle = str(request.POST["title"]) a.accountHP = str(request.POST["phone"]) a.accountAddress = str(request.POST["address"]) a.save() b = list(Account.objects.all()) #objects.filter() cascade delete return render(request, "index.html", {"a": a, "b": b})
def post(self, request): self.CA = Account() userName = str(request.POST["username"]) firstName = str(request.POST["firstname"]) lastName = str(request.POST["lastname"]) email = str(request.POST["email"]) title = str(request.POST["title"]) command = [userName, title, email, firstName, lastName] try: message = Account.createAccountModels(self.CA, command) return render(request, 'createAccount.html', {"message": message}) except Exception as e: return render(request, 'createAccount.html', {"message": str(e)})
def manager_studentview(request): if request.method == 'GET': return render(request,'manager/manager_studentview.html') else: email = request.POST.get('email') name = request.POST.get('name') contact = request.POST['contact'] password = randomPassword() user = Account(email=email, password=make_password(password), is_teacher=False,is_manager=False,is_student=True) user.save() msg = f'{name}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}' Mail(subject='Account created', message=msg,recipient_list=[email]) student = Student(name=name, contact=contact, user_id=user.id) student.save() messages.add_message(request,messages.SUCCESS,'student Account is created successfully') return redirect('manager_view')
def create(self, validated_data): account = Account(email=validated_data['email'], account_type=validated_data['account_type'], fullname=validated_data.get('fullname', None), firstname=validated_data.get('firstname', None), lastname=validated_data.get('lastname', None)) account.set_unusable_password() account.set_social_id(validated_data.get('social_id', None)) account.save() return account
def OwnerAccountCreate(request): if request.method == 'GET': return render(request,'owner_register.html') else: email = request.POST.get('email') fname = request.POST.get('fname') lname = request.POST.get('lname') contact = request.POST['contact'] address = request.POST['address'] password = randomPassword() user = Account(email=email, first_name=fname,last_name=lname,password=make_password(password),is_owner=True,is_client=False) user.save() msg = f'{fname + lname}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}' Mail(subject='Account created', message=msg, recipient_list=[email]) owner = OwnerInfo(email=request.user.email,address=address,name=fname + lname, contact=contact, user_id=user.id) owner.save() messages.add_message(request,messages.SUCCESS,'owner Account is created successfully') return render(request,'signin.html')
def ClientAccountCreate(request): if request.method == 'GET': return render(request,'client_register.html') else: fname = request.POST['fname'] lname = request.POST['lname'] contact = request.POST['contact'] address = request.POST.get('address') email = request.POST['email'] no_of_person = request.POST['no_of_person'] password = randomPassword() user = Account(email=email, first_name=fname, last_name=lname, password=make_password(password), is_owner=False, is_client=True) user.save() msg = f'{fname + lname}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}' Mail(subject='Account created', message=msg, recipient_list=[email]) client = Client(name=fname+lname, contact=contact, address=address, email=email, no_of_person=no_of_person, user_id=user.id) client.save() messages.add_message(request,messages.SUCCESS,'client Account created successfully') return render(request, 'signin.html')
def createAccount(self, command): # Check that the command has the correct number of arguments if len(command) != 4: return "Your command is missing arguments, please enter your command in the following format: " \ "createAccount username title email" # Check that the account trying to be created does not already exist if Account.objects.filter(userName=command[1]).exists(): return "Account already exists" # Make sure the account is trying to be created with a UWM email address str = command[3].split('@', 1) if len(str) == 1: return "The email address you have entered in not valid. " \ "Please make sure you are using a uwm email address in the correct format." if str[1] != "uwm.edu": return "The email address you have entered in not valid. " \ "Please make sure you are using a uwm email address in the correct format." # If we get here the account is safe to be created. else: A = Account() A.userName = command[1] A.email = command[3] if command[2].lower() == "ta": A.title = 1 elif command[2].lower() == "instructor": A.title = 2 else: return "Invalid title, account not created" # Make a temporary password for the newly created user A.password = A.userName + "456" A.save() return "Account successfully created. Temporary password is: " + A.userName + "456"
def create(self, validated_data): account = Account(email=validated_data['email'], fullname=validated_data.get('fullname', None), firstname=validated_data.get('firstname', None), lastname=validated_data.get('lastname', None)) password = validated_data['password'] password2 = validated_data['password2'] if password != password2: raise serializers.ValidationError( {'password': '******'}) account.set_password(password) account.save() return account
def save(self): account = Account(email=self.validated_data['email'], username=self.validated_data['username']) password = self.validated_data['password'] password2 = self.validated_data['password2'] if password != password2: raise serializers.ValidationError( {'password': "******"}) account.set_password(password) account.save() return account
def get(self, request): a = Account() a.accountName = "What" a.accountName = "no" return render(request, "index.html", {"a": a, "b": []})
def _maak_leden(self): """ Maak voor elke vereniging een aantal leden aan: een mix van alle wedstrijdklassen en boogtypen. Aspirant <13, Aspirant 13-14, Cadet 15-17, Junior 18-20, Senior 21-49, Master 50-59, Veteraan 60+ """ huidige_jaar = timezone.now().year lid_sinds_datum = datetime.date(year=huidige_jaar - 1, month=11, day=12) soorten = [ # wedstrijdleeftijd, geslacht, voornaam, boogtype, account (10, 'M', 'Asp10', 'R', False), (10, 'V', 'Asp10', 'R', False), (11, 'M', 'Asp11', 'R', False), (12, 'V', 'Asp12', 'R', False), (13, 'M', 'Asp13', 'R', False), (14, 'M', 'Cad14', 'R', False), (14, 'M', 'Cad14b', 'C', False), (14, 'M', 'Cad15', 'c', False), # kleine letter: geen voorkeur voor de competitie (15, 'V', 'Cad15', 'R', False), (15, 'M', 'Cad15b', 'BB', False), (15, 'V', 'Cad15b', 'C', False), (16, 'M', 'Cad16', 'R', False), (16, 'M', 'Cad16b', 'C', False), (16, 'M', 'Cad16c', 'BB', False), (17, 'V', 'Cad17', 'R', True), # account (17, 'V', 'Cad17b', 'C', False), (17, 'V', 'Cad17c', 'BB', False), (18, 'M', 'Jun18', 'R', False), (18, 'M', 'Jun18b', 'C', False), (18, 'M', 'Jun18c', 'BB', False), (18, 'V', 'Jun18', 'BB', False), (19, 'V', 'Jun19', 'R', False), (19, 'V', 'Jun19b', 'C', True), # account (20, 'M', 'Jun20', 'R', False), (20, 'M', 'Jun20b', 'LB', False), (21, 'V', 'Sen21', 'R', False), (21, 'V', 'Sen21b', 'C', False), (22, 'M', 'Sen22', 'R', False), (22, 'M', 'Sen22b', 'C', False), (22, 'M', 'Sen23', 'r', False), # kleine letter: geen voorkeur voor de competitie (31, 'V', 'Sen31', 'R', False), (32, 'M', 'Sen32', 'C', False), (32, 'M', 'Sen32b', 'BB', True), # account (33, 'V', 'Sen33', 'R', False), (33, 'V', 'Sen33b', 'BB', False), (34, 'M', 'Sen34', 'LB', True), # Sen34 = HWL (35, 'V', 'Sen35', 'R', False), (36, 'M', 'Sen36', 'C', False), (36, 'M', 'Sen36b', 'BB', False), (37, 'V', 'Sen37', 'R', False), (38, 'M', 'Sen38', 'LB', False), (39, 'V', 'Sen39', 'R', True), # Sen39 = BKO/RKO/RCL (40, 'M', 'Sen40', 'C', False), (41, 'V', 'Sen41', 'R', False), (42, 'M', 'Sen42', 'R', False), (42, 'M', 'Sen42b', 'C', False), (49, 'V', 'Sen49', 'R', False), (49, 'V', 'Sen49b', 'BB', False), (50, 'M', 'Mas50', 'R', True), # Mas50 = SEC (51, 'V', 'Mas51', 'R', True), # account (51, 'V', 'Mas51b', 'C', False), (51, 'V', 'Mas52', 'r', False), # kleine letter: geen voorkeur voor de competitie (59, 'M', 'Mas59', 'R', False), (59, 'M', 'Mas59b', 'LB', False), (60, 'V', 'Vet60', 'R', False), (60, 'V', 'Vet60b', 'C', False), (60, 'V', 'Vet60c', 'LB', True), # account (61, 'M', 'Vet61', 'C', False), (61, 'M', 'Vet61b', 'C', False), (80, 'V', 'Vet80', 'R', False), ] geslacht_voornaam2boogtype = dict() for _, geslacht, voornaam, boogtype, _ in soorten: try: _ = geslacht_voornaam2boogtype[geslacht + voornaam] except KeyError: geslacht_voornaam2boogtype[geslacht + voornaam] = boogtype else: raise IndexError( 'TestData: combinatie geslacht %s + voornaam %s komt meerdere keren voor' % (geslacht, voornaam)) # pragma: no cover # for # maak voor elke vereniging een paar accounts aan lid_nr = 300000 bulk = list() for ver in self.vereniging.values(): self.regio_ver_nrs[ver.regio.regio_nr] = ver.ver_nr for _, _, voornaam, _, maak_account in soorten: lid_nr += 1 if maak_account: account = Account(username=str(lid_nr), otp_code=self.OTP_CODE, otp_is_actief=True) account.set_password(self.WACHTWOORD) bulk.append(account) if len(bulk) > 100: # pragma: no branch Account.objects.bulk_create(bulk) # maak e-mails aan bulk2 = list() for account in bulk: # let op: e-mailadres moet overeenkomen met het Sporter.email email = AccountEmail( account=account, email_is_bevestigd=True, bevestigde_email='*****@*****.**' % account.username) bulk2.append(email) # for AccountEmail.objects.bulk_create(bulk2) del bulk2 bulk = list() # for # for if len(bulk) > 0: # pragma: no branch Account.objects.bulk_create(bulk) # maak e-mails aan bulk2 = list() for account in bulk: email = AccountEmail(account=account, email_is_bevestigd=True, bevestigde_email='*****@*****.**' % account.username) bulk2.append(email) # for AccountEmail.objects.bulk_create(bulk2) del bulk2 del bulk # cache de aangemaakte accounts lid_nr2account = dict() for account in Account.objects.all(): lid_nr2account[account.username] = account # for lid_nr = 300000 bulk = list() for ver in self.vereniging.values(): self.ver_sporters[ver.ver_nr] = list() self.ver_sporters_met_account[ver.ver_nr] = list() for wleeftijd, geslacht, voornaam, _, _ in soorten: lid_nr += 1 achternaam = "Lid%s van Club%s" % (ver.ver_nr, lid_nr) geboortedatum = datetime.date(year=huidige_jaar - wleeftijd, month=3, day=24) try: account = lid_nr2account[str(lid_nr)] except KeyError: account = None sporter = Sporter(lid_nr=lid_nr, voornaam=voornaam, achternaam=achternaam, unaccented_naam=voornaam + ' ' + achternaam, email='*****@*****.**' % lid_nr, geboorte_datum=geboortedatum, geslacht=geslacht, para_classificatie='', is_actief_lid=True, sinds_datum=lid_sinds_datum, bij_vereniging=ver, account=account, lid_tot_einde_jaar=huidige_jaar) bulk.append(sporter) if len(bulk) > 250: # pragma: no branch Sporter.objects.bulk_create(bulk) bulk = list() # for # for if len(bulk) > 0: # pragma: no branch Sporter.objects.bulk_create(bulk) del bulk del lid_nr2account # maak voor elke Sporter nu de SporterBoog records aan boogtypen = self.afkorting2boogtype.values() bulk_voorkeuren = list() bulk_sporter = list() for sporter in (Sporter.objects.select_related( 'account', 'bij_vereniging').all()): ver_nr = sporter.bij_vereniging.ver_nr self.ver_sporters[ver_nr].append(sporter) if sporter.account: self.ver_sporters_met_account[ver_nr].append(sporter) gewenst_boogtype = geslacht_voornaam2boogtype[sporter.geslacht + sporter.voornaam] # voorkeuren voorkeuren = SporterVoorkeuren(sporter=sporter) if gewenst_boogtype.islower(): voorkeuren.voorkeur_meedoen_competitie = False gewenst_boogtype = gewenst_boogtype.upper() # alle junioren willen een eigen blazoen if gewenst_boogtype == 'R' and sporter.voornaam.startswith('Jun'): voorkeuren.voorkeur_eigen_blazoen = True bulk_voorkeuren.append(voorkeuren) if len(bulk_voorkeuren) > 100: SporterVoorkeuren.objects.bulk_create(bulk_voorkeuren) bulk_voorkeuren = list() # sporterboog for boogtype in boogtypen: sporterboog = SporterBoog( sporter=sporter, # heeft_interesse=True # voor_wedstrijd=False boogtype=boogtype) if boogtype.afkorting == gewenst_boogtype: sporterboog.voor_wedstrijd = True bulk_sporter.append(sporterboog) if len(bulk_sporter) > 250: SporterBoog.objects.bulk_create(bulk_sporter) bulk_sporter = list() # for # for if len(bulk_voorkeuren): # pragma: no branch SporterVoorkeuren.objects.bulk_create(bulk_voorkeuren) del bulk_voorkeuren if len(bulk_sporter): # pragma: no branch SporterBoog.objects.bulk_create(bulk_sporter) del bulk_sporter