예제 #1
0
 def handleAdd(self, action):
     data, errors = self.extractData()
     if errors:
         return
     self.hlite.addGroup(data)
     self.context.plone_utils.addPortalMessage(_('Group successfully added.'))
     self.request.RESPONSE.redirect(self.context.absolute_url())
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        if data['selected_group']:
            self.group_obj = self.hlite[data['selected_group']]
            content = self.getContent()
            del data['selected_group']
            changes = form.applyChanges(self, content, data)
            if self.group_obj.id not in self.highlights:
                self.highlights[self.group_obj.id] = content
                interface.alsoProvides(self.context, IHighlighted)
            if changes:
                content.author = getActiveUser()
                self.context.reindexObject(idxs=['object_provides',
                                                 'hlite_groups'])
                self.status = self.successMessage
                self.refreshActions = True
                self.updateWidgets()
            else:
                self.status = self.noChangesMessage
        else:
            self.status = _(u'Please select a group.')
 def handleDelete(self, action):
     data, errors = self.extractData()
     if data['selected_group']:
         self.group_obj = self.hlite[data['selected_group']]
         self.group_obj.removeItem(obj=self.context)
         self.updateWidgets()
         self.status = self.successMessage
         self.refreshActions = True
     else:
         self.status = _(u'Please select a group.')
예제 #4
0

class GroupMembersEditForm(crud.EditForm):
    label = _(u"Highlighted items")


class GroupMembersForm(crud.CrudForm):
    """View list of items assigned to a group and allows for deletion"""

    addform_factory = crud.NullForm
    editform_factory = GroupMembersEditForm
    view_schema = IGroupMember

    def get_items(self):
        group = self.context.id
        return [(hl.UID, GroupMember(hl, group)) for hl in
                self.context.getContentItems()]

    def remove(self, (id, item)):
        self.context.removeItem(id)

    def link(self, item, field):
        if field == 'title':
            return item.url + '/@@highlight?group=%s' % self.context.id

GroupMembers = layout.wrap_form(
    GroupMembersForm,
    index=ViewPageTemplateFile('templates/form_layout.pt'),
    label=_(u"Group members"),
    back_link=back_to_highlightsmanager)
 def handleSelect(self, action):
     data, errors = self.extractData()
     self.group = data['group']
     self.status = _(u'Group selected')
     self.updateWidgets()
 def handle_delete(self, action):
     self.status = _(u"Please select items to remove.")
     selected = self.selected_items()
     if selected:
         self.status = _(u"Successfully removed categories.")
         self.highlights_manager.deleteGroups([id for id, gr_o in selected])
def back_to_highlightsmanager(self):
    root = getSite()
    return dict(label=_(u"Up to Highlights Manager Configuration"),
                url=root.absolute_url() + '/highlights_manager')
def back_to_controlpanel(self):
    root = getSite()
    return dict(label=_(u"Up to Site Setup"),
                url=root.absolute_url() + '/plone_control_panel')
        if selected:
            self.status = _(u"Successfully removed categories.")
            self.highlights_manager.deleteGroups([id for id, gr_o in selected])

class GroupOverviewForm(crud.CrudForm):
    """View list of groups and allow for deletion and addition."""
    
    addform_factory = crud.NullForm
    editform_factory = EditForm
    view_schema = IGroupOverview

    def __init__(self, *args, **kwargs):
        super(GroupOverviewForm, self).__init__(*args, **kwargs)
        self.highlights_manager = getToolByName(self.context, 'highlights_manager')
        
    def get_items(self):
        return [(group_id, GroupOverview(group))
                for group_id, group in self.highlights_manager.getAllGroups()]

    def remove(self, (id, item)):
        self.highlights_manager.deleteGroups([id])
    
    def link(self, item, field):
        if field == 'title':
            return '%s/edit' % item.group.absolute_url()

GroupsOverview = layout.wrap_form(
    GroupOverviewForm,
    index=ViewPageTemplateFile('templates/controlpanel.pt'),
    label = _(u"Highlights Manager: Groups Overview"),
    back_link=back_to_controlpanel)
from zope import interface, component
from zope.annotation.interfaces import IAnnotations
from plone.indexer.decorator import indexer

from collective.highlights.manager.interfaces import IHighlightable
from collective.highlights.manager.interfaces import IHighlightDataStorage
from collective.highlights.manager.interfaces import IHighlighted
from collective.highlights.manager.storage import HighlightData
from collective.highlights.manager.storage import HighlightDataStorage
from collective.highlights.manager.config import HLITE_ANNO_KEY
from collective.highlights.manager import MessageFactory as _


HighlightDataFactory = component.factory.Factory(HighlightData,
                                          _('Default HighlightData Factory'))


@component.adapter(IHighlightable)
@interface.implementer(IHighlightDataStorage)
def getHighlightDataStorage(context):
    annotations = IAnnotations(context)
    mapping = annotations.get(HLITE_ANNO_KEY, None)
    if mapping is None:
        mapping = annotations[HLITE_ANNO_KEY] = HighlightDataStorage()
    return mapping


@indexer(IHighlighted)
def hlite_groups(object):
    return IHighlightDataStorage(object).keys()