def setUp(self): p = Party(name='Party', website='www.website.com') p.save() d = District(name='District', abbreviation='d') d.save() pm = ParliamentMember(name='John Johnson', initials='jj', districtNumber=10, party=p, district=d) pm.save()
def load_parties(self): response = requests.get("{}/api/v2/partidos".format(self._host), params={"itens": 1000}) result = response.json() for data in result["dados"]: party = self.get_by_external_id(data["id"]) if not party: party = Party() party.name = data["nome"] party.initials = data["sigla"] party.external_id = data["id"] party.save()
def create(): form = BasicPartyForm() error = None if request.method == 'POST' and form.validate(): if form.end_datetime.data < form.start_datetime.data: error = "A party must end after it starts!" if not error: user = User.objects.filter(email=session.get('email')).first() party = Party(name=form.name.data, place=form.place.data, location=[form.lng.data, form.lat.data], start_datetime=form.start_datetime.data, end_datetime=form.end_datetime.data, description=form.description.data, host=user.id, attendees=[user]) party.save() #return '{} created.'.format(party.name) return redirect(url_for('party_page.edit', id=party.id)) return render_template('party/create.html', form=form, error=error)