def migrate_ratings(self):

        """
        contentratings and twothumbs both use annotations. Just want to move
        one to another. Here we say anything >= 3 rating is a thumbs up
        """

        from cioppino.twothumbs import rate as thumbrate

        transaction.begin()
        item = self.obj
        annotations = IAnnotations(item)
        if annotations:
            if 'contentratings.userrating.psc_stars' in annotations:
                ratings = annotations['contentratings.userrating.psc_stars'].all_user_ratings()
                annotations = thumbrate.setupAnnotations(item)
                for rating in ratings:

                    if rating >= 3.0:
                        thumbrate.loveIt(item, rating.userid)
                    else:
                        thumbrate.hateIt(item, rating.userid)

        # we need to reindex th object anyways
        item.reindexObject()
        transaction.commit()
    def migrate_ratings(self):
        """
        contentratings and twothumbs both use annotations. Just want to move
        one to another. Here we say anything >= 3 rating is a thumbs up
        """

        from cioppino.twothumbs import rate as thumbrate

        transaction.begin()
        item = self.obj
        annotations = IAnnotations(item)
        if annotations:
            if 'contentratings.userrating.psc_stars' in annotations:
                ratings = annotations[
                    'contentratings.userrating.psc_stars'].all_user_ratings()
                annotations = thumbrate.setupAnnotations(item)
                for rating in ratings:

                    if rating >= 3.0:
                        thumbrate.loveIt(item, rating.userid)
                    else:
                        thumbrate.hateIt(item, rating.userid)

        # we need to reindex th object anyways
        item.reindexObject()
        transaction.commit()
Пример #3
0
    def __call__(self, REQUEST, RESPONSE):
        form = self.request.form
        if form.get('form.lovinit', False):
            rate.loveIt(self.context)
        elif form.get('form.hatedit', False):
            rate.hateIt(self.context)
        else:
            return _(u"We don't like ambiguity around here. Check yo self before you wreck yo self.")

        tally = rate.getTally(self.context)
        RESPONSE.setHeader('Content-Type', 'application/javascript')
        return json.dumps(tally)
Пример #4
0
    def send_request(self, data):
        user = self.create_user(data)
        if data["vote"] == "FOR":
            for project in data["project"]:
                context = api.content.find(UID=project)[0].getObject()
                setupAnnotations(context)
                loveIt(context, userid=user.id)
        else:
            for project in data["project"]:
                context = api.content.find(UID=project)[0].getObject()
                setupAnnotations(context)
                hateIt(context, userid=user.id)

        self.request.response.redirect("{0}/@@vote_encoding".format(
            self.context.absolute_url()))
Пример #5
0
def add_project(
    container,
    project_id,
    title,
    project_theme,
    project_body,
    image_source,
    project_author,
    project_like,
    project_unlike,
    project_status,
):
    img_extensions = ("jpg", "png", "gif")
    with api.env.adopt_user(username="******"):
        project = api.content.create(
            type="Project",
            title=title,
            project_theme=project_theme,
            body=u"<br>".join(project_body.decode("utf8").splitlines()),
            container=container,
            original_author=project_author,
            original_id=project_id,
        )
        for ext in img_extensions:
            filename = "{0}.{1}".format(project_id, ext)
            img_path = os.path.join(image_source, filename)
            if os.path.exists(img_path):
                add_image_from_file(project, filename, image_source)
                break

    rate.setupAnnotations(project)
    if project_like:
        for x in range(0, int(project_like)):
            rate.loveIt(project, "userimportp" + str(x))
    if project_unlike:
        for x in range(0, int(project_unlike)):
            rate.hateIt(project, "userimportn" + str(x))

    with api.env.adopt_user(username="******"):
        if project_status in ["selected", "rejected"]:
            api.content.transition(obj=project, transition="deposit")
            api.content.transition(obj=project, transition="to_be_analysed")
            api.content.transition(obj=project, transition="vote")
            api.content.transition(obj=project, transition="vote_analysis")
            if project_status == "selected":
                api.content.transition(obj=project, transition="accept")
            else:
                api.content.transition(obj=project, transition="reject")
Пример #6
0
def add_project(
    container,
    project_id,
    title,
    project_theme,
    project_body,
    image_source,
    project_author,
    project_like,
    project_unlike,
    project_status,
):
    img_extensions = ("jpg", "png", "gif")
    with api.env.adopt_user(username="******"):
        project = api.content.create(
            type="Project",
            title=title,
            project_theme=project_theme,
            body=u"<br>".join(project_body.decode("utf8").splitlines()),
            container=container,
            original_author=project_author,
            original_id=project_id,
        )
        for ext in img_extensions:
            filename = "{0}.{1}".format(project_id, ext)
            img_path = os.path.join(image_source, filename)
            if os.path.exists(img_path):
                add_image_from_file(project, filename, image_source)
                break

    rate.setupAnnotations(project)
    if project_like:
        for x in range(0, int(project_like)):
            rate.loveIt(project, "userimportp" + str(x))
    if project_unlike:
        for x in range(0, int(project_unlike)):
            rate.hateIt(project, "userimportn" + str(x))

    with api.env.adopt_user(username="******"):
        if project_status in ["selected", "rejected"]:
            api.content.transition(obj=project, transition="deposit")
            api.content.transition(obj=project, transition="to_be_analysed")
            api.content.transition(obj=project, transition="vote")
            api.content.transition(obj=project, transition="vote_analysis")
            if project_status == "selected":
                api.content.transition(obj=project, transition="accept")
            else:
                api.content.transition(obj=project, transition="reject")
Пример #7
0
    def __call__(self, REQUEST, RESPONSE):
        form = self.request.form
        if form.get('form.lovinit', False):
            rate.loveIt(self.context)
            # vipod: additionally re-index a few more indexes
            self.context.reindexObject(idxs=['avg_ratings',
                'total_down_ratings'])
        elif form.get('form.hatedit', False):
            rate.hateIt(self.context)
            # vipod: additionally re-index a few more indexes
            self.context.reindexObject(idxs=['avg_ratings',
                'total_down_ratings'])
        else:
            return _(u"We don't like ambiguity around here. "
                     "Check yo self before you wreck yo self.")

        tally = rate.getTally(self.context)
        RESPONSE.setHeader('Content-Type', 'application/javascript')
        return json.dumps(tally)
Пример #8
0
    def __call__(self, REQUEST, RESPONSE):
        registry = getUtility(IRegistry)
        anonuid = None
        anonymous_voting = registry.get('cioppino.twothumbs.anonymousvoting', False)
        portal_state = getMultiAdapter((self.context, self.request),
                                       name='plone_portal_state')

        if portal_state.anonymous():
            if not anonymous_voting:
                return RESPONSE.redirect('%s/login?came_from=%s' %
                                         (portal_state.portal_url(),
                                          REQUEST['HTTP_REFERER'])
                                         )
            else:
                anonuid = self.request.cookies.get(COOKIENAME, None)
                if anonuid is None:
                    anonuid = str(uuid4())
                    RESPONSE.setCookie(COOKIENAME, anonuid)

        form = self.request.form
        action = None
        if form.get('form.lovinit', False):
            action = rate.loveIt(self.context, userid=anonuid)
        elif form.get('form.hatedit', False):
            action = rate.hateIt(self.context, userid=anonuid)
        else:
            return _(u"We don't like ambiguity around here. Check yo self "
                     "before you wreck yo self.")

        if not form.get('ajax', False):
            return RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        else:
            tally = rate.getTally(self.context)
            tally['action'] = action

            # Create handy translate function
            translate = self._get_translator()
            ltool = getToolByName(self, 'portal_languages')
            target_language = ltool.getPreferredLanguage()

            tally['msg'] = translate(
                self._getMessage(action),
                target_language=target_language
            )
            tally['close'] = translate(
                _(u"Close"),
                target_language=target_language
            )

            RESPONSE.setHeader('Content-Type',
                               'application/json; charset=utf-8')
            response_json = json.dumps(tally)
            RESPONSE.setHeader('content-length', len(response_json))
            return response_json
Пример #9
0
    def __call__(self, REQUEST, RESPONSE):
        registry = getUtility(IRegistry)
        anonuid = None
        anonymous_voting = registry.get('cioppino.twothumbs.anonymousvoting',
                                        False)
        portal_state = getMultiAdapter((self.context, self.request),
                                       name='plone_portal_state')

        if portal_state.anonymous():
            if not anonymous_voting:
                return RESPONSE.redirect(
                    '%s/login?came_from=%s' %
                    (portal_state.portal_url(), REQUEST['HTTP_REFERER']))
            else:
                anonuid = self.request.cookies.get(COOKIENAME, None)
                if anonuid is None:
                    anonuid = str(uuid4())
                    RESPONSE.setCookie(COOKIENAME, anonuid)

        form = self.request.form
        action = None
        if form.get('form.lovinit', False):
            action = rate.loveIt(self.context, userid=anonuid)
        elif form.get('form.hatedit', False):
            action = rate.hateIt(self.context, userid=anonuid)
        else:
            return _(u"We don't like ambiguity around here. Check yo self "
                     "before you wreck yo self.")

        if not form.get('ajax', False):
            return RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        else:
            tally = rate.getTally(self.context)
            tally['action'] = action

            # Create handy translate function
            translate = self._get_translator()
            ltool = getToolByName(self, 'portal_languages')
            target_language = ltool.getPreferredLanguage()

            tally['msg'] = translate(self._getMessage(action),
                                     target_language=target_language)
            tally['close'] = translate(_(u"Close"),
                                       target_language=target_language)

            RESPONSE.setHeader('Content-Type',
                               'application/json; charset=utf-8')
            response_json = json.dumps(tally)
            RESPONSE.setHeader('content-length', len(response_json))
            return response_json
Пример #10
0
    def __call__(self, REQUEST, RESPONSE):

        # First check if the user is allowed to rate
        portal_state = getMultiAdapter((self.context, self.request),
                                       name='plone_portal_state')
        if portal_state.anonymous():
            return RESPONSE.redirect('%s/login?came_from=%s' % (portal_state.portal_url(), REQUEST['HTTP_REFERER']))


        form = self.request.form
        action = None
        if form.get('form.lovinit', False):
            action = rate.loveIt(self.context)
        elif form.get('form.hatedit', False):
            action = rate.hateIt(self.context)
        else:
            return _(u"We don't like ambiguity around here. Check yo self before you wreck yo self.")

        if not form.get('ajax', False):
            return RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        else:
            tally = rate.getTally(self.context)
            tally['action'] = action

            # Create handy translate function
            td = queryUtility(ITranslationDomain, name='cioppino.twothumbs')
            if td:
                tx = td.translate
            else:
                # Workaround for non-registered translation domain to prevent breaking
                def tx(msgid, target_language=None):
                    return msgid

            ltool = getToolByName(self, 'portal_languages')
            target_language = ltool.getPreferredLanguage()

            if(action=='like'):
                tally['msg'] = tx(_(u"You liked this. Thanks for the feedback!"), target_language=target_language)
            elif(action=='dislike'):
                tally['msg'] = tx(_(u"You dislike this. Thanks for the feedback!"), target_language=target_language)
            elif(action=='undo'):
                tally['msg'] = tx(_(u"Your vote has been removed."), target_language=target_language)

            tally['close'] = tx(_(u"Close"), target_language=target_language)
            
            RESPONSE.setHeader('Content-Type', 'application/json; charset=utf-8')
            response_json = json.dumps(tally)
            RESPONSE.setHeader('content-length', len(response_json))
            return response_json
Пример #11
0
def contextThumbs(context, event):
    if not ILoveThumbsDontYou.providedBy(context):
        alsoProvides(context, ILoveThumbsDontYou)
        rate.setupAnnotations(context)
        rate.hateIt(context)
        context.reindexObject()
Пример #12
0
 def doIt(self):
     action = rate.hateIt(self.context)
     if action == "dislike":
         self.message = _(u"You dislike this. Thanks for the feedback!")
     else:
         self.message = _(u"Your vote has been removed.")