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)
#!/usr/bin/python import django import os import csv os.sys.path.append('../') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'paywall2.settings') django.setup() from party.models import Country, Party # Begin main program: instance = Party(partyType = 'organization', name = 'testPartybyQian', display=True) instance.save() # Step1: Open the source CSV file and load into memory. with open('organization.csv', 'rb') as f: reader = csv.reader(f) organizationData = list(reader) with open('organization_country.csv', 'rb') as f: reader = csv.reader(f) organizationCountryData = list(reader) # Initializing organization country print "Initializing Organization Country Array" organizationCountryArray = {} for entry in organizationCountryData: organizationId = entry[0]