def tileTypes(self): """Get a list of addable ITileType objects representing tiles which are addable in the current context """ tiles = [] for tile_name in getUtility(IRegistry)['plone.app.tiles']: tiletype = queryUtility(ITileType, tile_name.strip()) # check if we have permission to add this tile if tiletype and checkPermission(tiletype.add_permission, self.context): # tile actions # TODO: read from registry tiletype.actions = [{ 'name': 'edit', 'url': '@@edit-tile', 'title': _('Edit'), }, { 'name': 'remove', 'url': '@@delete-tile', 'title': _('Remove'), }] tiles.append(tiletype) tiles.sort(self.tileSortKey) return tiles
def tileTypes(self): """Get a list of addable ITileType objects representing tiles which are addable in the current context and selected in the registry configuration """ tiles = [] factory = getUtility( IVocabularyFactory, name="tiles.management.vocabularies.FilteredTiles", ) vocabulary = factory(self.context) for item in vocabulary: tiletype = item.value # tile actions # TODO: read from registry # noqa tiletype.actions = [ { "name": "edit", "url": "@@edit-tile", "title": _("Edit") }, { "name": "remove", "url": "@@delete-tile", "title": _("Remove"), }, ] tiles.append(tiletype) return sorted(tiles, key=self.keyfunction)
def tileTypes(self): """Get a list of addable ITileType objects representing tiles which are addable in the current context """ tiles = [] factory = getUtility(IVocabularyFactory, name=ALLOWED_TILES_VOCABULARY) vocabulary = factory(self.context) for item in vocabulary: tiletype = item.value # check if we have permission to add this tile if tiletype and checkPermission( tiletype.add_permission, self.context): # tile actions # TODO: read from registry tiletype.actions = [{ 'name': 'edit', 'url': '@@edit-tile', 'title': _('Edit'), }, { 'name': 'remove', 'url': '@@delete-tile', 'title': _('Remove'), }] tiles.append(tiletype) tiles.sort(key=attrgetter('title')) return tiles
def tileTypes(self): """Get a list of addable ITileType objects representing tiles which are addable in the current context """ tiles = [] for tile_name in getUtility(IRegistry)['plone.app.tiles']: tiletype = getUtility(ITileType, tile_name) # check if we have permission to add this tile if checkPermission(tiletype.add_permission, self.context): # tile actions # TODO: read from registry tiletype.actions = [{ 'name': 'edit', 'url': '@@edit-tile', 'title': _('Edit'), }, { 'name': 'remove', 'url': '@@delete-tile', 'title': _('Remove'), }] tiles.append(tiletype) tiles.sort(self.tileSortKey) return tiles
def actions(self): return [{ 'name': 'edit', 'url': '@@edit-tile', 'title': _('Edit'), }, { 'name': 'remove', 'url': '@@delete-tile', 'title': _('Remove'), }]
class ILogoTile(model.Schema): """ """ form.widget(picture='plone.app.imagetile.imagewidget.ImageFieldWidget') picture = NamedImage( title=_('Select an image'), required=True, ) title = TextLine( title=_('Image title.'), required=False, )
def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) content = {} applyChanges(self, content, data) dataManager.set(content) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, self.tileId)) IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) self.request.response.redirect(contextURL)
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, self.tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) #contextURL = absoluteURL(tile.context, self.request) #if tileURL.startswith(contextURL): # tileURL = '.' + tileURL[len(contextURL):] # Get the tile URL, possibly with encoded data IStatusMessage(self.request).addStatusMessage(_(u"Tile saved", ), type=u'info') notify(ObjectModifiedEvent(tile)) self.request.response.redirect(tileURL)
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectModifiedEvent(tile)) # Get the tile URL, possibly with encoded data IStatusMessage(self.request).addStatusMessage(_(u"Tile saved",), type=u'info') self.request.response.redirect(tileURL)
def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ context = self.context # Look up if our context supports tiles, if not # pick default view instead if not ILayoutAware(context, None): default_page_view = getMultiAdapter((context, self.request), name='default_page') default_page = default_page_view.getDefaultPage() context = default_page and context[default_page] or context context = ILayoutAware(context, None) # Traverse to a new tile in the context, with no data tile = context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, self.tileId)) IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) # Calculate the edit URL and append some data in a JSON structure, # to help the UI know what to do. url = getEditTileURL(tile, self.request) tileDataJson = {} tileDataJson['action'] = "save" tileDataJson['mode'] = "add" tileDataJson['url'] = tileRelativeURL tileDataJson['tile_type'] = typeName tileDataJson['id'] = tile.id url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url)
def __call__(self): self.errors = {} self.request['disable_border'] = True if 'form.button.Create' in self.request: newTileType = self.request.get('type', None) if newTileType is None: self.errors['type'] = _(u"You must select the type of " + \ u"tile to create") generator = getUtility(IUUIDGenerator) newTileId = generator() if newTileId is None: self.errors['id'] = _(u"You must specify an id") if len(self.errors) == 0: self.request.response.redirect("%s/@@add-tile/%s/%s" % \ (self.context.absolute_url(), newTileType, newTileId)) return '' return self.index()
def __call__(self): self.errors = {} self.request["disable_border"] = True if "form.button.Create" in self.request: newTileType = self.request.get("tiletype", None) if newTileType is None: self.errors["tiletype"] = _(u"You must select the type of " + u"tile to create") if len(self.errors) == 0: self.request.response.redirect("%s/@@add-tile/%s" % (self.context.absolute_url(), newTileType)) return "" return self.index()
def tileTypes(self): """Get a list of addable ITileType objects representing tiles which are addable in the current context """ tiles = [] factory = getUtility(IVocabularyFactory, name=ALLOWED_TILES_VOCABULARY) vocabulary = factory(self.context) for item in vocabulary: tiletype = item.value # check if we have permission to add this tile if tiletype and checkPermission(tiletype.add_permission, self.context): # tile actions # TODO: read from registry tiletype.actions = [ {"name": "edit", "url": "@@edit-tile", "title": _("Edit")}, {"name": "remove", "url": "@@delete-tile", "title": _("Remove")}, ] tiles.append(tiletype) tiles.sort(self.tileSortKey) return tiles
def __call__(self): self.errors = {} self.request['disable_border'] = True if 'form.button.Create' in self.request: newTileType = self.request.get('tiletype', None) if newTileType is None: self.errors['tiletype'] = _(u"You must select the type of " + u"tile to create") if len(self.errors) == 0: self.request.response.redirect( "%s/@@add-tile/%s" % (self.context.absolute_url(), newTileType)) return '' return self.index()
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, self.tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectModifiedEvent(tile)) # Get the tile URL, possibly with encoded data IStatusMessage(self.request).addStatusMessage(_(u"Tile saved", ), type=u'info') # Calculate the edit URL and append some data in a JSON structure, # to help the UI know what to do. url = getEditTileURL(tile, self.request) tileDataJson = {} tileDataJson['action'] = "save" tileDataJson['mode'] = "edit" tileDataJson['url'] = tileRelativeURL tileDataJson['tile_type'] = typeName tileDataJson['id'] = tile.id url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url)
def handleDelete(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to the tile about to be removed tile = self.context.restrictedTraverse( "@@%s/%s" % (typeName, self.tileId,) ) # Look up the URL - we need to do this before we've deleted the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) dataManager = ITileDataManager(tile) dataManager.delete() # PATCH # key = "{}/{}".format(typeName, self.tileId) if key in dataManager.storage.keys(): # this is a not persistent tile and we need to force deletion dataManager.storage[key] = {} # END OF PATCH # notify(ObjectRemovedEvent(tile, self.context, self.tileId)) logger.debug(u"Tile deleted at {0}".format(tileURL)) # Skip form rendering for AJAX requests if self.request.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest": IStatusMessage(self.request).addStatusMessage( _(u"Tile deleted at ${url}", mapping={"url": tileURL}), type=u"info", ) self.template = lambda: u"" return try: url = self.nextURL(tile) except NotImplementedError: url = self.context.absolute_url() self.request.response.redirect(url)
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectModifiedEvent(tile)) # Get the tile URL, possibly with encoded data IStatusMessage(self.request).addStatusMessage(_(u"Tile saved",), type=u'info') # Calculate the edit URL and append some data in a JSON structure, # to help the UI know what to do. url = getEditTileURL(tile, self.request) tileDataJson = {} tileDataJson['action'] = "save" tileDataJson['mode'] = "edit" tileDataJson['url'] = tileRelativeURL tileDataJson['tile_type'] = typeName tileDataJson['id'] = tile.id url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url)
def __call__(self): self.errors = {} self.request['disable_border'] = True if 'form.button.Create' in self.request: newTileType = self.request.get('tiletype', None) if newTileType is None: self.errors['tiletype'] = _(u"You must select the type of " + u"tile to create") if len(self.errors) == 0: extra = '' if newTileType == 'castle.cms.dynamic': extra = '?castle.cms.dynamic.tile_id={}'.format( self.request.get('tile_id', '')) self.request.response.redirect( "%s/@@add-tile/%s%s" % (self.context.absolute_url(), newTileType, extra)) return '' return self.index()
def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ generator = getUtility(IUUIDGenerator) tileId = generator() # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, tileId)) self.request.response.redirect(tileURL)
def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ generator = getUtility(IUUIDGenerator) tileId = generator() # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, tileId)) IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) self.request.response.redirect(tileURL)
def handleDelete(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) # Look up the URL - we need to do this before we've deletd the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) dataManager = ITileDataManager(tile) dataManager.delete() notify(ObjectRemovedEvent(tile)) logger.debug(u"Tile deleted at {0}".format(tileURL)) # Skip form rendering for AJAX requests if self.request.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': IStatusMessage(self.request).addStatusMessage( _(u"Tile deleted at ${url}", mapping={'url': tileURL}), type=u'info' ) self.template = lambda: u'' return try: url = self.nextURL(tile) except NotImplementedError: url = self.context.absolute_url() self.request.response.redirect(url)
def __call__(self): self.errors = {} self.request['disable_border'] = True if 'form.button.Create' in self.request: newTileType = self.request.get('tiletype', None) if newTileType is None: self.errors['tiletype'] = _(u"You must select the type of " + u"tile to create") if len(self.errors) == 0: # Redirect to tile add form with additional query query = self.request.form.copy() del query['tiletype'] del query['form.button.Create'] encoded = urlencode(query) if encoded: self.request.response.redirect("%s/@@add-tile/%s?%s" % ( self.context.absolute_url(), newTileType, encoded)) else: self.request.response.redirect("%s/@@add-tile/%s" % ( self.context.absolute_url(), newTileType)) return '' return self.index()
class DefaultDeleteForm(TileForm, form.Form): """Standard tile delete form, which is wrapped by DefaultDeleteView (see below). """ name = "delete_tile" # Set during traversal tileType = None tileId = None ignoreContext = True schema = None def __init__(self, context, request): super(DefaultDeleteForm, self).__init__(context, request) self.request['disable_border'] = True # UI @property def label(self): return _(u"Delete ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Delete'), name='delete') def handleDelete(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) # Look up the URL - we need to do this before we've deletd the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) dataManager = ITileDataManager(tile) dataManager.delete() notify(ObjectRemovedEvent(tile)) logger.debug(u"Tile deleted at {0}".format(tileURL)) # Skip form rendering for AJAX requests if self.request.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': IStatusMessage(self.request).addStatusMessage( _(u"Tile deleted at ${url}", mapping={'url': tileURL}), type=u'info' ) self.template = lambda: u'' return try: url = self.nextURL(tile) except NotImplementedError: url = self.context.absolute_url() self.request.response.redirect(url) def nextURL(self, tile): raise NotImplementedError @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): url = appendJSONData(self.action, '#', {'action': "cancel"}) url = url.replace('@@' + self.name.replace('_', '-') + '/', '@@') self.request.response.redirect(url) def updateActions(self): super(DefaultDeleteForm, self).updateActions() self.actions["delete"].addClass("context") self.actions["cancel"].addClass("standalone")
class DefaultAddForm(TileForm, form.Form): """Standard tile add form, which is wrapped by DefaultAddView (see below). This form is capable of rendering the fields of any tile schema as defined by an ITileType utility. """ # Set during traversal tileType = None tileId = None ignoreContext = True def __init__(self, context, request): super(DefaultAddForm, self).__init__(context, request) self.request['disable_border'] = True # UI @property def label(self): return _(u"Add ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Save'), name='save') def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ context = self.context # Look up if our context supports tiles, if not # pick default view instead if not ILayoutAware(context, None): default_page_view = getMultiAdapter((context, self.request), name='default_page') default_page = default_page_view.getDefaultPage() context = default_page and context[default_page] or context context = ILayoutAware(context, None) # Traverse to a new tile in the context, with no data tile = context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, self.tileId)) IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) # Calculate the edit URL and append some data in a JSON structure, # to help the UI know what to do. url = getEditTileURL(tile, self.request) tileDataJson = {} tileDataJson['action'] = "save" tileDataJson['mode'] = "add" tileDataJson['url'] = tileRelativeURL tileDataJson['tile_type'] = typeName tileDataJson['id'] = tile.id url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url) @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): tileDataJson = {} tileDataJson['action'] = "cancel" url = self.request.getURL() url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url) def updateActions(self): super(DefaultAddForm, self).updateActions() self.actions["save"].addClass("context") self.actions["cancel"].addClass("standalone")
def label(self): return _(u"Add ${name}", mapping={'name': self.tileType.title})
class DeleteForm(DefaultDeleteForm): @property def action(self): """See interfaces.IInputForm""" if self.tileType and self.tileId and self.name: # PATCH # url = "{url}/@@delete-tile/{type}/{id}".format( url=self.context.absolute_url(), type=self.tileType.__name__, id=self.tileId, ) # END OF PATCH # else: url = self.request.getURL() return url @button.buttonAndHandler(_("Delete"), name="delete") def handleDelete(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to the tile about to be removed tile = self.context.restrictedTraverse( "@@%s/%s" % (typeName, self.tileId,) ) # Look up the URL - we need to do this before we've deleted the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) dataManager = ITileDataManager(tile) dataManager.delete() # PATCH # key = "{}/{}".format(typeName, self.tileId) if key in dataManager.storage.keys(): # this is a not persistent tile and we need to force deletion dataManager.storage[key] = {} # END OF PATCH # notify(ObjectRemovedEvent(tile, self.context, self.tileId)) logger.debug(u"Tile deleted at {0}".format(tileURL)) # Skip form rendering for AJAX requests if self.request.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest": IStatusMessage(self.request).addStatusMessage( _(u"Tile deleted at ${url}", mapping={"url": tileURL}), type=u"info", ) self.template = lambda: u"" return try: url = self.nextURL(tile) except NotImplementedError: url = self.context.absolute_url() self.request.response.redirect(url) @button.buttonAndHandler(_(u"Cancel"), name="cancel") def handleCancel(self, action): super(DeleteForm, self).handleCancel(action)
def label(self): return _(u"Edit ${name}", mapping={'name': self.tileType.title})
class DefaultEditForm(TileForm, form.Form): """Standard tile edit form, which is wrapped by DefaultEditView (see below). This form is capable of rendering the fields of any tile schema as defined by an ITileType utility. """ name = "edit_tile" # Set during traversal tileType = None tileId = None ignoreContext = False # Avoid the data to be extracted from the request directly by the form # instead of using the tile data manager. ignoreRequest = True def __init__(self, context, request): super(DefaultEditForm, self).__init__(context, request) self.request['disable_border'] = True def update(self): if 'buttons.save' in self.request.form or \ 'buttons.cancel' in self.request.form: self.ignoreRequest = False super(DefaultEditForm, self).update() def getContent(self): typeName = self.tileType.__name__ tileId = self.tileId # Traverse to the tile. If it is a transient tile, it will pick up # query string parameters from the original request tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, tileId, )) dataManager = ITileDataManager(tile) return dataManager.get() # UI @property def label(self): return _(u"Edit ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Save'), name='save') def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, self.tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) #contextURL = absoluteURL(tile.context, self.request) #if tileURL.startswith(contextURL): # tileURL = '.' + tileURL[len(contextURL):] # Get the tile URL, possibly with encoded data IStatusMessage(self.request).addStatusMessage(_(u"Tile saved", ), type=u'info') notify(ObjectModifiedEvent(tile)) self.request.response.redirect(tileURL) @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): tileDataJson = {} tileDataJson['action'] = "cancel" url = self.request.getURL() url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url) def updateActions(self): super(DefaultEditForm, self).updateActions() self.actions["save"].addClass("context") self.actions["cancel"].addClass("standalone")
def label(self): return _(u"Edit ${name}", mapping={"name": self.tileType.title})
class DefaultAddForm(TileForm, form.Form): """Standard tile add form, which is wrapped by DefaultAddView (see below). This form is capable of rendering the fields of any tile schema as defined by an ITileType utility. """ name = "add_tile" # Set during traversal tileType = None tileId = None ignoreContext = True def __init__(self, context, request): super(DefaultAddForm, self).__init__(context, request) self.request['disable_border'] = True # UI @property def label(self): return _(u"Add ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Save'), name='save') def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ generator = getUtility(IUUIDGenerator) tileId = generator() # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) contextURL = absoluteURL(tile.context, self.request) tileRelativeURL = tileURL if tileURL.startswith(contextURL): tileRelativeURL = '.' + tileURL[len(contextURL):] IStatusMessage(self.request).addStatusMessage( _(u"Tile created at ${url}", mapping={'url': tileURL}), type=u'info', ) notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, tileId)) self.request.response.redirect(tileURL) @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): tileDataJson = {} tileDataJson['action'] = "cancel" url = self.request.getURL() url = appendJSONData(url, 'tiledata', tileDataJson) self.request.response.redirect(url) def updateActions(self): super(DefaultAddForm, self).updateActions() self.actions["save"].addClass("context") self.actions["cancel"].addClass("standalone")
class DefaultEditForm(TileForm, form.Form): """Standard tile edit form, which is wrapped by DefaultEditView (see below). This form is capable of rendering the fields of any tile schema as defined by an ITileType utility. """ name = "edit_tile" # Set during traversal tileType = None tileId = None ignoreContext = False # Avoid the data to be extracted from the request directly by the form # instead of using the tile data manager. ignoreRequest = True def __init__(self, context, request): super(DefaultEditForm, self).__init__(context, request) self.request['disable_border'] = True def update(self): if 'buttons.save' in self.request.form or \ 'buttons.cancel' in self.request.form: self.ignoreRequest = False super(DefaultEditForm, self).update() def getContent(self): typeName = self.tileType.__name__ tileId = self.tileId # Traverse to the tile. If it is a transient tile, it will pick up # query string parameters from the original request It is necessary to # defer security checking because during initial form setup, the # security context is not yet set. Setting the IDeferSecurityCheck # interface on the request is handled in # plone.z3cform.traversal.FormWidgetTraversal if IDeferSecurityCheck.providedBy(self.request): tile = self.context.unrestrictedTraverse( '@@%s/%s' % (typeName, tileId,)) else: tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, tileId,)) dataManager = ITileDataManager(tile) return AcquirableDictionary(dataManager.get()).__of__(self.context) # UI @property def label(self): return _(u"Edit ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Save'), name='save') def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse( '@@%s/%s' % (typeName, self.tileId,)) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) notify(ObjectModifiedEvent(tile)) logger.debug(u"Tile edited at {0}".format(tileURL)) try: url = self.nextURL(tile) except NotImplementedError: url = tileURL self.request.response.redirect(url) def nextURL(self, tile): raise NotImplementedError @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): url = appendJSONData(self.action, '#', {'action': "cancel"}) url = url.replace('@@' + self.name.replace('_', '-') + '/', '@@') self.request.response.redirect(url) def updateActions(self): super(DefaultEditForm, self).updateActions() self.actions["save"].addClass("context") self.actions["cancel"].addClass("standalone")
class DefaultAddForm(TileForm, form.Form): """Standard tile add form, which is wrapped by DefaultAddView (see below). This form is capable of rendering the fields of any tile schema as defined by an ITileType utility. """ name = "add_tile" # Set during traversal tileType = None tileId = None ignoreContext = True def __init__(self, context, request): super(DefaultAddForm, self).__init__(context, request) self.request['disable_border'] = True # UI @property def label(self): return _(u"Add ${name}", mapping={'name': self.tileType.title}) # Buttons/actions @button.buttonAndHandler(_('Save'), name='save') def handleAdd(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return typeName = self.tileType.__name__ generator = getUtility(IUUIDGenerator) tileId = generator() # Traverse to a new tile in the context, with no data tile = self.context.restrictedTraverse('@@%s/%s' % ( typeName, tileId, )) dataManager = ITileDataManager(tile) dataManager.set(data) # Look up the URL - we need to do this after we've set the data to # correctly account for transient tiles tileURL = absoluteURL(tile, self.request) notify(ObjectCreatedEvent(tile)) notify(ObjectAddedEvent(tile, self.context, tileId)) logger.debug(u"Tile created at {0}".format(tileURL)) try: url = self.nextURL(tile) except NotImplementedError: url = tileURL self.request.response.redirect(url) def nextURL(self, tile): raise NotImplementedError @button.buttonAndHandler(_(u'Cancel'), name='cancel') def handleCancel(self, action): url = appendJSONData(self.context.absolute_url(), '#', {'action': "cancel"}) self.request.response.redirect(url) def updateActions(self): super(DefaultAddForm, self).updateActions() self.actions["save"].addClass("context") self.actions["cancel"].addClass("standalone")