def replace(self, target): content = getattr(self.page, self.attribute) content = (content[:self.offset] + target + content[self.offset + len(self.term):]) setattr(self.page, self.attribute, content) self.group.rebase(self, len(target) - len(self.term)) zope.event.notify(grok.ObjectModifiedEvent(self.page))
def render(self): id = self.request.form.get('id') user = self.context[id] # TO-DO oh the hackery!!! user.principal_id = self.request.principal.id event.notify(grok.ObjectModifiedEvent(user)) del self.context[id] self.redirect(self.url(self.context))
def test_search_result_preview_htmlpage(self): edition = self.cms.editions.next() edition.content = 'sometext asdf someothertext' edition.title = u'Something going on' zope.event.notify(grok.ObjectModifiedEvent(edition)) transaction.commit() s = self.selenium s.type('name=q', 'asdf') s.selenium.key_press('name=q', r'\13') s.waitForPageToLoad() s.assertTextPresent('Something going on')
class Importer(object): """Import content from an XML file. """ def __init__(self, cms, data): self.cms = cms self.data = data def __call__(self, allow_duplicates=False): errors = [] try: export = lxml.etree.fromstring(self.data) except lxml.etree.XMLSyntaxError, e: return ["XML syntax error: %s." % e] self.base_path = export.get('base') imported_editions = [] for page_node in export: page_path = page_node.get('path') page = self.get_page(page_path, page_node.tag) if page_node.get('purge', 'false').lower() == 'true': for subpage in list(page.subpages): del page[subpage.__name__] for edition in list(page.editions): del page[edition.__name__] for edition_node in page_node: assert edition_node.tag == 'edition' parameters_value = edition_node.get('parameters') parameters = set(parameters_value.split()) parameters = asm.cms.edition.EditionParameters(parameters) if 'lang:' in parameters: # ensure that the fallback language is english parameters = parameters.replace('lang:', 'lang:en') try: edition = page.addEdition(parameters) except KeyError: # Leave existing content alone. if not allow_duplicates: errors.append('Duplicate page "%s" ' 'with edition "%s" detected' % ( page_path, parameters_value)) continue getattr(self, 'import_%s' % page.type)(edition, edition_node) edition.title = edition_node.get('title') edition.tags = edition_node.get('tags') edition.modified = extract_date(edition_node.get('modified')) edition.created = extract_date(edition_node.get('created')) imported_editions.append(edition) zope.event.notify(grok.ObjectModifiedEvent(edition)) zope.event.notify(ContentImported(self.cms, imported_editions, errors)) return errors
def update(self): gid = self.request.form.get('gid', None) group = grok.getApplication()['groups'][gid] if self.context.__name__ not in group.uids: group.uids = group.uids + (self.context.__name__, ) # TO-DO oh the hackery!!! group.principal_id = self.request.principal.id event.notify(grok.ObjectModifiedEvent(group)) # save must be called after event notification, otherwise it # can't diff between the before and after states! group.save()
def generate_map(event): # Ensure we only operate on archive sites if asmarchive not in event.site.getSiteManager().__bases__: return years = filter(lambda x: YEAR_MATCH.match(x.__name__), list(event.site.subpages)) for homepage in event.site.editions: gallery_map = homepage.gallery_map for year in years: for year_edition in year.editions: if not year_edition in event.imported_editions: continue year_name = year.page.__name__ gallery_map[year_name] = generate_year_map( year, homepage.parameters) homepage.gallery_map = gallery_map grok.notify(grok.ObjectModifiedEvent(homepage))
def update(self): gid = self.request.form.get('gid', None) if not gid: return group = grok.getApplication()['groups'][gid] new_group = [] for uid in group.uids: if uid != self.context.__name__: new_group.append(uid) group.uids = new_group # TO-DO oh the hackery!!! group.principal_id = self.request.principal.id event.notify(grok.ObjectModifiedEvent(group)) # save must be called after event notification, otherwise it # can't diff between the before and after states! group.save()
def upload(self, data=None, title=None, message=None): self.context.title = title self.context.message = message zope.event.notify(grok.ObjectModifiedEvent(self.context)) update_schedule(self, data)
view.flash( u'Your schedule was imported successfully with %d locations.' % rows) public_writer = CsvWriter() for event_id in finnish.events.keys(): event_en = english.events[event_id] event_fi = finnish.events[event_id] public_writer(event_id, event_en, event_fi) public_csv = public_writer.getCsv() finnish.public_csv = public_csv english.public_csv = public_csv zope.event.notify(grok.ObjectModifiedEvent(finnish)) zope.event.notify(grok.ObjectModifiedEvent(english)) def update_schedule_events(schedule, events, result): schedule.events.clear() locations = schedule.locations if 'public_json' in result: schedule.public_json = result['public_json'] for event_id, event in events.items(): schedule.events[event_id] = event location_id = event.location_id if location_id in locations: location = locations[location_id]