Exemple #1
0
 def portalboxes_ln(self):
     """Get Portalboxes ln."""
     return db.object_session(self).query(CollectionPortalbox).\
         with_parent(self).\
         options(db.joinedload_all(CollectionPortalbox.portalbox)).\
         filter(CollectionPortalbox.ln == g.ln).\
         order_by(db.desc(CollectionPortalbox.score)).all()
Exemple #2
0
 def most_specific_dad(self):
     """Most specific dad."""
     results = sorted(db.object_session(self).query(Collection).join(
         Collection.sons).filter(
             CollectionCollection.id_son == self.id).all(),
                      key=lambda c: c.nbrecs)
     return results[0] if len(results) else None
Exemple #3
0
 def most_specific_dad(self):
     results = sorted(
         db.object_session(self).query(Collection).join(
             Collection.sons
         ).filter(CollectionCollection.id_son == self.id).all(),
         key=lambda c: c.nbrecs)
     return results[0] if len(results) else None
 def portalboxes_ln(self):
     """Get Portalboxes ln."""
     return db.object_session(self).query(CollectionPortalbox).\
         with_parent(self).\
         options(db.joinedload_all(CollectionPortalbox.portalbox)).\
         filter(CollectionPortalbox.ln == g.ln).\
         order_by(db.desc(CollectionPortalbox.score)).all()
Exemple #5
0
 def most_specific_dad(self):
     """Most specific dad."""
     return db.object_session(self).query(Collection).\
         join(Collection.sons).\
         filter(CollectionCollection.id_son == self.id).\
         order_by(db.asc(Collection.nbrecs)).\
         first()
Exemple #6
0
 def translation(self, lang):
     try:
         return db.object_session(self).query(Collectionname).\
             with_parent(self).filter(db.and_(Collectionname.ln == lang,
                 Collectionname.type == 'ln')).first().value
     except:
         return ""
Exemple #7
0
 def title(self):
     try:
         return db.object_session(self).query(LnkENTRYURLTITLE).\
             filter(db.and_(
                 LnkENTRYURLTITLE.url==self.origin_url,
                 LnkENTRYURLTITLE.title<>"",
                 LnkENTRYURLTITLE.broken==0)).first().title
     except:
         return self.origin_url
Exemple #8
0
 def title(self):
     try:
         return db.object_session(self).query(LnkENTRYURLTITLE).\
             filter(db.and_(
                 LnkENTRYURLTITLE.url==self.origin_url,
                 LnkENTRYURLTITLE.title<>"",
                 LnkENTRYURLTITLE.broken==0)).first().title
     except:
         return self.origin_url
Exemple #9
0
 def translation(self, lang):
     """Get the translation according to the language code."""
     try:
         return db.object_session(self).query(Collectionname).\
             with_parent(self).filter(db.and_(
                 Collectionname.ln == lang,
                 Collectionname.type == 'ln'
             )).first().value
     except Exception:
         return ""
 def translation(self, lang):
     """Get the translation according to the language code."""
     try:
         return db.object_session(self).query(Collectionname).\
             with_parent(self).filter(db.and_(
                 Collectionname.ln == lang,
                 Collectionname.type == 'ln'
             )).first().value
     except Exception:
         return ""
Exemple #11
0
    def get_collectionbox_name(self, ln=None, box_type="r"):
        """Return collection-specific labelling subtrees.

        - 'Focus on': regular collection
        - 'Narrow by': virtual collection
        - 'Latest addition': boxes

        If translation for given language does not exist, use label
        for CFG_SITE_LANG. If no custom label is defined for
        CFG_SITE_LANG, return default label for the box.

        :param ln: the language of the label
        :param box_type: can be 'r' (=Narrow by), 'v' (=Focus on),
                         'l' (=Latest additions)
        """
        if ln is None:
            ln = g.ln
        collectionboxnamequery = db.object_session(self).query(
            Collectionboxname).with_parent(self)
        try:
            collectionboxname = collectionboxnamequery.filter(
                db.and_(
                    Collectionboxname.ln == ln,
                    Collectionboxname.type == box_type,
                )).one()
        except Exception:
            try:
                collectionboxname = collectionboxnamequery.filter(
                    db.and_(
                        Collectionboxname.ln == ln,
                        Collectionboxname.type == box_type,
                    )).one()
            except Exception:
                collectionboxname = None

        if collectionboxname is None:
            # load the right message language
            _ = gettext_set_language(ln)
            return _(Collectionboxname.TYPES.get(box_type, ''))
        else:
            return collectionboxname.value
    def get_collectionbox_name(self, ln=None, box_type="r"):
        """Return collection-specific labelling subtrees.

        - 'Focus on': regular collection
        - 'Narrow by': virtual collection
        - 'Latest addition': boxes

        If translation for given language does not exist, use label
        for CFG_SITE_LANG. If no custom label is defined for
        CFG_SITE_LANG, return default label for the box.

        :param ln: the language of the label
        :param box_type: can be 'r' (=Narrow by), 'v' (=Focus on),
                         'l' (=Latest additions)
        """
        if ln is None:
            ln = g.ln
        collectionboxnamequery = db.object_session(self).query(
            Collectionboxname).with_parent(self)
        try:
            collectionboxname = collectionboxnamequery.filter(db.and_(
                Collectionboxname.ln == ln,
                Collectionboxname.type == box_type,
            )).one()
        except Exception:
            try:
                collectionboxname = collectionboxnamequery.filter(db.and_(
                    Collectionboxname.ln == ln,
                    Collectionboxname.type == box_type,
                )).one()
            except Exception:
                collectionboxname = None

        if collectionboxname is None:
            # load the right message language
            _ = gettext_set_language(ln)
            return _(Collectionboxname.TYPES.get(box_type, ''))
        else:
            return collectionboxname.value
Exemple #13
0
    UserAccROLE,
    lazy="dynamic",
    primaryjoin=db.and_(
        User.id == UserAccROLE.id_user,
        UserAccROLE.expiration >= db.func.now()
    )
)

User.has_admin_role = property(lambda self:
    self.has_super_admin_role or db.object_session(self).query(
        db.func.count(User.id)>0
    ).join(
        User.active_roles,
        UserAccROLE.role,
        AccROLE.authorizations
    ).filter(
        AccAuthorization.id_accACTION.in_(
            db.select([AccACTION.id]).where(
                AccACTION.name.in_(CFG_ACC_ACTIVITIES_URLS.keys())
            )
        ),
        User.id == self.id
    ).scalar()
)

User.has_super_admin_role = property(lambda self:
    db.object_session(self).query(db.func.count(User.id)>0).join(
        User.active_roles,
        UserAccROLE.role
    ).filter(
        AccROLE.name == SUPERADMINROLE,
        User.id == self.id
Exemple #14
0
    lazy="dynamic",
    primaryjoin=db.and_(
        User.id == UserAccROLE.id_user,
        UserAccROLE.expiration >= db.func.now()
    )
)

User.has_admin_role = property(
    lambda self:
    self.has_super_admin_role or db.object_session(self).query(
        db.func.count(User.id) > 0
    ).join(
        User.active_roles,
        UserAccROLE.role,
        AccROLE.authorizations
    ).filter(
        AccAuthorization.id_accACTION.in_(
            db.select([AccACTION.id]).where(
                AccACTION.name.in_(CFG_ACC_ACTIVITIES_URLS.keys())
            )
        ),
        User.id == self.id
    ).scalar()
)

User.has_super_admin_role = property(
    lambda self:
    db.object_session(self).query(db.func.count(User.id) > 0).join(
        User.active_roles,
        UserAccROLE.role
    ).filter(
        AccROLE.name == SUPERADMINROLE,
Exemple #15
0
 def most_specific_dad(self):
     return db.object_session(self).query(Collection).\
         join(Collection.sons).\
         filter(CollectionCollection.id_son == self.id).\
         order_by(db.asc(Collection.nbrecs)).\
         first()