Exemplo n.º 1
0
 def render(self):
     model = self.model
     title = model.metadata.get('title', model.name)
     if not model.properties.action_delete:
         ts = _('object_not_deletable',
                default='Object "${title}" not deletable',
                mapping={'title': title})
         localizer = get_localizer(self.request)
         message = localizer.translate(ts)
         ajax_message(self.request, message, 'error')
         return u''
     content_tile = model.properties.action_delete_tile
     if not content_tile:
         content_tile = 'content'
     parent = model.parent
     del parent[model.name]
     if hasattr(parent, '__call__'):
         parent()
     query = make_query(contenttile=content_tile)
     url = make_url(self.request, node=parent, query=query)
     ajax_continue(self.request, self.continuation(url))
     if self.show_confirm_deleted:
         ts = _('deleted_object',
                default='Deleted: ${title}',
                mapping={'title': title})
         localizer = get_localizer(self.request)
         message = localizer.translate(ts)
         ajax_message(self.request, message, 'info')
     return u''
Exemplo n.º 2
0
 def render(self):
     model = self.model
     title = model.metadata.get('title', model.name)
     if not model.properties.action_delete:
         ts = _('object_not_deletable',
                default='Object "${title}" not deletable',
                mapping={'title': title})
         localizer = get_localizer(self.request)
         message = localizer.translate(ts)
         ajax_message(self.request, message, 'error')
         return u''
     content_tile = model.properties.action_delete_tile
     if not content_tile:
         content_tile = 'content'
     parent = model.parent
     del parent[model.name]
     if hasattr(parent, '__call__'):
         parent()
     query = make_query(contenttile=content_tile)
     url = make_url(self.request, node=parent, query=query)
     ajax_continue(self.request, self.continuation(url))
     if self.show_confirm_deleted:
         ts = _('deleted_object',
                default='Deleted: ${title}',
                mapping={'title': title})
         localizer = get_localizer(self.request)
         message = localizer.translate(ts)
         ajax_message(self.request, message, 'info')
     return u''
Exemplo n.º 3
0
 def render(self):
     try:
         message = self.create_container()
         ajax_message(self.request, message, 'info')
         continuation = self.continuation
         ajax_continue(self.request, continuation)
     except Exception, e:
         message = u"Can't create container %s" % str(e)
         ajax_message(self.request, message, 'error')
Exemplo n.º 4
0
 def render(self):
     request = self.request
     request.response.headers = forget(request)
     location = request.params.get('came_from', request.application_url)
     ajax_continue(self.request, AjaxEvent(
         target=location,
         name='contextchanged',
         selector='#layout'
     ))
     return u''
Exemplo n.º 5
0
 def render(self):
     request = self.request
     request.response.headers = forget(request)
     location = request.params.get('came_from', request.application_url)
     ajax_continue(
         self.request,
         AjaxEvent(target=location,
                   name='contextchanged',
                   selector='#layout'))
     return u''
Exemplo n.º 6
0
 def render(self):
     try:
         message = self.create_container()
         ajax_message(self.request, message, 'info')
         continuation = self.continuation
         ajax_continue(self.request, continuation)
     except Exception, e:
         localizer = get_localizer(self.request)
         message = localizer.translate(
             _('cannot_create_container',
               default="Can't create container: ${error}",
               mapping={'error': str(e)}))
         ajax_message(self.request, message, 'error')
Exemplo n.º 7
0
 def render(self):
     try:
         message = self.model.create_container()
         ajax_message(self.request, message, 'info')
         continuation = self.continuation
         ajax_continue(self.request, continuation)
     except Exception as e:
         localizer = get_localizer(self.request)
         message = localizer.translate(_(
             'cannot_create_container',
             default="Cannot create container: ${error}",
             mapping={'error': localizer.translate(e.error_message)}
         ))
         ajax_message(self.request, message, 'error')
     # XXX: initialize UGM backend?
     return u''
Exemplo n.º 8
0
 def render(self):
     conf = self.model.attrs
     url = 'http://%s:%s/%s/' % (conf.server, conf.port, conf.basepath)
     PySolr(url).delete(q='*:*')
     repositories = self.model.root['repositories']
     count = 0
     for repository in repositories.values():
         for media in repository.values():
             index_media(media)
             count += 1
             for revision in media.values():
                 index_revision(revision)
                 count += 1
     url = make_url(self.request, node=self.model)
     continuation = [AjaxAction(url, 'content', 'inner', '.solr')]
     ajax_continue(self.request, continuation)
     message = 'Rebuilt SOLR catalog. Catalog contains now %i items' % count
     ajax_message(self.request, message, 'info')
     return u''
Exemplo n.º 9
0
 def render(self):
     model = self.model
     title = model.metadata.get('title', model.name)
     if not model.properties.deletable:
         message = 'Object "%s" not deletable' % title
         ajax_message(self.request, message, 'error')
         return u''
     parent = model.parent
     del parent[model.name]
     if hasattr(parent, '__call__'):
         parent()
     url = make_url(self.request, node=parent)
     action = AjaxAction(url, 'content', 'inner', '#content')
     event = AjaxEvent(url, 'contextchanged', '.contextsensitiv')
     continuation = [action, event]
     ajax_continue(self.request, continuation)
     message = 'Deleted: %s' % title
     ajax_message(self.request, message, 'info')
     return u''
Exemplo n.º 10
0
 def render(self):
     ajax_continue(
         self.request,
         AjaxAction('target', 'name', 'mode', 'selector')
     )
     return u''
Exemplo n.º 11
0
 def render(self):
     cut = extract_copysupport_cookie(self.request, 'cut')
     copy = extract_copysupport_cookie(self.request, 'copy')
     localizer = get_localizer(self.request)
     if not cut and not copy:
         message = localizer.translate(
             _('nothing_to_paste', default='Nothing to paste'))
         ajax_message(self.request, message)
         return u''
     urls = copy and copy or cut
     paths = paths_from_urls(urls)
     call_sources = set()
     errors = list()
     success = 0
     for path in paths:
         node = self.model.root
         for key in path:
             node = node[key]
         if not node.node_info_name:
             message = localizer.translate(
                 _('cannot_paste_unknown_source',
                   default="Cannot paste '${name}'. Unknown source"),
                   mapping={'name': node.name})
             errors.append(message)
             continue
         if not self.model.node_info_name:
             message = localizer.translate(
                 _('cannot_paste_unknown_target',
                   default="Cannot paste to '${name}'. Unknown target"),
                   mapping={'name': self.model.name})
             errors.append(message)
             continue
         if not node.node_info_name in self.model.nodeinfo.addables:
             message = localizer.translate(
                 _('cannot_paste_cardinality_violation',
                   default="Violation. '${target}' is not allowed to " +\
                           "contain '${source}'"),
                   mapping={
                       'target': self.model.nodeinfo.title,
                       'source': node.nodeinfo.title})
             errors.append(message)
             continue
         source = node.parent
         if copy:
             node = source[node.name].deepcopy()
         else:
             in_model = False
             for parent in LocationIterator(self.model):
                 if parent is node:
                     message = localizer.translate(
                         _('cannot_paste_self_containment',
                           default="Cannot paste cut object to child " +\
                                   "of it: ${name}"),
                           mapping={'name': parent.name})
                     errors.append(message)
                     in_model = True
                     break
             if in_model:
                 continue
             node = source.detach(node.name)
         node.__parent__ = self.model
         self.model[choose_name(self.model, node.name)] = node
         if cut:
             call_sources.add(source)
         success += 1
     if success > 0:
         self.model()
     for source in call_sources:
         source()
     message = localizer.translate(
         _('pasted_items',
           default="Pasted ${count} items"),
           mapping={'count': success})
     if errors:
         failed = localizer.translate(
             _('pasting_items_failed',
               default="Pasting of ${count} items failed"),
               mapping={'count': len(errors)})
         failed = "<br /><strong>%s</strong>" % failed
         message += "<br />".join([failed] + errors)
     ajax_message(self.request, message)
     url = make_url(self.request, node=self.model)
     action = AjaxAction(url, 'content', 'inner', '#content')
     event = AjaxEvent(url, 'contextchanged', '.contextsensitiv')
     continuation = [action, event]
     ajax_continue(self.request, continuation)
     res = self.request.response
     res.delete_cookie(cookie_name(copy and 'copy' or 'cut'))
     return u''
Exemplo n.º 12
0
 def render(self):
     cut = extract_copysupport_cookie(self.request, 'cut')
     copy = extract_copysupport_cookie(self.request, 'copy')
     localizer = get_localizer(self.request)
     if not cut and not copy:
         message = localizer.translate(
             _('nothing_to_paste', default='Nothing to paste'))
         ajax_message(self.request, message)
         return u''
     urls = copy and copy or cut
     paths = paths_from_urls(urls)
     call_sources = set()
     errors = list()
     success = 0
     for path in paths:
         node = self.model.root
         for key in path:
             node = node[key]
         if not node.node_info_name:
             message = localizer.translate(_(
                 'cannot_paste_unknown_source',
                 default="Cannot paste '${name}'. Unknown source"),
                                           mapping={'name': node.name})
             errors.append(message)
             continue
         if not self.model.node_info_name:
             message = localizer.translate(
                 _('cannot_paste_unknown_target',
                   default="Cannot paste to '${name}'. Unknown target"),
                 mapping={'name': self.model.name})
             errors.append(message)
             continue
         if node.node_info_name not in self.model.nodeinfo.addables:
             message = localizer.translate(
                 _('cannot_paste_cardinality_violation',
                   default=("Violation. '${target}' is not allowed to "
                            "contain '${source}'")),
                 mapping={
                     'target': self.model.nodeinfo.title,
                     'source': node.nodeinfo.title
                 })
             errors.append(message)
             continue
         source = node.parent
         if copy:
             node = source[node.name].deepcopy()
         else:
             in_model = False
             for parent in LocationIterator(self.model):
                 if parent is node:
                     message = localizer.translate(
                         _('cannot_paste_self_containment',
                           default=("Cannot paste cut object to child "
                                    "of it: ${name}")),
                         mapping={'name': parent.name})
                     errors.append(message)
                     in_model = True
                     break
             if in_model:
                 continue
             node = source.detach(node.name)
         node.__parent__ = self.model
         self.model[choose_name(self.model, node.name)] = node
         if cut:
             call_sources.add(source)
         success += 1
     if success > 0:
         self.model()
     for source in call_sources:
         source()
     message = localizer.translate(_('pasted_items',
                                     default="Pasted ${count} items"),
                                   mapping={'count': success})
     if errors:
         failed = localizer.translate(_(
             'pasting_items_failed',
             default="Pasting of ${count} items failed"),
                                      mapping={'count': len(errors)})
         failed = "<br /><strong>%s</strong>" % failed
         message += "<br />".join([failed] + errors)
     ajax_message(self.request, message)
     content_tile = self.model.properties.action_paste_tile
     if not content_tile:
         content_tile = 'listing'
     query = make_query(contenttile=content_tile)
     url = make_url(self.request, node=self.model, query=query)
     event = AjaxEvent(url, 'contextchanged', '#layout')
     ajax_continue(self.request, event)
     res = self.request.response
     res.delete_cookie(cookie_name(copy and 'copy' or 'cut'))
     return u''
Exemplo n.º 13
0
 def contenttile(self):
     path = u"/".join([safe_decode(it) for it in self.model.path if it])
     ajax_continue(self.request, [AjaxPath(path)])
     return get_action_context(self.request).scope