Ejemplo n.º 1
0
class RatingRemover(object):
    """An adapter that adds the rating removal field"""
    adapts(IATDocument)
    implements(ISchemaExtender)

    fields = [
        ReverseInterfaceField(
            "allow_ratings",
            default=True,
            widget=BooleanWidget(
                label=_(u"Enable Ratings"),
                description=_(
                    'allow_ratings_help',
                    default=(u"Check this box to add ratings to this "
                             u"item. Use the control panel to select "
                             u"the ratings shown on each content type."))),
            schemata="settings"),
    ]

    def __init__(self, context):
        self.context = context

    def getFields(self):
        """If the product is installed, return our custom field"""
        if queryUtility(IRatingCategoryAssignment) is not None:
            return self.fields
        else:
            return []
Ejemplo n.º 2
0
class IPloneRatingCategory(IRatingCategory):
    """use a vocabulary for views"""

    view_name = Choice(title=_(u"View"),
                       description=_(u"Select the view for this category"),
                       vocabulary='plone.contentratings.rating_views',
                       required=True)
Ejemplo n.º 3
0
class IRatingBehavior(Schema):
    """ Allows enabling/disabling rating on individual items
    """
    fieldset('settings', label=_(u"Settings"), fields=['allow_ratings'])
    allow_ratings = Bool(title=_(u'Enable Ratings'),
                         description=_(u'Enable ratings on this content item'),
                         default=True)
    omitted('allow_ratings')
    no_omit(IEditForm, 'allow_ratings')
    no_omit(IAddForm, 'allow_ratings')
Ejemplo n.º 4
0
class ICategoryAssignment(Interface):

    portal_type = Choice(title=_(u"Portal Type"),
                         required=True,
                         vocabulary="plone.contentratings.portal_types")
    assigned_categories = Set(
        title=_(u"Categories"),
        value_type=Choice(title=_(u"Category"),
                          vocabulary="plone.contentratings.categories"),
        required=False)
Ejemplo n.º 5
0
class ICategoryContainer(Interface):

    local_categories = List(title=_(u"Local Categories"),
                            value_type=Object(IPloneRatingCategory,
                                              title=_(u"Category")),
                            required=False)

    acquired_categories = Tuple(title=_(u"Acquired Categories"),
                                value_type=Object(IPloneRatingCategory,
                                                  title=_(u"Category")),
                                readonly=True,
                                required=False)
Ejemplo n.º 6
0
class ContentRatingsControlPanel(ControlPanelForm):

    form_name = _(u"Category Assignments")

    actions = ControlPanelForm.actions.copy()

    label = _(u"Rating settings")
    description = _(u"Settings related to content ratings.")

    typespolicies['assignment'].custom_widget = AssignmentWidget

    categories['local_categories'].custom_widget = hr_categories_widget
    categories['acquired_categories'].custom_widget = display_categories_widget
    form_fields = FormFieldsets(typespolicies, categories)

    @form.action(_(u'Change Portal Type'), name=u'change_type')
    def change_type(self, action, data):
        """Does nothing except reload the form"""
        type_id = self.request.form['form.assignment.portal_type']
        self.request.form.clear()
        self.request.form['type_id'] = type_id
        return self()
Ejemplo n.º 7
0
        assignment = CategoryAssignment()
        assignment.portal_type = portal_type
        assignment.assigned_categories = set(selected_categories(portal_type))

        return assignment


def selected_categories(portal_type):
    assignments = getUtility(IRatingCategoryAssignment)
    return (t for t in assignments.categories_for_type(portal_type))


typespolicies = FormFieldsets(IEditCategoryAssignment)
typespolicies.id = 'types_categories'
typespolicies.label = _(u'Rating Assignments')
typespolicies.description = _(
    'typespolicies_description_help',
    default=u'Choose a portal type from the list and select '
    u'one or more rating categories to appear on that type.')
typespolicies.required = False

categories = FormFieldsets(ICategoryContainer)
categories.id = 'manage_categories'
categories.label = _(u'Manage Categories')
categories.description = _(
    'categories_description_help',
    default=u'Add, modify, or remove rating categories. You '
    u'may specify a title, description, conditions for viewing and setting '
    u'ratings, a view to display the rating, and a relative order number. '
    u'Categories which are defined at a lower level (e.g., globally) may not be '
Ejemplo n.º 8
0
            portal_type = list(vocab_factory(self.context.context.context))[0].token

        assignment = CategoryAssignment()
        assignment.portal_type = portal_type
        assignment.assigned_categories = set(selected_categories(portal_type))

        return assignment

def selected_categories(portal_type):
    assignments = getUtility(IRatingCategoryAssignment)
    return (t for t in assignments.categories_for_type(portal_type))


typespolicies = FormFieldsets(IEditCategoryAssignment)
typespolicies.id = 'types_categories'
typespolicies.label = _(u'Rating Assignments')
typespolicies.description = _(u'Choose a portal type from the list and select '
u'one or more rating categories to appear on that type. ')
typespolicies.required = False

categories = FormFieldsets(ICategoryContainer)
categories.id = 'manage_categories'
categories.label = _(u'Manage Categories')
categories.description = _(u'Add, modify, or remove rating categories.  You '
u'may specify a title, description, conditions for viewing and setting '
u'ratings, a view to display the rating, and a relative order number.  '
u'Categories which are defined at a lower level (e.g., globally) may not be '
u'edited. You need to save your changes after adding or removing categories')

categories.required = False
Ejemplo n.º 9
0
class IEditCategoryAssignment(Interface):

    assignment = Object(ICategoryAssignment,
                        title=_(u"Assignment"),
                        required=False)