Exemplo n.º 1
0
    def label(self):
        if not all((self.person, self.tile)):
            return _(u'Edit role')

        return _(u'Edit role of ${organization} / ${person}',
                 mapping={
                     'person': api.content.get(UID=self.person).title,
                     'organization': self.context.title
                 })
Exemplo n.º 2
0
class IMemberListTile(IPersistentCoverTile):

    uuids = schema.List(title=_(u'Members'),
                        value_type=schema.TextLine(),
                        required=False)

    is_memberlist_tile = schema.Bool(required=False)

    roles = schema.Dict(title=_(u'Roles'),
                        key_type=schema.TextLine(),
                        value_type=schema.TextLine())

    title = schema.TextLine(title=_(u'Title'), required=False)
Exemplo n.º 3
0
class TileTitleEditForm(TileEditForm):
    """ From to edit the role of a member in an organization. """
    
    grok.name('edit-title')
    schema = ITileTitleEditForm
    label = _(u'Edit title')

    @property
    def title(self):
        title = self.parameter('title')
        if title is not None:
            return title
        else:
            return self.load_title()

    def load_title(self):
        if not self.tile:
            return u''

        return (self.get_tile_data().get('title') or _(u'Members'))

    def save_title(self):
        assert self.tile, """
            Only call when tile is available.
        """
        
        data = self.get_tile_data()
        data['title'] = self.title
        self.set_tile_data(data)

        notify(ObjectModifiedEvent(self.context))

    @button.buttonAndHandler(_(u'Save'))
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        self.save_title()
        self.request.response.redirect(self.redirect_url)

    @button.buttonAndHandler(_(u'Cancel'))
    def handleCancel(self, action):
        self.request.response.redirect(self.redirect_url)
Exemplo n.º 4
0
class MemberListTile(ListTile):

    implements(IPersistentCoverTile)
    index = ViewPageTemplateFile('templates/list.pt')

    is_editable = False
    is_configurable = True

    short_name = _(u'Memberlist')
    limit = 1000

    def translate(self, text):
        return tools.translator(self.request, 'seantis.cover.people')(text)

    @contextmanager
    def change_data(self):
        data_mgr = ITileDataManager(self)
        data = data_mgr.get()
        yield data
        data_mgr.set(data)

    def get_title(self):
        title = self.data.get('title')
        title = title if title is not None else _(u'Members')
        return self.translate(title)

    def set_title(self, title):
        with self.change_data() as data:
            data['title'] = title

    def get_role(self, uuid):
        roles = self.data.get('roles') or {}
        return roles.get(uuid, u'')

    def set_role(self, uuid, role):
        with self.change_data() as data:
            data['roles'] = data.get('roles') or {}
            data['roles'][uuid] = role

    def populate_with_object(self, obj):
        super(MemberListTile, self).populate_with_object(obj)
        notify(ObjectModifiedEvent(obj))

    def remove_item(self, uuid):
        super(MemberListTile, self).remove_item(uuid)

        with self.change_data() as data:
            if uuid in data['roles']:
                del data['roles'][uuid]

        notify(ObjectModifiedEvent(api.content.get(UID=uuid)))

    def accepted_ct(self):
        return [
            fti.id
            for fti in tools.get_type_info_by_behavior(IPerson.__identifier__)
        ]
Exemplo n.º 5
0
class TileRoleEditForm(TileEditForm):
    """ From to edit the role of a member in an organization. """

    grok.name('edit-role')
    schema = ITileRoleEditForm

    @property
    def label(self):
        if not all((self.person, self.tile)):
            return _(u'Edit role')

        return _(u'Edit role of ${organization} / ${person}',
                 mapping={
                     'person': api.content.get(UID=self.person).title,
                     'organization': self.context.title
                 })

    @property
    def person(self):
        return self.parameter('person')

    @property
    def role(self):
        role = self.parameter('role')

        if role is not None:
            return role
        else:
            return self.load_role()

    def load_role(self):
        if not all((self.tile, self.person)):
            return u''

        return (self.get_tile_data().get('roles') or {}).get(self.person, u'')

    def save_role(self):
        assert all((self.tile, self.person)), """
            Only call when tile and person are available.
        """

        # load person to ensure validity of uuid
        person = api.content.get(UID=self.person)

        data = self.get_tile_data()
        data['roles'] = data.get('roles') or {}
        data['roles'][self.person] = self.role

        self.set_tile_data(data)

        # notify both ends as they might rely on the role data
        notify(ObjectModifiedEvent(self.context))
        notify(MembershipChangedEvent(person))

    @button.buttonAndHandler(_(u'Save'))
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        self.save_role()
        self.request.response.redirect(self.redirect_url)

    @button.buttonAndHandler(_(u'Cancel'))
    def handleCancel(self, action):
        self.request.response.redirect(self.redirect_url)
Exemplo n.º 6
0
class ITileRoleEditForm(ITileEditForm):

    form.mode(person='hidden')
    person = schema.TextLine(title=u'Person UUID', )

    role = schema.TextLine(title=_(u'Role'), required=False)
Exemplo n.º 7
0
    def load_title(self):
        if not self.tile:
            return u''

        return (self.get_tile_data().get('title') or _(u'Members'))
Exemplo n.º 8
0
class ITileTitleEditForm(ITileEditForm):

    title = schema.TextLine(
        title=_(u'Title'),
        required=False
    )
Exemplo n.º 9
0
 def get_title(self):
     title = self.data.get('title')
     title = title if title is not None else _(u'Members')
     return self.translate(title)
Exemplo n.º 10
0
 def get_title(self):
     title = self.data.get('title')
     title = title if title is not None else _(u'Members')
     return self.translate(title)