def save(self): '''Save entry in db''' data = self.cleaned_data name = data['name'] for pe_name in data['production_environment']: prod_env = ProductionEnvironment.objects.filter(name=pe_name) area = Area(name=name, productionEnvironment=prod_env[0]) area.save()
def get(self): aut = Authorisation(self) if aut.checkCookieUser(): name = self.request.get('name') description = self.request.get('description') polygon = self.request.get('polygon') list = polygon.split('|') list = list[:-1] latList = [] lngList = [] for i in range(len(list)): if i % 2: lngList.append(float(list[i])) else: latList.append(float(list[i])) # area = Area() area.name = name area.description = description area.latList = latList area.lngList = lngList area.user = aut.getUserKey() # area.name = "name12" # area.description = "desc12" # area.latList = [29.8025179058,-70.1806640625,29.8025179058,-70.1806640625] # area.lngList = [27.1764691319,-104.282226563,27.1764691319,-104.282226563] # area.user = aut.getUserKey() area.put() else: requestString = '{"Error":"error"}' self.response.headers['Content-Type'] = 'text/plain' self.response.out.write(requestString)
def getAreasOfCountry(self, country): #Coupling of method interface with NDB-based model... remove. if not country.key.kind() == "Country": raise ValueError("key must refer to an instance of Country.") query = Area.query(ancestor=country.key).order(Area.name) areas = query.fetch() return areas
def post(self): id = self.request.get('id') area = Area.all().filter('id = ', id).get() op = '' if area: op = 'updated' area.name = self.request.get('name') area.url = self.request.get('url') else: op = 'created' area = Area(id = int(id), name = self.request.get('name'), url = self.request.get('url'), ) area.put() self.response.out.write('%s %s.' % (self.request.get('name'), op))
def onGet(self, countryNameKey): self._country = Country.get_by_id(self.helper.getNormalisedCountryName(countryNameKey)) if self._country is None: return self._areas = [y for y in Area.query(ancestor=self._country.key).fetch()]
def getAreasOfCountryForId(self, countryId): query = Area.query(ancestor=ndb.Key("Country", countryId)).order(Area.name) areas = query.fetch() return areas
def get_area_key(self, name): area = Area.all().filter('name = ', name).get() if area: return area.key() else: return ''
def load_data_to_db(row): province_id = int(row['CH_ID']) province = Area.objects(aid=province_id).first() if not province: try: province = Area(level='ch', th_name=row['CHANGWAT_T'].split()[-1], en_name=row['CHANGWAT_E'], aid=province_id) province.save() except ValidationError as e: print(row['CHANGWAT_T'], row['CHANGWAT_E']) amphoe_id = int(row['AM_ID']) amphoe = Area.objects(aid=amphoe_id).first() if not amphoe: try: amphoe = Area(level='am', th_name=row['AMPHOE_T'].split()[1], en_name=row['AMPHOE_E'], aid=amphoe_id, parent=province) amphoe.save() except ValidationError as e: print(row['AMPHOE_E'], row['AMPHOE_T']) tambon_id = int(row['TA_ID']) tambon = Area.objects(aid=tambon_id).first() if not tambon: try: tambon = Area( level='ta', th_name=row['TAMBON_T'].split()[1], aid=tambon_id, parent=amphoe, latlng=[float(row['LONG']), float(row['LAT'])], ) tambon.save() except ValidationError as e: print(row['TAMBON_E'], row['TAMBON_T']) sys.exit(1) else: # the tambon exists, do nothing. ''' print('{}, {}, {} already in the database'.format( tambon.th_name.encode('utf8'), amphoe.th_name.encode('utf8'), province.th_name.encode('utf8') )) ''' return amphoe.childs.append(tambon) amphoe.save() province.childs.append(amphoe) province.save()
def get_all_areas(): return [Area(a) for a in backend.data.areas.find()]
def get_context_data(self): context = super(LocationPointWidget, self).get_context_data() context['areas'] = Area.get_all() return context
def setUp(self): u = get_user_model()() u.id = 1 u.username = '******' u.first_name = 'test' u.last_name = 'test' u.email = 'test' u.set_password('test') u.save() p = Provider() p.id = 1 p.user = u p.name = "test" p.email = "*****@*****.**" p.phone = 12312312 p.currency = "USD" p.language = "DE" p.save() a = Area() a.id = 1 a.name = "test" a.price = 10.20 a.provider = p a.poly = '{ "type": "Polygon", "coordinates": [ [ [0, 0], [10, 50], [10, 0], [0, 0] ] ] }' a.save() u = get_user_model()() u.id = 2 u.username = '******' u.first_name = 'test2' u.last_name = 'test2' u.email = '*****@*****.**' u.set_password('test') u.save() p = Provider() p.id = 2 p.user = u p.name = "test2" p.email = "*****@*****.**" p.phone = 123123212 p.currency = "USD" p.language = "EN" p.save() a = Area() a.id = 2 a.name = "test2" a.price = 10.20 a.provider = p a.poly = '{ "type": "Polygon", "coordinates": [ [ [0, 0], [10, 50], [10, 0], [0, 0] ] ] }' a.save() self.url = reverse("area:area-detail",kwargs={"pk":1})
def test_area_model(self): area = Area(city="Los Angeles", state="CA") db.session.add(area) db.session.commit() check_area = Area.query.get(area.id) self.assertIsNotNone(check_area)
async def addA(): a1 = Area(name='电子科技大学(沙河校区)', parid='xxx') a2 = Area(name='电子科技大学(清水河校区)', parid='xxx') await a1.save() await a2.save() return a1, a2