def setPesonBack(): Person.objects.all().delete() emp_list = Employee.objects.filter(is_enabled=1, is_select=1) for emp in emp_list: for i in range(emp.weight): tmp = Person(name=emp.name) tmp.save()
def index(request): if request.method == "POST": new_subscriber = Person(first_name=request.POST.get('first'), last_name=request.POST.get('last'), phone_number=request.POST.get('number')) new_subscriber.save() # on_register(new_subscriber['phone_number']) return render(request, "backend/index.html")
def setPeson(request): Person.objects.all().delete() emp_list = Employee.objects.filter(is_enabled=1, is_select=1) for emp in emp_list: for i in range(emp.weight): tmp = Person(name=emp.name) tmp.save() return JsonResponse({ 'twz': 'Love python and Django', 'zqxt': 'I am teaching Django' })
def teams_add(): if request.mimetype != 'application/json': abort(415) data = team_schema(request.json) name = data['name'] original_slug = parameterize(name[:20]) slug = _generate_slug(original_slug) while Team.query.filter_by(slug=slug).count() > 0: slug = _generate_slug(original_slug) team = Team(name=name, slug=slug) db.session.add(team) TeamMembership( team=team, user=current_identity, is_admin=True ) db.session.add(TabType(name='Beer', price=1, team=team)) db.session.add(TabType(name='Cider', price=2, team=team)) db.session.add(Person(name=current_identity.name, team=team)) db.session.commit() response = _get_teams_response() response.status_code = 201 return response
def is_session_valid(session): for couple in session: person_1 = couple[0] person_2 = couple[1] if not Person.test_persons_can_meet(person_1, person_2): return False return True
def test_no_person(self): client = self.make_test_client( "*****@*****.**") response = client.get(reverse("public_newnm")) self.assertEqual(response.status_code, 200) self.assertEqual(response.context["person"], None) self.assertEqual(response.context["errors"], []) self.assertEqual(response.context["DAYS_VALID"], 3) self.assertNotContains(response, "Please login first") self.assertNotContains(response, "You already have an entry in the system") self.assertNotContains(response, "Not only you have an entry, but you are also") self.assertContains(response, "Apply for an entry in the system") self.assertNotContains( response, "Submit disabled because you already have an entry in the system") # A new Person is created on POST response = client.post(reverse("public_newnm"), data={ "fpr": self.new_person_fingerprint, "sc_ok": "yes", "dmup_ok": "yes", "cn": "test", "email": "*****@*****.**" }) self.assertRedirectMatches( response, reverse("public_newnm_resend_challenge", kwargs={"key": "*****@*****.**"})) new_person = Person.lookup("*****@*****.**") self.assertEqual(new_person.status, const.STATUS_DC) self.assertIsNotNone(new_person.expires) self.assertIsNotNone(new_person.pending) # The new person can resend the challenge email response = client.get( reverse("public_newnm_resend_challenge", kwargs={"key": "*****@*****.**"})) self.assertRedirectMatches(response, new_person.get_absolute_url()) # The new person has a page in the system response = client.get(new_person.get_absolute_url()) self.assertEqual(response.status_code, 200) # The new person can confirm its record response = client.get( reverse("public_newnm_confirm", kwargs={"nonce": new_person.pending})) self.assertRedirectMatches(response, new_person.get_absolute_url()) new_person = Person.objects.get(pk=new_person.pk) self.assertEqual(new_person.status, const.STATUS_DC) self.assertIsNotNone(new_person.expires) self.assertEqual(new_person.pending, "")
def create_person(team): data = person_schema(request.json) person = Person( team=team, name=data['name'] ) db.session.add(person) db.session.commit() return jsonify(_get_person_data(team))
def setUp(self): self.person = Person(cn="Ondřej", sn="Nový", email="*****@*****.**") self.addrstr = "*****@*****.**" self.addrtuple = ("Enric♥ Zìní", "*****@*****.**") self.date = datetime.datetime(2017, 6, 5, 4, 3, 2) self.args = { "from_email": self.person, "to": self.addrstr, "cc": [self.person, self.addrstr, self.addrtuple], "subject": "♥ Debian ♥", "date": self.date, "body": "Debian ♥ Debian", }
def registrierung(request): user = None messages = [] form = None if request.method == 'POST': # create a form instance and populate it with data from the request: form = RegistrierungForm(request.POST) # check whether it's valid: if form.is_valid(): # Nutzeraccount erstellen semester = form.cleaned_data['semester'] matrikelnummer = form.cleaned_data['matrikelnummer'] email = form.cleaned_data['email'] passwort = form.cleaned_data['passwort'] vorname = form.cleaned_data['vorname'] nachname = form.cleaned_data['nachname'] adresse = form.cleaned_data['adresse'] daten_sofort_loeschen = form.cleaned_data['daten_sofort_loeschen'] try: validate_password(form.cleaned_data['passwort']) # User erstellen und in Gruppe 'Antragstellung' aufnehmen user = User.objects.create_user(matrikelnummer, email, passwort, first_name=vorname, last_name=nachname) group = Group.objects.get(name='Antragstellung') group.user_set.add(user) # Person um User bauen person = Person() person.user = user person.adresse = adresse person.daten_sofort_loeschen = daten_sofort_loeschen person.save() accounthistory = AccountHistory() accounthistory.akteur = person.user accounthistory.account = person.user accounthistory.beschreibung = "Account erstellt (Registrierung)" accounthistory.save() # User einloggen und Seite 2 aufrufen user = authenticate(username=matrikelnummer, password=passwort) if user is not None: if user.is_active: login(request, user) if(user.groups.filter(name='Antragstellung').exists()): # Willkommens-E-Mail senden if(user.email): send_mail( '[STRE] Willkommen im Semesterticketrückerstattungssystem!', 'Hallo {vorname} {nachname}!\n\nDu hast dich gerade erfolgreich im Semesterticketrückerstattungssystem registriert.\nMit deiner Matrikelnummer ({matrikelnummer}) und dem von dir gewählten Passwort kannst du dich im System anmelden, Nachweise hochladen und deinen Antragsstatus verfolgen.\n\n{timestamp}\n\n------------------\n~>Signatur<~'.format(vorname=user.first_name, nachname=user.last_name, matrikelnummer=user.username, timestamp=datetime.datetime.now()), 'STRE-Bot<*****@*****.**>', [user.email], fail_silently=False, ) # Redirect auf Seite 2 response = redirect('frontend:antragstellung', semester_id=semester.id) response['Location'] += '?m=initialantrag' return response else: messages.append({'klassen':'alert-danger','text':'falsche_gruppe'}) else: # Return a 'disabled account' error message messages.append({'klassen':'alert-warning','text':'<strong>Hoppla!</strong> Dein Zugang wurde deaktiviert. Bitte wende dich an den Semesterticketausschuss.'}) else: # Return an 'invalid login' error message. messages.append({'klassen':'alert-danger','text':'<strong>Herrje!</strong> Das hat nicht funktioniert. Hast du Matrikelnummer und Passwort auch wirklich korrekt eingegeben?'}) except IntegrityError as ie: # user existiert bereits login_url = reverse('frontend:loginpage') messages.append({'klassen':'alert-info','text':'<strong>Hoppla!</strong> Für diese Matrikelnummer existiert bereist ein Konto. <a href="{0}?u={1}">Melde dich bitte an</a> und stelle dann den Antrag.'.format(login_url, form.cleaned_data['matrikelnummer'])}) except ValidationError as e: validation_errors = e for validation_error in validation_errors: messages.append({'klassen':'alert-warning','text':validation_error}) else: # form invalid pass else: form = RegistrierungForm() context = { 'current_page' : 'registrierung', 'form':form, 'user':user, 'messages':messages } return render(request, 'frontend/registrierung.html', context)
def initdb(): # for table in reversed(db.metadata.sorted_tables): # db.engine.execute(table.delete()) click.echo('Dropping db') db.drop_all() click.echo('Creating db') db.create_all() click.echo('Creating dummy data') # User user = User(email='*****@*****.**', first_name='Test', last_name='User', registered_at=datetime.datetime.now(), is_invite=False) user.password = '******' db.session.add(user) # Teams team1 = Team(name='Beer drinking club', slug='beer-drinkers') db.session.add(team1) team2 = Team(name='Sandwich club', slug='bread-eaters') db.session.add(team2) # Team Memberships TeamMembership(user=user, team=team1, is_admin=True) TeamMembership(user=user, team=team2, is_admin=True) # Persons persons = [ Person(team=team1, name='Pekka Piikkaaja'), Person(team=team1, name='Osku Oskunen'), Person(team=team1, name='Mira Miranen'), Person(team=team2, name='Mikko Jokunen'), Person(team=team2, name='Jaska Unkuri'), ] for i in range(10): persons.append(Person(team=team1, name='Testi Nro{}'.format(i))) persons.append(Person(team=team2, name='Testi Nro{}'.format(i))) for person in persons: db.session.add(person) # TabTypes db.session.add(TabType(name='Pilsner', price=1.5, team=team1)) db.session.add(TabType(name='IPA', price=2.5, team=team1)) db.session.add(TabType(name='Premium cider', price=3.5, team=team1)) db.session.add(TabType(name='Small bread', price=1, team=team2)) db.session.add(TabType(name='Sandwich', price=3, team=team2)) db.session.add(TabType(name='Burger', price=5, team=team2)) # TabItems for i in range(1000): price = int(random.randint(1, 5)) amount = int(random.randint(1, 5)) person = persons[i % 4] db.session.add( TabItem(name=['Item 1', 'Item 2', 'Item 3'][i % 3], price=price, amount=amount, person=person, adder=user, added_at=(datetime.datetime.now() - datetime.timedelta(minutes=i)), team=person.team)) db.session.commit() click.echo('Done')