def create_g24_event(self, container, node): title = node.getAttribute('pc_title') try: text = node.getElementsByTagName('text')[0].childNodes[1].data except IndexError: text = u'' tags = [] for t in node.getElementsByTagName('tag'): tags.append(t.getAttribute('name')) loc = node.getAttribute('location_name') data = { 'is_event': True, 'title': title, 'text': text, 'subjects': tags, 'timezone': 'Europe/Vienna', 'whole_day': node.getAttribute('pc_alldayevent') == "1", 'open_end': False, 'recurrence': None, 'location': LOC_TO_UUID.get(loc), } createdate = DateTime(node.getAttribute('pc_time')) event_date = DateTime( node.getAttribute('pc_eventDate') + " " + node.getAttribute('pc_startTime') + " Europe/Vienna" ) data['start'] = pydt(event_date) # calc / use end date , fallback is same as start data['end'] = pydt(event_date) if node.hasAttribute('pc_endDate'): end_date = DateTime( node.getAttribute('pc_endDate') + " " + node.getAttribute('pc_endTime') + " Europe/Vienna" ) data['end'] = pydt(end_date) elif node.getAttribute('pc_duration'): end_date = DateTime( int(event_date) + int(node.getAttribute('pc_duration')) ) data['end'] = pydt(end_date) obj = create(container, G24_BASETYPE) # set the creators by loginname. if more than one, # seperate by whitespace obj.setCreators(node.getAttribute('pc_informant')) obj.creation_date = createdate edit(obj, data, order=FEATURES) obj = add(obj, container) return obj
def create_g24_posting(self, container, postingdata): data = { 'is_thread': postingdata['title'].strip() != "", # TODO: is_thread only for threads 'title': postingdata['title'], 'text': postingdata['text'], 'subjects': postingdata['tags'], } obj = create(container, G24_BASETYPE) # TODO: set ownership! via api? plone_utils... # http://www.uwosh.edu/ploneprojects/docs/how-tos/scripts-to-change-owner-of-an-item obj.setCreators(postingdata['username']) # set the creators by loginname. if more than one, seperate by whitespace obj.creation_date = DateTime(postingdata['post_time']) edit(obj, data, order=FEATURES) obj = add(obj, container) return obj
def import_places(container): importpath = "src/g24.importer/src/g24/importer/scripts/export-places.json" locations = json.loads(open(importpath).read()) batch = 0 for key, loc in locations.items(): batch += 1 # create data data = {'is_place': True} title = 'event_location' in loc and loc['event_location'] or None str1 = 'event_street1' in loc and loc['event_street1'] or None str2 = 'event_street2' in loc and loc['event_street2'] or None street = '%s%s%s' % (str1 and str1 or '', str1 and str2 and ' ' or '', str2 and str2 or '') zipc = 'event_postal' in loc and loc['event_postal'] or None city = 'event_city' in loc and loc['event_city'] or None lat, lng = get_geocode(zipc, city, title, str1, str2) if title: data['title'] = title if street: data['street'] = street if zipc: data['zip_code'] = zipc if city: data['city'] = city data['country'] = '040' if lat and lng: data['geolocation'] = Geolocation(lat, lng) obj = create(container, G24_BASETYPE) obj.creation_date = DateTime(loc['event_datetime']) edit(obj, data, order=FEATURES) obj = add(obj, container) uuid = IUUID(obj) LOC_TO_UUID[key] = uuid logger.info('created place %s, uuid: %s, lat: %s, lng: %s' % ( title, uuid, lat, lng )) if batch % 10 == 0: transaction.get().commit() transaction.get().commit()
def create(self): obj = create(self.context, self.portal_type) return obj