Example #1
0
 def __call__(self):
     self.remove = set([
         v.encode('utf8')
         for v in json_loads(self.request.form.get('remove'))
     ])
     self.add = set([
         v.encode('utf8') for v in json_loads(self.request.form.get('add'))
     ])
     return super(TagsAction, self).__call__()
Example #2
0
 def __call__(self):
     self.effectiveDate = self.request.form.get("effectiveDate")
     effectiveTime = self.request.form.get("effectiveTime")
     if self.effectiveDate and effectiveTime:
         self.effectiveDate = self.effectiveDate + " " + effectiveTime
     self.expirationDate = self.request.form.get("expirationDate")
     expirationTime = self.request.form.get("expirationTime")
     if self.expirationDate and expirationTime:
         self.expirationDate = self.expirationDate + " " + expirationTime
     self.copyright = self.request.form.get("copyright", "")
     self.contributors = json_loads(self.request.form.get("contributors", "[]"))
     self.creators = json_loads(self.request.form.get("creators", "[]"))
     self.exclude = self.request.form.get("exclude_from_nav", None)
     return super(PropertiesAction, self).__call__()
Example #3
0
 def __call__(self):
     self.effectiveDate = self.request.form.get('effectiveDate')
     effectiveTime = self.request.form.get('effectiveTime')
     if self.effectiveDate and effectiveTime:
         self.effectiveDate = self.effectiveDate + ' ' + effectiveTime
     self.expirationDate = self.request.form.get('expirationDate')
     expirationTime = self.request.form.get('expirationTime')
     if self.expirationDate and expirationTime:
         self.expirationDate = self.expirationDate + ' ' + expirationTime
     self.copyright = self.request.form.get('copyright', '')
     self.contributors = json_loads(
         self.request.form.get('contributors', '[]'))
     self.creators = json_loads(self.request.form.get('creators', '[]'))
     self.exclude = self.request.form.get('exclude_from_nav', None)
     return super(PropertiesAction, self).__call__()
Example #4
0
 def __call__(self):
     self.effectiveDate = self.request.form.get('effectiveDate')
     effectiveTime = self.request.form.get('effectiveTime')
     if self.effectiveDate and effectiveTime:
         self.effectiveDate = self.effectiveDate + ' ' + effectiveTime
     self.expirationDate = self.request.form.get('expirationDate')
     expirationTime = self.request.form.get('expirationTime')
     if self.expirationDate and expirationTime:
         self.expirationDate = self.expirationDate + ' ' + expirationTime
     self.copyright = self.request.form.get('copyright', '')
     self.contributors = json_loads(
         self.request.form.get('contributors', '[]'))
     self.creators = json_loads(self.request.form.get('creators', '[]'))
     self.exclude = self.request.form.get('exclude_from_nav', None)
     return super(PropertiesAction, self).__call__()
Example #5
0
    def __call__(self):
        self.errors = []
        self.protect()
        id = self.request.form.get('id')
        ordering = self.getOrdering()

        if ordering is None:
            self.errors.append(_('This folder does not support ordering'))
            return self.message()

        delta = self.request.form['delta']

        if delta == 'top':
            ordering.moveObjectsToTop([id])
            return self.message()

        if delta == 'bottom':
            ordering.moveObjectsToBottom([id])
            return self.message()

        delta = int(delta)
        subset_ids = json_loads(self.request.form.get('subset_ids', '[]'))
        if subset_ids:
            position_id = [
                (ordering.getObjectPosition(i), i) for i in subset_ids
            ]
            position_id.sort()
            if subset_ids != [i for position, i in position_id]:
                self.errors.append(_('Client/server ordering mismatch'))
                return self.message()

        ordering.moveObjectsByDelta([id], delta)
        return self.message()
Example #6
0
def _parseJSON(s):
    if isinstance(s, basestring):
        s = s.strip()
        if (s.startswith('{') and s.endswith('}')) or \
                (s.startswith('[') and s.endswith(']')):  # detect if json
            return json_loads(s)
    return s
Example #7
0
def _parseJSON(s):
    if isinstance(s, basestring):
        s = s.strip()
        if (s.startswith('{') and s.endswith('}')) or \
                (s.startswith('[') and s.endswith(']')):  # detect if json
            return json_loads(s)
    return s
Example #8
0
    def __call__(self):
        self.errors = []
        self.protect()
        context = aq_inner(self.context)

        torename = json_loads(self.request.form['torename'])

        catalog = getToolByName(context, 'portal_catalog')
        mtool = getToolByName(context, 'portal_membership')

        missing = []
        for data in torename:
            uid = data['UID']
            brains = catalog(UID=uid)
            if len(brains) == 0:
                missing.append(uid)
                continue
            obj = brains[0].getObject()
            title = self.objectTitle(obj)
            if not mtool.checkPermission('Copy or Move', obj):
                self.errors(
                    _(u'Permission denied to rename ${title}.',
                      mapping={u'title': title}))
                continue

            sp = transaction.savepoint(optimistic=True)

            newid = data['newid'].encode('utf8')
            newtitle = data['newtitle']
            try:
                obid = obj.getId()
                title = obj.Title()
                change_title = newtitle and title != newtitle
                if change_title:
                    getSecurityManager().validate(obj, obj, 'setTitle',
                                                  obj.setTitle)
                    obj.setTitle(newtitle)
                    notify(ObjectModifiedEvent(obj))
                if newid and obid != newid:
                    parent = aq_parent(aq_inner(obj))
                    # Make sure newid is safe
                    newid = INameChooser(parent).chooseName(newid, obj)
                    # Update the default_page on the parent.
                    context_state = getMultiAdapter((obj, self.request),
                                                    name='plone_context_state')
                    if context_state.is_default_page():
                        parent.setDefaultPage(newid)
                    parent.manage_renameObjects((obid, ), (newid, ))
                elif change_title:
                    # the rename will have already triggered a reindex
                    obj.reindexObject()
            except ConflictError:
                raise
            except Exception:
                sp.rollback()
                self.errors.append(
                    _('Error renaming ${title}', mapping={'title': title}))

        return self.message(missing)
Example #9
0
def _parseJSON(s):
    # XXX this should be changed to a try loads except return s
    if isinstance(s, six.string_types):
        s = s.strip()
        if (s.startswith('{') and s.endswith('}')) or \
                (s.startswith('[') and s.endswith(']')):  # detect if json
            return json_loads(s)
    return s
Example #10
0
def _parseJSON(s):
    # XXX this should be changed to a try loads except return s
    if isinstance(s, six.string_types):
        s = s.strip()
        if (s.startswith('{') and s.endswith('}')) or \
                (s.startswith('[') and s.endswith(']')):  # detect if json
            return json_loads(s)
    return s
Example #11
0
    def __call__(self):
        self.errors = []
        self.protect()
        context = aq_inner(self.context)

        torename = json_loads(self.request.form['torename'])

        catalog = getToolByName(context, 'portal_catalog')
        mtool = getToolByName(context, 'portal_membership')

        missing = []
        for data in torename:
            uid = data['UID']
            brains = catalog(UID=uid)
            if len(brains) == 0:
                missing.append(uid)
                continue
            obj = brains[0].getObject()
            title = self.objectTitle(obj)
            if not mtool.checkPermission('Copy or Move', obj):
                self.errors(_(u'Permission denied to rename ${title}.',
                              mapping={u'title': title}))
                continue

            sp = transaction.savepoint(optimistic=True)

            newid = data['newid'].encode('utf8')
            newtitle = data['newtitle']
            try:
                obid = obj.getId()
                title = obj.Title()
                change_title = newtitle and title != newtitle
                if change_title:
                    getSecurityManager().validate(obj, obj, 'setTitle',
                                                  obj.setTitle)
                    obj.setTitle(newtitle)
                    notify(ObjectModifiedEvent(obj))
                if newid and obid != newid:
                    parent = aq_parent(aq_inner(obj))
                    # Make sure newid is safe
                    newid = INameChooser(parent).chooseName(newid, obj)
                    # Update the default_page on the parent.
                    context_state = getMultiAdapter(
                        (obj, self.request), name='plone_context_state')
                    if context_state.is_default_page():
                        parent.setDefaultPage(newid)
                    parent.manage_renameObjects((obid, ), (newid, ))
                elif change_title:
                    # the rename will have already triggered a reindex
                    obj.reindexObject()
            except ConflictError:
                raise
            except Exception:
                sp.rollback()
                self.errors.append(_('Error renaming ${title}', mapping={
                    'title': title}))

        return self.message(missing)
Example #12
0
    def __call__(self):
        """ If the 'resultsonly' parameter is in the request then extract the
        value for "results" from the JSON string returned from the default
        @@getVocabulary view, so that it can be used by pat-autosuggest.

        @@getVocabulary also uses the vocabulary item 'token' value for the
        'id', which escapes unicode strings. For pat-autosuggest we need to use
        unicode for both the 'text' and the 'id'.
        """
        vocab_json = super(PersonalizedVocabularyView, self).__call__()
        if vocab_json and self.request.get('resultsonly', False):
            vocab_obj = json_loads(vocab_json)
            results = vocab_obj.get('results', [])
            text_values = [i['text'] for i in results]
            vocab_list = [{'text': val, 'id': val} for val in text_values]
            return json_dumps(vocab_list)

        return vocab_json
Example #13
0
    def __call__(self):
        """ If the 'resultsonly' parameter is in the request then extract the
        value for "results" from the JSON string returned from the default
        @@getVocabulary view, so that it can be used by pat-autosuggest.

        @@getVocabulary also uses the vocabulary item 'token' value for the
        'id', which escapes unicode strings. For pat-autosuggest we need to use
        unicode for both the 'text' and the 'id'.
        """
        vocab_json = super(PersonalizedVocabularyView, self).__call__()
        if vocab_json and self.request.get('resultsonly', False):
            vocab_obj = json_loads(vocab_json)
            results = vocab_obj.get('results', [])
            text_values = [i['text'] for i in results]
            vocab_list = [{'text': val, 'id': val} for val in text_values]
            return json_dumps(vocab_list)

        return vocab_json
Example #14
0
    def __call__(self):
        self.errors = []
        self.protect()
        id = self.request.form.get("id")
        ordering = self.getOrdering()
        delta = self.request.form["delta"]
        subset_ids = json_loads(self.request.form.get("subset_ids", "[]"))
        if delta == "top":
            ordering.moveObjectsToTop([id])
        elif delta == "bottom":
            ordering.moveObjectsToBottom([id])
        else:
            delta = int(delta)
            if subset_ids:
                position_id = [(ordering.getObjectPosition(i), i) for i in subset_ids]
                position_id.sort()
                if subset_ids != [i for position, i in position_id]:
                    self.errors.append(_("Client/server ordering mismatch"))
                    return self.message()

            ordering.moveObjectsByDelta([id], delta)
        return self.message()
Example #15
0
 def get_selection(self):
     selection = self.request.form.get('selection', '[]')
     return json_loads(selection)
Example #16
0
 def get_selection(self):
     selection = self.request.form.get("selection", "[]")
     return json_loads(selection)
Example #17
0
 def __call__(self):
     self.remove = set([v.encode("utf8") for v in json_loads(self.request.form.get("remove"))])
     self.add = set([v.encode("utf8") for v in json_loads(self.request.form.get("add"))])
     return super(TagsAction, self).__call__()
Example #18
0
 def get_selection(self):
     selection = self.request.form.get('selection', '[]')
     return json_loads(selection)
Example #19
0
def _parseJSON(s):
    if isinstance(s, basestring):
        s = s.strip()
        if (s.startswith("{") and s.endswith("}")) or (s.startswith("[") and s.endswith("]")):  # detect if json
            return json_loads(s)
    return s
Example #20
0
 def __call__(self):
     self.remove = set([v.encode('utf8') for v in
                        json_loads(self.request.form.get('remove'))])
     self.add = set([v.encode('utf8') for v in
                     json_loads(self.request.form.get('add'))])
     return super(TagsAction, self).__call__()