コード例 #1
0
 def get_member_vote(self, object):
     """ """
     if not IAttributeAnnotatable.providedBy(object):
         alsoProvides(object, IAttributeAnnotatable)
     annotations = IAnnotations(object)
     voters = annotations.get('opkode.rateablediscussion.voters', {})
     return voters.get(self.member.getId(), None)
コード例 #2
0
    def downvote(self, path):
        """ """
        user_rating = None
        s = getSite()
        rpath = '/'.join(s.getPhysicalPath()) + path.replace(s.absolute_url(), '')
        reply = self.context.restrictedTraverse(rpath)
        if not IAttributeAnnotatable.providedBy(reply):
            alsoProvides(reply, IAttributeAnnotatable)
        annotations = IAnnotations(reply)
        voters = annotations.get('opkode.rateablediscussion.voters', {})
        rating = annotations.get('opkode.rateablediscussion.rating', 0)
        pm = getToolByName(s, 'portal_membership')
        if pm.isAnonymousUser():
            return 
        pm = getToolByName(s, 'portal_membership')
        member = pm.getAuthenticatedMember()
        member_id = member.getId()
        if member_id not in voters:
            voters[member_id] = 'down'
            user_rating = 'down'
            annotations['opkode.rateablediscussion.voters'] = voters
            rating -= 1
            annotations['opkode.rateablediscussion.rating'] = rating
        elif voters.get(member_id) == 'up':
            # The voter is removing his vote, so let's delete him
            del voters[member_id]
            annotations['opkode.rateablediscussion.voters'] = voters
            rating -= 1
            annotations['opkode.rateablediscussion.rating'] = rating
        elif voters.get(member_id) == 'down':
            # The down arrow has already been clicked before
            user_rating = 'down'

        return json.dumps(
                    {'reply_rating': rating, 'user_rating':user_rating})
コード例 #3
0
def _children_all(tree, debug=False):
    """returns a list of every child"""

    objects = [o for o in tree.objectValues() if IPersistent.providedBy(o)]

    child_list = []
    to_crawl = deque(objects)

    i = 0
    while to_crawl:
        current = to_crawl.popleft()
        child_list.append(current)
        #print "Looking at ", current.absolute_url()
        print ".",

        if IFolder.providedBy(current):
            node_children = [o for o in current.objectValues() if \
                    IAttributeAnnotatable.providedBy(o) and is_ok(o.getId())]
            to_crawl.extend(node_children)

        i += 1
        if debug and (i > 1000):
            break

    return child_list
コード例 #4
0
 def registry(self):
     context = self.context
     if not IAttributeAnnotatable.providedBy(context):
         interface.alsoProvides(self.context, IAttributeAnnotatable)
     annotations = IAnnotations(self.context)
     if not KEY in annotations:
         annotations[KEY] = PersistentDict()
     return annotations[KEY]
コード例 #5
0
def initial_rating(obj, event):
    """ Give the comment creator an inital vote of +1 for the comment.
    """
    s = getSite()
    if not IAttributeAnnotatable.providedBy(obj):
        alsoProvides(obj, IAttributeAnnotatable)
    annotations = IAnnotations(obj)
    pm = getToolByName(s, 'portal_membership')
    member = pm.getAuthenticatedMember()
    annotations['opkode.rateablediscussion.voters'] = {member.getId(): 'up'}
    annotations['opkode.rateablediscussion.rating'] = 1
コード例 #6
0
ファイル: views.py プロジェクト: jean/collective.isotope
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        assert IAttributeAnnotatable.providedBy(self.context)
        annotations = IAnnotations(self.context)
        annotations[ISOTOPE_CONFIGURATION_KEY] = data

        self.request.response.redirect(self.context.absolute_url())
        messages = IStatusMessage(self.request)
        messages.add(_(u"Your configuration has been saved"), type=u"info")
コード例 #7
0
    def handleApply(self, action):
        data, errors = self.extractData()

        if errors:
            self.status = self.formErrorsMessage
            return

        assert IAttributeAnnotatable.providedBy(self.context)
        annotations = IAnnotations(self.context)
        annotations[STYLESHEET_SELECTED_KEY] = data['style']

        self.request.response.redirect(self.context.absolute_url())
        messages = IStatusMessage(self.request)
        messages.add(_(u"Citation style set: ") + data['style'], type=u"info")
コード例 #8
0
ファイル: contenthandler.py プロジェクト: a25kk/stv2
    def apply(self, contentNode):
        if not IAttributeAnnotatable.providedBy(self.context):
            directly = interface.directlyProvidedBy(self.context)
            interface.directlyProvides(self.context,
                                            directly + IAttributeAnnotatable)
        annotations = IAnnotations(self.context)
        metadata = annotations.get(self.ANNO_KEY, None)
        if metadata is None:
            metadata = PersistentDict()
            annotations[self.ANNO_KEY] = metadata

        for dl_el in contentNode.childNodes:
            if dl_el.nodeName != 'dl':
                continue

            term = None
            for el in dl_el.childNodes:
                if el.nodeName == 'dt':
                    term = self._extractText(el)
                elif el.nodeName == 'dd':
                    definition = self._extractText(el)
                    metadata[term] = definition
コード例 #9
0
    def apply(self, contentNode):
        if not IAttributeAnnotatable.providedBy(self.context):
            directly = interface.directlyProvidedBy(self.context)
            interface.directlyProvides(self.context,
                                       directly + IAttributeAnnotatable)
        annotations = IAnnotations(self.context)
        metadata = annotations.get(self.ANNO_KEY, None)
        if metadata is None:
            metadata = PersistentDict()
            annotations[self.ANNO_KEY] = metadata

        for dl_el in contentNode.childNodes:
            if dl_el.nodeName != 'dl':
                continue

            term = None
            for el in dl_el.childNodes:
                if el.nodeName == 'dt':
                    term = self._extractText(el)
                elif el.nodeName == 'dd':
                    definition = self._extractText(el)
                    metadata[term] = definition
コード例 #10
0
 def get_rating(self, object):
     """ """
     if not IAttributeAnnotatable.providedBy(object):
         alsoProvides(object, IAttributeAnnotatable)
     annotations = IAnnotations(object)
     return annotations.get('opkode.rateablediscussion.rating', 0)
コード例 #11
0
 def wrapper(self, *a, **kw):
     if not IAttributeAnnotatable.providedBy(self.queue):
         alsoProvides(
             self.queue,
             IAttributeAnnotatable)
     return func(self, *a, **kw)