Beispiel #1
0
class Group(Content, LocalRolesMixin, ContextACLMixin):
    type_name = u"Group"
    type_title = _(u"Group")
    add_permission = "Add %s" % type_name
    title = u""
    description = u""
    css_icon = "glyphicon glyphicon-user" #FIXME no group icon!?

    def __init__(self, **kwargs):
        #Things like created, creator etc...
        super(Group, self).__init__()
        self.__members__ = OOSet()
        self.update(event = False, **kwargs)

    @property
    def principal_name(self):
        """ The way the security system likes to check names
            to avoid collisions with userids.
        """
        return u"group:%s" % self.__name__

    @property
    def members(self):
        return self.__members__

    @members.setter
    def members(self, value):
        self.__members__.clear()
        self.__members__.update(value)
Beispiel #2
0
class Group(Content, LocalRolesMixin, ContextACLMixin):
    type_name = u"Group"
    type_title = _(u"Group")
    add_permission = "Add %s" % type_name
    title = u""
    description = u""
    icon = u"user"  #FIXME no group icon!?

    def __init__(self, **kwargs):
        #Things like created, creator etc...
        super(Group, self).__init__()
        self.__members__ = OOSet()
        self.update(event=False, **kwargs)

    @property
    def principal_name(self):
        """ The way the security system likes to check names
            to avoid collisions with userids.
        """
        return u"group:%s" % self.__name__

    @property
    def members(self):
        return self.__members__

    @members.setter
    def members(self, value):
        self.__members__.clear()
        self.__members__.update(value)
Beispiel #3
0
class Content(Base, Folder):
    title = ""
    description = ""
    default_view = u"view"
    delegate_view = None
    nav_visible = True
    nav_title = None
    listing_visible = True
    search_visible = True
    show_byline = False
    custom_addable = False

    def __init__(self, **kw):
        #To set that this should keep track of ordering. See Folder
        #If _order is set to None, ordering isn't stored
        self._order = ()
        Folder.__init__(self)
        super(Content, self).__init__(**kw)

    def get_nav_title(self):
        nav_title = getattr(self, 'nav_title', None)
        if nav_title:
            return nav_title
        title = getattr(self, 'title', '')
        return title and title or self.__name__

    @property
    def tags(self): return getattr(self, '__tags__', ())
    @tags.setter
    def tags(self, value):
        #Is this the right way to mutate objects, or should we simply clear the contents?
        if value:
            self.__tags__ = OOSet(value)
        else:
            if hasattr(self, '__tags__'):
                delattr(self, '__tags__')

    @property
    def custom_addable_types(self):
        return frozenset(getattr(self, '_custom_addable_types', ()))
    @custom_addable_types.setter
    def custom_addable_types(self, value):
        if not hasattr(self, '_custom_addable_types'):
            self._custom_addable_types = OOSet(value)
        if set(value) != set(self._custom_addable_types):
            self._custom_addable_types.clear()
            self._custom_addable_types.update(value)
    @custom_addable_types.deleter
    def custom_addable_types(self):
        if hasattr(self, '_custom_addable_types'):
            delattr(self, '_custom_addable_types')
Beispiel #4
0
class LangField(BaseField):
    """ Language sensitive field. """

    def __init__(self, key=None, main_lang = None, **kwargs):
        super(LangField, self).__init__(key=key, **kwargs)
        if not main_lang:
            request = get_current_request()
            main_lang = request.registry.settings.get('default_locale_name', 'en')
        self.main_lang = main_lang
        self.fuzzy = OOSet()
        self.__data__ = OOBTree()

    @property
    def langs(self):
        return set(self.__data__.keys())

    @property
    def translated(self):
        return self.langs - set([self.main_lang])

    def get(self, default=None, langs = None, **kwargs):
        if not langs:
            request = get_current_request()
            langs = (get_locale_name(request),)
        return dict((lang, self.__data__.get(lang, default)) for lang in langs)

    def set(self, value, **kwargs):
        if not isinstance(value, dict):
            raise TypeError("Must be a dict")
        updated = value.keys()
        main_updated = self.main_lang in updated
        for (lang, value) in value.items():
            self.__data__[lang] = value
            if lang in self.fuzzy:
                self.fuzzy.remove(lang)
        if main_updated:
            others = self.translated - set(updated)
            self.fuzzy.update(others)

    def remove(self, key):
        self.__data__.pop(key, None)
        if key in self.fuzzy:
            self.fuzzy.remove(key)

    def __len__(self):
        return len(self.__data__)
    def setTags(self, pid, oid, tags):
        self.removeTags(pid, oid)

        if not tags:
            return

        t = []
        for tag in tags:
            tag = tag.lower().strip()
            if tag:
                t.append(tag)
        if not t:
            return

        tags = t

        pdata = self.tags.get(pid)
        if pdata is None:
            pdata = IOBTree()
            self.tags[pid] = pdata

        oids = pdata.get(oid)
        if oids is None:
            oids = OOSet()
            pdata[oid] = oids

        oids.update(tags)

        # insert oid -> pid reference
        oids = self.oids.get(oid)
        if oids is None:
            oids = OOSet()
            self.oids[oid] = oids

        oids.insert(pid)

        #update tagging engine
        engine = self.getEngine(pid)
        try:
            engine.update(oid, tags)
        except:
            engine.clear()
            engine.update(oid, tags)
Beispiel #6
0
 def set_connection_oids(self, conn_id, oids):
     """Records the OIDs a connection is using and periodically scans.
     """
     changed = 0
     new_oids = OOSet()
     self.lock.acquire()
     try:
         if oids:
             self.conn_oids[conn_id] = OOSet(oids)
         else:
             if self.conn_oids.has_key(conn_id):
                 del self.conn_oids[conn_id]
         for set in self.conn_oids.values():
             new_oids.update(set)
         if self.oids != new_oids:
             self.oids = new_oids
             changed = 1
     finally:
         self.lock.release()
     if changed:
         self.storage.scanner.set_oids(new_oids)
Beispiel #7
0
 def set_connection_oids(self, conn_id, oids):
     """Records the OIDs a connection is using and periodically scans.
     """
     changed = 0
     new_oids = OOSet()
     self.lock.acquire()
     try:
         if oids:
             self.conn_oids[conn_id] = OOSet(oids)
         else:
             if self.conn_oids.has_key(conn_id):
                 del self.conn_oids[conn_id]
         for set in self.conn_oids.values():
             new_oids.update(set)
         if self.oids != new_oids:
             self.oids = new_oids
             changed = 1
     finally:
         self.lock.release()
     if changed:
         self.storage.scanner.set_oids(new_oids)