Ejemplo n.º 1
0
 def references(self, start, end):
     ret = list()
     for record in self.visible_references[start:end]:
         # ref title and path
         title = self.reference_title(record)
         path = self.reference_path(record)
         # case rendered in frontend
         if self.is_frontend:
             query = make_query(**{
                 UX_IDENT: UX_FRONTEND,
                 'submitter_came_from': submitter_came_from(self.request),
             })
             ref = self._make_reference(
                 title,
                 target=make_url(self.request, path=path, query=query),
                 overlay=self.reference_tile,
                 icon=self.icon,
                 path=self.reference_permalink(record)
             )
         # case rendered in backend
         else:
             ref = self._make_reference(
                 title,
                 target=make_url(self.request, path=path),
                 event='contextchanged:#layout',
                 icon=self.icon,
                 path='target'
             )
         ret.append(ref)
     return ret
Ejemplo n.º 2
0
 def form_action(self, widget, data):
     resource = self.action_resource
     if self.form_flavor == 'add':
         return make_url(self.request,
                         node=self.model.parent,
                         resource=resource)
     return make_url(self.request, node=self.model, resource=resource)
Ejemplo n.º 3
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not self.request.has_permission('view', node):
             continue
         if not node.properties.get('in_navtree'):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(
             contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == safe_decode(key)
         icon = node_icon(node)
         css = ''
         if IWorkflowState.providedBy(node):
             css = 'state-%s' % node.state
         child = self.navtreeitem(title, url, target, node_path(node), icon,
                                  css)
         child['showchildren'] = curnode
         if curnode:
             child['selected'] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = node_path(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             # XXX: probably superfluous. keep as of cone.app 1.1
             # if selected_path == node_path(node):
             #     selected = True
             child['selected'] = selected
         tree['children'].append(child)
Ejemplo n.º 4
0
 def next(self, request):
     if self.ajax_request:
         url = make_url(request.request, node=self.model)
         selector = '.%s' % self.model.name
         return [
             AjaxAction(url, 'content', 'inner', selector),
         ]
     url = make_url(request.request, node=self.model.parent)
     return HTTPFound(location=url)
Ejemplo n.º 5
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not self.request.has_permission('view', node):
             continue
         if not node.properties.get('in_navtree'):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == safe_decode(key)
         icon = node_icon(node)
         css = ''
         if IWorkflowState.providedBy(node):
             css = 'state-%s' % node.state
         child = self.navtreeitem(
             title, url, target, node_path(node), icon, css)
         child['showchildren'] = curnode
         if curnode:
             child['selected'] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = node_path(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             # XXX: probably superfluous. keep as of cone.app 1.1
             # if selected_path == node_path(node):
             #     selected = True
             child['selected'] = selected
         tree['children'].append(child)
Ejemplo n.º 6
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not has_permission("view", node, self.request):
             continue
         if not node.properties.get("in_navtree"):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == key and True or False
         icon = node_icon(self.request, node)
         css = ""
         if IWorkflowState.providedBy(node):
             css = "state-%s" % node.state
         child = self.navtreeitem(title, url, target, nodepath(node), icon, css)
         child["showchildren"] = curnode
         if curnode:
             child["selected"] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = nodepath(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             if selected_path == nodepath(node):
                 selected = True
             child["selected"] = selected
         tree["children"].append(child)
Ejemplo n.º 7
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         query = make_query(pid=next_resource)
         url = make_url(request.request, node=self.model.parent, query=query)
     else:
         url = make_url(request.request, node=self.model.parent)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 8
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         query = make_query(pid=next_resource)
         url = make_url(request.request, node=self.model.parent, query=query)
     else:
         url = make_url(request.request, node=self.model.parent)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 9
0
    def __get__(self, obj, objtype=None):
        if obj is None:
            return self

        appuser = obj.model
        user = appuser.model
        related_ids = user.membership.keys()
        # always True if we list members only, otherwise will be set
        # in the loop below
        related = self.related_only

        if self.related_only:
            groups = user.membership
        else:
            groups = obj.model.root['groups'].ldap_groups

        ret = list()
        col_1_attr = obj.group_attrs

        # XXX: These should be the mapped attributes - lack of backend support
        for id in groups.keys():
            group = groups[id]

            # XXX: resource was only set for alluserlisting
            item_target = make_url(obj.request, node=group, resource=id)
            action_query = make_query(id=id)
            action_target = make_url(obj.request,
                                     node=appuser,
                                     query=action_query)

            if not self.related_only:
                related = id in related_ids

            action_id = 'add_item'
            action_enabled = not bool(related)
            action_title = 'Add user to selected group'
            add_item_action = obj.create_action(action_id, action_enabled,
                                                action_title, action_target)

            action_id = 'remove_item'
            action_enabled = bool(related)
            action_title = 'Remove user from selected group'
            remove_item_action = obj.create_action(action_id, action_enabled,
                                                   action_title, action_target)

            actions = [add_item_action, remove_item_action]
            val_1 = group.attrs[col_1_attr]
            content = obj.item_content(val_1)
            item = obj.create_item(val_1, item_target, content, False, actions)
            ret.append(item)
        return ret
Ejemplo n.º 10
0
    def __get__(self, obj, objtype=None):
        if obj is None:
            return self

        appuser = obj.model
        user = appuser.model
        related_ids = user.membership.keys()
        # always True if we list members only, otherwise will be set
        # in the loop below
        related = self.related_only

        if self.related_only:
            groups = user.membership
        else:
            groups = obj.model.root['groups'].ldap_groups

        ret = list()
        col_1_attr = obj.group_attrs

        # XXX: These should be the mapped attributes - lack of backend support
        for id in groups.keys():
            group = groups[id]

            # XXX: resource was only set for alluserlisting
            item_target = make_url(obj.request, node=group, resource=id)
            action_query = make_query(id=id)
            action_target = make_url(obj.request,
                                     node=appuser,
                                     query=action_query)

            if not self.related_only:
                related = id in related_ids

            action_id = 'add_item'
            action_enabled = not bool(related)
            action_title = 'Add user to selected group'
            add_item_action = obj.create_action(
                action_id, action_enabled, action_title, action_target)

            action_id = 'remove_item'
            action_enabled = bool(related)
            action_title = 'Remove user from selected group'
            remove_item_action = obj.create_action(
                action_id, action_enabled, action_title, action_target)

            actions = [add_item_action, remove_item_action]
            val_1 = group.attrs[col_1_attr]
            content = obj.item_content(val_1)
            item = obj.create_item(val_1, item_target, content, False, actions)
            ret.append(item)
        return ret
Ejemplo n.º 11
0
 def test_make_url(self):
     root = BaseNode()
     root['child'] = BaseNode()
     request = self.layer.new_request()
     self.assertEqual(make_url(request), 'http://example.com/')
     self.assertEqual(make_url(request, path=['1', '2', '3']),
                      'http://example.com/1/2/3')
     self.assertEqual(make_url(request, node=root['child']),
                      'http://example.com/child')
     self.assertEqual(make_url(request, node=root['child'], resource='foo'),
                      'http://example.com/child/foo')
     self.assertEqual(
         make_url(request, node=root['child'], resource='foo',
                  query='&a=1'), 'http://example.com/child/foo&a=1')
Ejemplo n.º 12
0
 def target(self):
     query = make_query(**{
         'sort': self.request.params.get('sort'),
         'term': self.request.params.get('term'),
         'order': self.request.params.get('order'),
         'b_page': self.request.params.get('b_page'),
         'size': self.request.params.get('size'),
     })
     came_from = make_url(self.request, node=self.model.root, query=query)
     query = make_query(**{
         UX_IDENT: UX_FRONTEND,
         'submitter_came_from': urllib2.quote(came_from),
     })
     return make_url(self.request, node=self.model, query=query)
Ejemplo n.º 13
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         url = make_url(request.request,
                        node=self.model,
                        resource=next_resource)
     else:
         url = make_url(request.request, node=self.model)
     if request.get('ajax'):
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 14
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         url = make_url(request.request,
                        node=self.model,
                        resource=next_resource)
     else:
         url = make_url(request.request, node=self.model)
     if request.get('ajax'):
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 15
0
 def prepare(_next, self):
     """Hook after prepare and set 'portrait' as image widget to
     ``self.form``.
     """
     _next(self)
     if not self.portrait_support:
         return
     model = self.model
     request = self.request
     if request.has_permission('edit_user', model.parent):
         mode = 'edit'
     else:
         mode = 'display'
     settings = general_settings(model)
     image_attr = settings.attrs.users_portrait_attr
     image_accept = settings.attrs.users_portrait_accept
     image_width = int(settings.attrs.users_portrait_width)
     image_height = int(settings.attrs.users_portrait_height)
     image_data = model.attrs.get(image_attr)
     if image_data:
         image_value = {
             'file': BytesIO(image_data),
             'mimetype': 'image/jpeg',
         }
         image_url = make_url(request,
                              node=model,
                              resource='portrait_image')
     else:
         image_value = UNSET
         resource = 'cone.ugm.static/images/default_portrait.jpg'
         image_url = make_url(request, node=model.root, resource=resource)
     portrait_widget = factory('field:label:error:image',
                               name='portrait',
                               value=image_value,
                               props={
                                   'label': _('portrait',
                                              default='Portrait'),
                                   'src': image_url,
                                   'alt': _('portrait', default='Portrait'),
                                   'accept': image_accept,
                                   'minsize': (image_width, image_height),
                                   'crop': {
                                       'size': (image_width, image_height),
                                       'fitting': True,
                                   }
                               },
                               mode=mode)
     save_widget = self.form['save']
     self.form.insertbefore(portrait_widget, save_widget)
Ejemplo n.º 16
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Ejemplo n.º 17
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Ejemplo n.º 18
0
 def prepare(_next, self):
     """Hook after prepare and set 'portrait' as image widget to
     ``self.form``.
     """
     _next(self)
     if not self.portrait_support:
         return
     model = self.model
     request = self.request
     if has_permission('edit_user', model.parent, request):
         mode = 'edit'
     else:
         mode = 'display'
     cfg = ugm_general(model)
     image_attr = cfg.attrs['users_portrait_attr']
     image_accept = cfg.attrs['users_portrait_accept']
     image_width = int(cfg.attrs['users_portrait_width'])
     image_height = int(cfg.attrs['users_portrait_height'])
     image_data = model.attrs.get(image_attr)
     if image_data:
         image_value = {
             'file': StringIO(image_data),
             'mimetype': 'image/jpeg',
         }
         image_url = make_url(request, node=model,
                              resource='portrait_image')
     else:
         image_value = UNSET
         resource = 'cone.ugm.static/images/default_portrait.jpg'
         image_url = make_url(request, node=model.root, resource=resource)
     portrait_widget = factory(
         'field:label:error:image',
         name='portrait',
         value=image_value,
         props={
             'label': _('portrait', 'Portrait'),
             'src': image_url,
             'alt': _('portrait', 'Portrait'),
             'accept': image_accept,
             'minsize': (image_width, image_height),
             'crop': {
                 'size': (image_width, image_height),
                 'fitting': True,
             }
         },
         mode=mode)
     save_widget = self.form['save']
     self.form.insertbefore(portrait_widget, save_widget)
Ejemplo n.º 19
0
 def prepare(self):
     action = make_url(self.request, node=self.model, resource='login')
     form = factory(
         u'form',
         name='loginform',
         props={
             'action': action
         })
     form['user'] = factory(
         'field:label:error:text',
         props = {
             'required': 'No username given',
             'label': 'Username',
         })    
     form['password'] = factory(
         'field:label:*credentials:error:password',
         props = {
             'required': 'No password given',
             'label': 'Password',
         },
         custom = {
             'credentials': ([self.login], [], [], []),
         })
     form['login'] = factory(
         'submit',
         props = {
             'action': 'login',
             'expression': True,
             'handler': self.noop,
             'next': self.next,
             'label': 'Login',
         })
     self.form = form
Ejemplo n.º 20
0
 def create_item(self, node, props, empty_title, selected):
     md = node.metadata
     item = dict()
     item["id"] = node.name
     if empty_title:
         item["title"] = ""
         item["description"] = md.title
     else:
         item["title"] = md.title
         item["description"] = md.description
     item["url"] = make_url(self.request, node=node)
     query = make_query(contenttile=props.default_content_tile)
     item["target"] = make_url(self.request, node=node, query=query)
     item["selected"] = selected
     item["icon"] = node_icon(self.request, node)
     return item
Ejemplo n.º 21
0
    def query_items(self):
        can_delete = has_permission(self.delete_permission,
                                    self.model,
                                    self.request)
        try:
            attrlist = self.listing_attrs
            criteria = self.listing_criteria
            sort_attr = self.sort_attr
            ret = list()
            users = self.model.backend
            result = users.search(criteria=criteria,
                                  attrlist=attrlist,
                                  or_search=True)
            for key, attrs in result:
                target = make_url(self.request,
                                  node=self.model,
                                  resource=key)
                actions = list()
                if can_delete:
                    action_id = 'delete_item'
                    action_title = self.delete_label
                    delete_action = self.create_action(
                        action_id, True, action_title, target)
                    actions = [delete_action]

                vals = [self.extract_raw(attrs, attr) for attr in attrlist]
                sort = self.extract_raw(attrs, sort_attr)
                content = self.item_content(*vals)
                current = self.current_id == key
                item = self.create_item(
                    sort, target, content, current, actions)
                ret.append(item)
            return ret
        except Exception, e:
            logger.error(str(e))
Ejemplo n.º 22
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''
Ejemplo n.º 23
0
 def menuitems(self):
     ret = list()
     count = 0
     path = nodepath(self.model)
     if path:
         curpath = path[0]
     else:
         curpath = ''
     # work with ``self.model.root.keys()``, ``values()`` propably not works
     # due to the use of factory node.
     root = self.model.root
     # check for default child id if no curpath
     if not curpath and root.properties.default_child:
         curpath = root.properties.default_child
     # check wether to render mainmenu item title
     empty_title = root.properties.mainmenu_empty_title
     for key in root.keys():
         child = root[key]
         if not has_permission('view', child, self.request):
             continue
         item = dict()
         item['id'] = key
         if empty_title:
             item['title'] = ' '
             item['description'] = child.metadata.title
         else:
             item['title'] = child.metadata.title
             item['description'] = child.metadata.description
         item['url'] = make_url(self.request, path=[key])
         item['selected'] = curpath == key
         item['first'] = count == 0
         ret.append(item)
         count += 1
     return ret
Ejemplo n.º 24
0
 def items(self):
     items = list()
     node = self.model
     while node is not None:
         items.append({
             'title': node.metadata.title,
             'url': make_url(self.request, node=node),
             'selected': False,
             'id': node.name,
             'default_child': node.properties.default_child,
         })
         node = node.parent
     items.reverse()
     ret = list()
     count = len(items)
     for i in range(count):
         default_child = items[i]['default_child']
         if default_child \
           and i < count - 1 \
           and default_child == items[i + 1]['id']:
             continue
         ret.append(items[i])
     ret[0]['title'] = 'Home'
     ret[-1]['selected'] = True
     return ret
Ejemplo n.º 25
0
 def create_item(self, node, props, empty_title, selected):
     md = node.metadata
     item = dict()
     item['id'] = node.name
     if empty_title:
         item['title'] = ''
         item['description'] = md.title
     else:
         item['title'] = md.title
         item['description'] = md.description
     item['url'] = make_url(self.request, node=node)
     query = make_query(contenttile=props.default_content_tile)
     item['target'] = make_url(self.request, node=node, query=query)
     item['selected'] = selected
     item['icon'] = node_icon(node)
     return item
Ejemplo n.º 26
0
 def batch_target(self, path, b_page):
     query = make_query(
         b_page=str(b_page),
         filter=self.filter_term,
         sort=self.sort_column,
         order=self.sort_order)
     return safe_decode(make_url(self.request, path=path, query=query))
Ejemplo n.º 27
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = self.references_tile.item_count
     slicesize = self.references_tile.slicesize
     pages = count / slicesize
     if count % slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     params = {
         UX_IDENT: UX_FRONTEND,
         'submitter_came_from': submitter_came_from(self.request),
         'size': slicesize,
     }
     for i in range(pages):
         params['b_page'] = str(i)
         query = make_query(**params)
         url = make_url(self.request, path=path, query=query)
         ret.append({
             'page': '%i' % (i + 1),
             'current': current == str(i),
             'visible': True,
             'url': url,
         })
     return ret
Ejemplo n.º 28
0
 def vocab(self):
     ret = list()
     path = node_path(self.model)
     count = self.table_tile.item_count
     slicesize = self.table_tile.slicesize
     pages = count / slicesize
     if count % slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     params = {
         'sort': self.table_tile.sort_column,
         'order': self.table_tile.sort_order,
         'size': slicesize,
         'term': self.table_tile.filter_term,
     }
     for term in self.table_tile.query_whitelist:
         params[term] = self.request.params.get(term, '')
     for i in range(pages):
         params['b_page'] = str(i)
         query = make_query(**params)
         url = make_url(
             self.request,
             path=path,
             #resource=self.related_view,
             query=query)
         ret.append({
             'page': '%i' % (i + 1),
             'current': current == str(i),
             'visible': True,
             'url': url,
         })
     return ret
Ejemplo n.º 29
0
def wrap_ajax_target(rendered, widget, data):
    target = widget.attrs['target']
    if not target:
        request = data.request.request
        request = request if request else get_current_request()
        target = make_url(request, node=get_root())
    if callable(target):
        target = target(widget, data)
    referencable = widget.attrs['referencable']
    if callable(referencable):
        referencable = referencable(widget, data)
    if type(referencable) in compat.ITER_TYPES:
        referencable = ','.join(referencable)
    if not referencable:
        referencable = ''
    root = widget.attrs['root']
    if callable(root):
        root = root(widget, data)
    value = fetch_reference_value(widget, data)
    selected = ''
    if widget.attrs['multivalued'] and value:
        selected = ','.join(value)
    elif value:
        selected = value
    query = make_query(**{
        'root': root,
        'referencable': referencable,
        'selected': selected,
    })
    target = '{}{}'.format(target, query)
    attrs = {
        'ajax:target': target,
    }
    return tag('span', rendered, **attrs)
Ejemplo n.º 30
0
 def vocab(self):
     ret = list()
     path = node_path(self.model)
     count = self.table_tile.item_count
     slicesize = self.table_tile.slicesize
     pages = count // slicesize
     if count % slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     params = {
         'sort': self.table_tile.sort_column,
         'order': self.table_tile.sort_order,
         'size': slicesize,
         'term': self.table_tile.filter_term,
     }
     for term in self.table_tile.query_whitelist:
         params[term] = self.request.params.get(term, '')
     for i in range(pages):
         params['b_page'] = str(i)
         query = make_query(**params)
         url = make_url(
             self.request,
             path=path,
             # resource=self.related_view,
             query=query
         )
         ret.append({
             'page': '%i' % (i + 1),
             'current': current == str(i),
             'visible': True,
             'url': url,
         })
     return ret
Ejemplo n.º 31
0
 def create_item(self, node, props, empty_title, selected):
     md = node.metadata
     item = dict()
     item['id'] = node.name
     if empty_title:
         item['title'] = ''
         item['description'] = md.title
     else:
         item['title'] = md.title
         item['description'] = md.description
     item['url'] = make_url(self.request, node=node)
     query = make_query(contenttile=props.default_content_tile)
     item['target'] = make_url(self.request, node=node, query=query)
     item['selected'] = selected
     item['icon'] = node_icon(self.request, node)
     return item
Ejemplo n.º 32
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''
Ejemplo n.º 33
0
    def query_items(self):
        col_1_attr, col_2_attr, col_3_attr, sort_attr = self.user_attrs
        ret = list()
        attrlist = [col_1_attr, col_2_attr, col_3_attr]
        users = self.model.ldap_users
        result = users.search(criteria=None, attrlist=attrlist)
        for key, attrs in result:
            target = make_url(self.request,
                              node=self.model,
                              resource=key)

            action_id = 'delete_item'
            action_title = 'Delete User'
            delete_action = self.create_action(
                action_id, True, action_title, target)

            val_1 = self.extract_raw(attrs, col_1_attr)
            val_2 = self.extract_raw(attrs, col_2_attr)
            val_3 = self.extract_raw(attrs, col_3_attr)
            sort = self.extract_raw(attrs, sort_attr)
            content = self.item_content(val_1, val_2, val_3)
            current = self.current_id == key
            item = self.create_item(
                sort, target, content, current, [delete_action])
            ret.append(item)
        return ret
Ejemplo n.º 34
0
    def prepare(self):
        resource = 'add'
        if self.model.__name__ is not None:
            resource = 'edit'

            # XXX: tmp - load props each time they are accessed.
            self.model.attrs.context.load()

        action = make_url(self.request, node=self.model, resource=resource)
        form = factory(u'form',
                       name='userform',
                       props={
                           'action': action,
                           'class': 'ajax',
                       })
        settings = self.model.root['settings']
        attrmap = settings.attrs.users_form_attrmap
        if not attrmap:
            return form
        schema = self.schema
        required = self._required_fields
        protected = self._protected_fields
        default_chain = 'field:label:error:mode:text'
        for key, val in attrmap.items():
            field = schema.get(key, dict())
            chain = field.get('chain', default_chain)
            props = dict()
            props['label'] = val
            props['html5required'] = False
            if key in required:
                props['required'] = 'No %s defined' % val
            props.update(field.get('props', dict()))
            value = UNSET
            if resource == 'edit':
                if key in protected:
                    props['mode'] = 'display'
                value = self.model.attrs.get(key, u'')
            form[key] = factory(chain,
                                value=value,
                                props=props,
                                custom=field.get('custom', dict()))
        form['save'] = factory('submit',
                               props={
                                   'action': 'save',
                                   'expression': True,
                                   'handler': self.save,
                                   'next': self.next,
                                   'label': 'Save',
                               })
        if resource == 'add':
            form['cancel'] = factory('submit',
                                     props={
                                         'action': 'cancel',
                                         'expression': True,
                                         'handler': None,
                                         'next': self.next,
                                         'label': 'Cancel',
                                         'skip': True,
                                     })
        self.form = form
Ejemplo n.º 35
0
 def sort_target(self, sort, order):
     query = make_query(
         filter=self.filter_term,
         b_page=self.current_page,
         sort=sort,
         order=order)
     return safe_decode(make_url(self.request, node=self.model, query=query))
Ejemplo n.º 36
0
    def next(self, request):
        """Read 'came_from' parameter from request and compute next url.

        If came_from is 'parent', URL of node parent is computed.
        If came_from is set but not 'parent', it is considered as URL to use
        If no came_from is set, return URL of node
        """
        if request.get('came_from') == 'parent':
            url = make_url(request.request, node=self.model.parent)
        elif request.get('came_from'):
            url = request.get('came_from')
        else:
            url = make_url(request.request, node=self.model)
        if self.ajax_request:
            return [AjaxEvent(url, 'contextchanged', '#layout')]
        return HTTPFound(location=url)
Ejemplo n.º 37
0
 def action_up(self):
     action = self.model.properties.action_up_tile
     if not action:
         action = 'listing'
     return {
         'target': make_url(self.request, node=self.model.parent),
         'action': '%s:#content:inner' % action,
     }
Ejemplo n.º 38
0
 def next(self, request):
     url = make_url(request.request, node=self.model)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 39
0
 def next(self, request):
     url = make_url(request.request, node=self.model)
     if request.get('ajax'):
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 40
0
 def image_src(self):
     a_type = self.model.attrs['attachment_type']
     if a_type == 'image':
         query = make_query(scale='mini')
         return make_url(self.request,
                         node=self.model,
                         resource='download',
                         query=query)
Ejemplo n.º 41
0
 def items(self):
     model = self.model
     ret = [{
         'title': model.metadata.title,
         'url': make_url(self.request, node=model),
         'selected': True,
     }]
     while model.__parent__ is not None:
         model = model.__parent__
         ret.append({
             'title': model.metadata.title,
             'url': make_url(self.request, node=model),
             'selected': False,
         })
     ret.pop()
     ret.reverse()
     return ret
Ejemplo n.º 42
0
 def vocab(self):
     ret = list()
     path = node_path(self.model)
     current = self.request.params.get('b_page', '0')
     for i in range(10):
         query = make_query(b_page=str(i))
         href = make_url(self.request,
                         path=path,
                         resource='someview',
                         query=query)
         target = make_url(self.request, path=path, query=query)
         ret.append({
             'page': '%i' % i,
             'current': current == str(i),
             'visible': True,
             'href': href,
             'target': target,
         })
     return ret
Ejemplo n.º 43
0
 def tabs(self):
     ret = list()
     for val in self.model.values():
         ret.append({
             'title': val.metadata.title,
             'target': make_url(self.request,
                                node=val,
                                resource='settings_tab_content'),
         })
     return ret
Ejemplo n.º 44
0
 def target(self):
     container = self.model.parent
     default_child = container.properties.default_child
     if default_child and self.model.name == default_child:
         container = container.parent
     contenttile = self.model.properties.action_up_tile
     if not contenttile:
         contenttile = 'listing'
     query = make_query(contenttile=contenttile)
     return make_url(self.request, node=container, query=query)
Ejemplo n.º 45
0
 def next(self, request):
     came_from_url = urllib2.unquote(request.get('authoring_came_from'))
     came_from_url += make_query(**{
         UX_IDENT: UX_FRONTEND,
         'submitter_came_from': submitter_came_from(self.request),
     })
     came_from_tile = request.get('came_from_tile')
     root_url = make_url(self.request, node=self.model.root)
     return [AjaxOverlay(action=came_from_tile, target=came_from_url),
             AjaxEvent(root_url, 'datachanged', '#chronotope-map')]
Ejemplo n.º 46
0
 def next(self, request):
     came_from_url = urllib2.unquote(request.get('authoring_came_from'))
     root_url = make_url(self.request, node=self.model.root)
     if not came_from_url:
         if request.get('action.{0}.cancel'.format(self.form_name)):
             return [AjaxOverlay(close=True)]
         query = make_query(**{
             UX_IDENT: UX_FRONTEND,
         })
         url = make_url(self.request, node=self.model, query=query)
         return [AjaxOverlay(action='location', target=url),
                 AjaxEvent(root_url, 'datachanged', '#chronotope-map')]
     came_from_url += make_query(**{
         UX_IDENT: UX_FRONTEND,
         'submitter_came_from': submitter_came_from(self.request),
     })
     came_from_tile = request.get('came_from_tile')
     return [AjaxOverlay(action=came_from_tile, target=came_from_url),
             AjaxEvent(root_url, 'datachanged', '#chronotope-map')]
Ejemplo n.º 47
0
 def items(self):
     ret = list()
     addables = self.model.nodeinfo.addables
     if not addables:
         return ret
     for addable in addables:
         info = getNodeInfo(addable)
         if not info:
             continue
         query = make_query(factory=addable)
         url = make_url(self.request, node=self.model,
                        resource='add', query=query)
         target = make_url(self.request, node=self.model, query=query)
         props = Properties()
         props.url = url
         props.target = target
         props.title = info.title
         props.icon = info.icon
         ret.append(props)
     return ret
Ejemplo n.º 48
0
 def do_transition(self):
     """if ``do_transition`` is found on request.params, perform
     transition.
     """
     transition = self.request.params.get('do_transition')
     if not transition:
         return
     workflow = self.workflow
     workflow.transition(self.model, self.request, transition)
     self.model()
     url = make_url(self.request, node=self.model)
     continuation = [AjaxEvent(url, 'contextchanged', '#layout')]
     self.request.environ['cone.app.continuation'] = continuation
Ejemplo n.º 49
0
 def next(self, request):
     came_from = request.get('came_from')
     if came_from:
         came_from = compat.unquote(came_from)
         url = '{}?pid={}'.format(came_from, self.model.name)
     else:
         url = make_url(request.request, node=self.model)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Ejemplo n.º 50
0
 def vocab(self):
     ret = list()
     path = node_path(self.model)
     current = self.request.params.get('b_page', '0')
     for i in range(10):
         query = make_query(b_page=str(i))
         url = make_url(self.request, path=path, query=query)
         ret.append({
             'page': '%i' % i,
             'current': current == str(i),
             'visible': True,
             'url': url
         })
     return ret
Ejemplo n.º 51
0
 def prepare(self):
     action = make_url(self.request, node=self.model, resource='login')
     form = factory(u'form',
                    name='loginform',
                    props={
                        'action': action,
                        'class': 'form-horizontal',
                    })
     form['user'] = factory('field:label:div:help:error:text',
                            props={
                                'required':
                                _('no_username_given',
                                  default='No username given'),
                                'label':
                                _('username', default='Username'),
                                'label.class_add':
                                'col-sm-2',
                                'div.class_add':
                                'col-sm-5',
                            })
     form['password'] = factory(
         'field:label:div:help:*credentials:error:password',
         props={
             'required': _('no_password_given',
                           default='No password given'),
             'label': _('password', default='Password'),
             'label.class_add': 'col-sm-2',
             'div.class_add': 'col-sm-5',
         },
         custom={
             'credentials': ([self.login], [], [], []),
         })
     actions = form['form_actions'] = factory(
         'field:div',
         props={
             'div.class_add': 'col-sm-offset-2 col-sm-5',
             'structural': True,
         })
     actions['login'] = factory('submit',
                                props={
                                    'action': 'login',
                                    'expression': True,
                                    'handler': self.noop,
                                    'next': self.next,
                                    'label': _('login', default='Login'),
                                    'div.class_add':
                                    'col-sm-offset-2 col-sm-5',
                                })
     self.form = form
Ejemplo n.º 52
0
 def prepare(self):
     resource = 'add'
     if self.model.__name__ is not None:
         resource = 'edit'
     action = make_url(self.request, node=self.model, resource=resource)
     form = factory(
         u'form',
         name='groupform',
         props={
             'action': action,
             'class': 'ajax',
         })
     props = {
         'label': 'Name',
         'required': 'No group id defined',
         'ascii': True,
         'html5required': False,
     }
     if resource == 'edit':
         props['mode'] = 'display'
     form['name'] = factory(
         'field:*ascii:*exists:label:error:mode:text',
         value=self.model.__name__,
         props=props,
         custom= {
             'ascii': ([ascii_extractor], [], [], []),
             'exists': ([self.exists], [], [], []),
         })
     if resource =='add': # XXX: no fields to edit atm
         form['save'] = factory(
             'submit',
             props={
                 'action': 'save',
                 'expression': True,
                 'handler': self.save,
                 'next': self.next,
                 'label': 'Save',
             })
     if resource =='add':
         form['cancel'] = factory(
             'submit',
             props={
                 'action': 'cancel',
                 'expression': True,
                 'next': self.next,
                 'label': 'Cancel',
                 'skip': True,
             })
     self.form = form
Ejemplo n.º 53
0
    def make_url(self, params, path=None, include_view=False):
        """Create URL considering ``query_whitelist``.

        :param params: Dictionary with query parameters.
        :param path: Optional model path, if ``None``, path gets taken from
            ``self.model``
        :param include_view: Boolean whether to include
            ``self.related_view`` to URL.
        :return: URL as string.
        """
        return safe_decode(
            make_url(self.request,
                     path=path,
                     node=None if path else self.model,
                     resource=self.related_view if include_view else None,
                     query=self.make_query(params)))
Ejemplo n.º 54
0
 def vocab(self):
     ret = list()
     path = nodepath(self.model)
     count = len(self.items)
     pages = count / self.slicesize
     if count % self.slicesize != 0:
         pages += 1
     current = self.request.params.get('b_page', '0')
     for i in range(pages):
         query = make_query(b_page=str(i))
         url = make_url(self.request, path=path, query=query)
         ret.append({
             'page': '%i' % (i + 1),
             'current': current == str(i),
             'visible': True,
             'url': url,
         })
     return ret
Ejemplo n.º 55
0
 def sorted_rows(self, start, end, sort, order):
     children = self.sorted_children(sort, order)
     rows = list()
     cut_urls = extract_copysupport_cookie(self.request, 'cut')
     for child in children[start:end]:
         row_data = self.row_data(child)
         target = make_url(self.request, node=child)
         if ICopySupport.providedBy(child):
             row_data.selectable = True
             row_data.target = target
             row_data.css = 'copysupportitem'
             if target in cut_urls:
                 row_data.css += ' copysupport_cut'
         if IWorkflowState.providedBy(child):
             row_data.css += ' state-%s' % child.state
         if hasattr(child, 'node_info_name') and child.node_info_name:
             row_data.css += ' node-type-%s' % child.node_info_name
         rows.append(row_data)
     return rows
Ejemplo n.º 56
0
    def test_copysupport(self):
        # Copysupport Attributes
        model = CopySupportNode()
        model['child'] = CopySupportNode()
        request = self.layer.new_request()

        with self.layer.authenticated('manager'):
            rendered = render_tile(model, request, 'contents')

        expected = 'class="selectable copysupportitem"'
        self.assertTrue(rendered.find(expected) > -1)

        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            cut_url = compat.quote(make_url(request, node=model['child']))
            request.cookies['cone.app.copysupport.cut'] = cut_url
            rendered = render_tile(model, request, 'contents')

        expected = 'class="selectable copysupportitem copysupport_cut"'
        self.assertTrue(rendered.find(expected) > -1)
Ejemplo n.º 57
0
 def query_items(self):
     col_1_attr = self.group_attrs
     ret = list()
     result = self.model.ldap_groups.search(criteria=None,
                                            attrlist=[col_1_attr])
     for key, attrs in result:
         target = make_url(self.request,
                           node=self.model,
                           resource=key)
         action_id = 'delete_item'
         action_title = 'Delete Group'
         delete_action = self.create_action(
             action_id, True, action_title, target)
         
         val_1 = self.extract_raw(attrs, col_1_attr)
         content = self.item_content(val_1)
         current = self.current_id == key
         item = self.create_item(
             val_1, target, content, current, [delete_action])
         ret.append(item)
     return ret
Ejemplo n.º 58
0
 def prepare(self):
     model = self.model
     request = self.request
     scope = self.action_resource
     self.form = form = factory(u'form',
                                name=self.form_name,
                                props={
                                    'action':
                                    make_url(request,
                                             node=model,
                                             resource=scope),
                                })
     registry = self.field_factory_registry
     backend_name = ugm_backend.name
     form_attrs = itertools.chain(
         self.reserved_attrs.items(),
         self.form_attrmap.items() if self.form_attrmap else [])
     for attr_name, label in form_attrs:
         field_factory = registry.factory(attr_name, backend=backend_name)
         value = model.attrs.get(attr_name, UNSET)
         form[attr_name] = field_factory(self, label, value)
     form['save'] = factory('submit',
                            props={
                                'action': 'save',
                                'expression': True,
                                'handler': self.save,
                                'next': self.next,
                                'label': _('save', default='Save')
                            })
     if scope == 'add':
         form['cancel'] = factory('submit',
                                  props={
                                      'action': 'cancel',
                                      'expression': True,
                                      'handler': None,
                                      'next': self.next,
                                      'label': _('cancel',
                                                 default='Cancel'),
                                      'skip': True
                                  })
Ejemplo n.º 59
0
 def transitions(self):
     self.do_transition()
     ret = list()
     try:
         workflow = self.workflow
         transitions = workflow.get_transitions(
             self.model, self.request, from_state=self.model.state)
     except (WorkflowError, AttributeError) as e:
         logger.error("transitions error: %s" % str(e))
         return ret
     workflow_tsf = self.model.workflow_tsf
     for transition in transitions:
         query = make_query(do_transition=transition['name'])
         target = make_url(self.request, node=self.model, query=query)
         props = Properties()
         props.target = target
         if workflow_tsf:
             props.title = workflow_tsf(transition['name'])
         else:
             props.title = transition['name']
         ret.append(props)
     return ret