def _copyConferenceToForm(self, conf, displayName): """Copy relevant fields from Conference to ConferenceForm.""" cf = ConferenceForm() for field in cf.all_fields(): if hasattr(conf, field.name): # convert Date to date string; just copy others if field.name.endswith('Date'): setattr(cf, field.name, str(getattr(conf, field.name))) else: setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeKey": setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, 'organizerDisplayName', displayName) cf.check_initialized() return cf
def _copyConferenceToForm(self, conf, displayName): """Copy relevant fields from Conference to ConferenceForm. Args: conf: conference entity displayName: Name of conference Returns: Conference Form """ # Establish empty conference form cf = ConferenceForm() # For every field in the form for field in cf.all_fields(): # If the Conference entitry has the field name as a property if hasattr(conf, field.name): # convert Date to date string; just copy others if field.name.endswith('Date'): setattr(cf, field.name, str(getattr(conf, field.name))) else: # Assign the form field to the value in the entity property setattr(cf, field.name, getattr(conf, field.name)) # Special handling for the websafeKey field elif field.name == "websafeKey": # Assign the field from the conference key setattr(cf, field.name, conf.key.urlsafe()) # Assign the displayName to the form from the function arg if exists if displayName: setattr(cf, 'organizerDisplayName', displayName) # Check that all required fields are present cf.check_initialized() return cf
def _copyConferenceToForm(self, conf, displayName): cf = ConferenceForm() for field in cf.all_fields(): if hasattr(conf, field.name): if(field.name.startsWith("Date")): setattr(cf, field.name, str(getattr(conf, field.name))) else: setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeKey": setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, 'organizerDisplayName', displayName) cf.check_initialized() return cf
def _copyConferenceToForm(self, conf, displayName): cf = ConferenceForm() for field in cf.all_fields(): if hasattr(conf, field.name): if field.name.endswith('Date'): setattr(cf, field.name, str(getattr(conf, field.name))) else: setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeKey": setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, 'organizerDisplayName', displayName) cf.check_initialized() return cf
def toConferenceForm(self, conf=None, displayName=None): """Copy relevant fields from Conference to ConferenceForm.""" cf = ConferenceForm() if conf: for field in cf.all_fields(): if hasattr(conf, field.name): # convert Date to date string; just copy others if field.name.endswith("Date"): setattr(cf, field.name, str(getattr(conf, field.name))) else: setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeConferenceKey" and hasattr(conf, "key"): setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, "organizerDisplayName", displayName) cf.check_initialized() return cf
def populateApp(self, request): """Populate and reutrn conference""" confs = [ConferenceForm( name= u'aa', description= u'Uno', topics= [u'Medical Innovations'], city= u'Chicago', maxAttendees= 10, startDate= u'2016-11-25T05:00:00.000Z', endDate= u'2016-12-03T05:00:00.000Z'), ConferenceForm( name= u'bb', description= u'Dos', topics= [u'Programming Languages'], city= u'London', maxAttendees= 20, startDate= u'2016-10-15T05:00:00.000Z', endDate= u'2016-10-03T05:00:00.000Z'), ConferenceForm( name= u'cc', description= u'Tres', topics= [u'Web Technologies'], city= u'Paris', maxAttendees= 30, startDate= u'2016-10-15T05:00:00.000Z', endDate= u'2016-10-25T05:00:00.000Z'), ConferenceForm( name= u'dd', description= u'Cuatro', topics= [u'Movie Making'], city= u'Tokyo', maxAttendees= 40, startDate= u'2016-10-31T05:00:00.000Z', endDate= u'2016-11-05T05:00:00.000Z'), ConferenceForm( name= u'ee', description= u'Cinco', topics= [u'Health and Nutrition'], city= u'Chicago', maxAttendees= 50, startDate= u'2016-11-15T05:00:00.000Z', endDate= u'2016-12-03T05:00:00.000Z'), ConferenceForm( name= u'ff', description= u'Seis', topics= [u'Medical Innovations', u'Movie Making'], city= u'London', maxAttendees= 60, startDate= u'2016-11-28T05:00:00.000Z', endDate= u'2016-12-05T05:00:00.000Z'), ConferenceForm( name= u'gg', description= u'Siete', topics= [u'Health and Nutrition', u'Programming Languages'], city= u'Paris', maxAttendees= 70, startDate= u'2016-12-08T05:00:00.000Z', endDate= u'2016-12-25T05:00:00.000Z') ] for conf in confs: self._createConferenceObject(conf) conferences = Conference.query() # return set of ConferenceForm objects per Conference return ConferenceForms( items=[self._copyConferenceToForm(conf, None) for conf in conferences] )
def _copyConferenceToForm(self, conf, displayName): """ Copy relevant fields from Conference to ConferenceForm. Set the origanizer using the displayName. """ # create an empty conference form cf = ConferenceForm() # fill in the values for field in cf.all_fields(): if hasattr(conf, field.name): # convert Date to date string; just copy others if field.name.endswith("Date"): setattr(cf, field.name, str(getattr(conf, field.name))) else: setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeKey": setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, "organizerDisplayName", displayName) cf.check_initialized() return cf
def _copyConferenceToForm(self, conf, displayName): # create a new ConferenceForm object cf = ConferenceForm() for field in cf.all_fields(): if hasattr(conf, field.name): # convert Date to date string; just copy others if field.name.endswith('Date'): # set cf."field.name" equal to string of conf."field.name" setattr(cf, field.name, str(getattr(conf, field.name))) else: # set cf."field.name" equal to conf."field.name" setattr(cf, field.name, getattr(conf, field.name)) elif field.name == "websafeKey": setattr(cf, field.name, conf.key.urlsafe()) if displayName: setattr(cf, 'organizerDisplayName', displayName) # check if all required fields are initialized # returns ValidationError if not cf.check_initialized() return cf
def _copyConferenceToForm(self, conference, displayName): """Copy relevant fields from Conference to ConferenceForm""" conferenceForm = ConferenceForm() for field in conferenceForm.all_fields(): logging.debug("field name is: "+field.name) if hasattr(conference, field.name): # convert Date to date string: just copy others if field.name.endswith('Date'): setattr(conferenceForm, field.name, str(getattr(conference, field.name))) else: setattr(conferenceForm, field.name, getattr(conference, field.name)) elif field.name == "webSafeKey": setattr(conferenceForm, field.name, conference.key.urlsafe()) if displayName: setattr(conferenceForm, "organizerDisplayName", displayName) logging.info( "conferenceForm is: " ) logging.info( conferenceForm ) conferenceForm.check_initialized() return conferenceForm
def filterPlayground(self, request): q = Conference.query() # 1: city equals to London q = q.filter(Conference.city == "London") # 2: topic equals "medical Innovations" q = q.filter(Conference.topic == "Medical Innovations") # 3: order by conference q = q.order(Conference.name) # 4: filter for big conference q = q.filter(Conference.maxAttendees > 1000) return ConferenceForm( iterms=[self._copyConferenceToForm(conf, "") for conf in q])