예제 #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()
예제 #2
0
    def filter_communities(cls, p, so):
        """Search for communities.

        Helper function which takes from database only those communities which
        match search criteria. Uses parameter 'so' to set communities in the
        correct order.

        Parameter 'page' is introduced to restrict results and return only
        slice of them for the current page. If page == 0 function will return
        all communities that match the pattern.
        """
        query = cls.query
        if p:
            query = query.filter(
                db.or_(
                    cls.id.like("%" + p + "%"),
                    cls.title.like("%" + p + "%"),
                    cls.description.like("%" + p + "%"),
                ))
        if so in cfg['COMMUNITIES_SORTING_OPTIONS']:
            order = so == 'title' and db.asc or db.desc
            query = query.order_by(order(getattr(cls, so)))
        else:
            query = query.order_by(db.desc(cls.ranking))
        return query
예제 #3
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()
예제 #4
0
class CollectionFormat(db.Model):
    """Represent a CollectionFormat record."""
    __tablename__ = 'collection_format'
    id_collection = db.Column(db.MediumInteger(9, unsigned=True),
                              db.ForeignKey(Collection.id),
                              primary_key=True)
    id_format = db.Column(db.MediumInteger(9, unsigned=True),
                          db.ForeignKey(Format.id),
                          primary_key=True)
    score = db.Column(db.TinyInteger(4, unsigned=True),
                      nullable=False,
                      server_default='0')
    collection = db.relationship(Collection,
                                 backref='formats',
                                 order_by=db.desc(score))
    format = db.relationship(Format,
                             backref='collections',
                             order_by=db.desc(score))
예제 #5
0
class CollectionFormat(db.Model):

    """Represent a CollectionFormat record."""

    __tablename__ = 'collection_format'
    id_collection = db.Column(db.MediumInteger(9, unsigned=True),
                              db.ForeignKey(Collection.id), primary_key=True)
    format_code = db.Column('format', db.String(10), primary_key=True)
    score = db.Column(db.TinyInteger(4, unsigned=True),
                      nullable=False, server_default='0')

    collection = db.relationship(
        Collection, backref=db.backref(
            'formats', order_by=db.desc(score)
        ), order_by=db.desc(score))

    @property
    def format(self):
        """Return output format definition."""
        return output_formats[self.format_code]
예제 #6
0
def ranking_deamon():
    """
        Ranks communities.
        Task is being run periodically.
    """
    comms = Community.query.all()
    coll = Collection.query.filter(Collection.community).order_by(db.desc(Collection.nbrecs)).first()
    if coll:
        max_recs_cnt = coll.nbrecs
    for comm in comms:
        ranking = calculate_rank_for_community(comm, max_recs_cnt)
        comm.ranking = ranking
    db.session.commit()
예제 #7
0
파일: tasks.py 프로젝트: chokribr/invenio-1
def ranking_deamon():
    """
        Ranks communities.
        Task is being run periodically.
    """
    comms = Community.query.all()
    coll = Collection.query.filter(Collection.community).order_by(
        db.desc(Collection.nbrecs)).first()
    if coll:
        max_recs_cnt = coll.nbrecs
    for comm in comms:
        ranking = calculate_rank_for_community(comm, max_recs_cnt)
        comm.ranking = ranking
    db.session.commit()
예제 #8
0
파일: views.py 프로젝트: chokribr/invenio-1
def menu():
    uid = current_user.get_id()

    dbquery.update_user_inbox_for_reminders(uid)
    # join: msgMESSAGE -> user_msgMESSAGE, msgMESSAGE -> users
    # filter: all messages from user AND filter form
    # order: sorted by one of the table column
    messages = db.session.query(MsgMESSAGE, UserMsgMESSAGE).\
        join(MsgMESSAGE.user_from, MsgMESSAGE.sent_to_users).\
        filter(db.and_(dbquery.filter_all_messages_from_user(uid))).\
        order_by(db.desc(MsgMESSAGE.received_date)).limit(5)

    #return dict(messages=messages.all())
    return render_template('messages/menu.html', messages=messages.all())
예제 #9
0
파일: views.py 프로젝트: mhellmic/b2share
def menu():
    uid = current_user.get_id()

    dbquery.update_user_inbox_for_reminders(uid)
    # join: msgMESSAGE -> user_msgMESSAGE, msgMESSAGE -> users
    # filter: all messages from user AND filter form
    # order: sorted by one of the table column
    messages = db.session.query(MsgMESSAGE, UserMsgMESSAGE).\
        join(MsgMESSAGE.user_from, MsgMESSAGE.sent_to_users).\
        filter(db.and_(dbquery.filter_all_messages_from_user(uid))).\
        order_by(db.desc(MsgMESSAGE.received_date)).limit(5)

    #return dict(messages=messages.all())
    return render_template('messages/menu.html', messages=messages.all())
예제 #10
0
파일: api.py 프로젝트: jirikuncar/invenio
def add_kb(kb_name=u"Untitled", kb_type=None, tries=10):
    """Add a new kb in database, return the id.

    Add a new kb in database, and returns its id
    The name of the kb will be 'Untitled#'
    such that it is unique.

    :param kb_name: the name of the kb
    :param kb_type: the type of the kb, incl 'taxonomy' and 'dynamic'.
                   None for typical (leftside-rightside).
    :param tries: exit after <n> retry
    :return: the id of the newly created kb
    """
    created = False
    name = kb_name
    i = 0
    while i < tries and created is False:
        try:
            kb = models.KnwKB(name=name, description="", kbtype=kb_type)
            created = True
            db.session.add(kb)
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
            # get the highest id to calculate the new name
            result = db.session.execute(
                db.select([models.KnwKB.id]).order_by(db.desc(models.KnwKB.id)).limit(1)
            ).first()
            index = result[0] + 1 if result is not None else 1
            name = kb_name + " " + str(index)
            i = i + 1
            created = False
        except Exception:
            db.session.rollback()
            raise

    if created is False:
        # TODO raise the right exception
        raise Exception(
            _(
                'Can\'t create knowledge base "%(name)s".\n' "Probabily the server is busy! " "Try again later.",
                name=kb_name,
            )
        )

    return kb.id
예제 #11
0
def add_kb(kb_name=u"Untitled", kb_type=None, tries=10):
    """Add a new kb in database, return the id.

    Add a new kb in database, and returns its id
    The name of the kb will be 'Untitled#'
    such that it is unique.

    :param kb_name: the name of the kb
    :param kb_type: the type of the kb, incl 'taxonomy' and 'dynamic'.
                   None for typical (leftside-rightside).
    :param tries: exit after <n> retry
    :return: the id of the newly created kb
    """
    created = False
    name = kb_name
    i = 0
    while (i < tries and created is False):
        try:
            kb = models.KnwKB(name=name, description="", kbtype=kb_type)
            created = True
            db.session.add(kb)
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
            # get the highest id to calculate the new name
            result = db.session.execute(
                db.select([models.KnwKB.id]).order_by(db.desc(
                    models.KnwKB.id)).limit(1)).first()
            index = result[0] + 1 if result is not None else 1
            name = kb_name + " " + str(index)
            i = i + 1
            created = False
        except Exception:
            db.session.rollback()
            raise

    if created is False:
        # TODO raise the right exception
        raise Exception(
            _(
                "Can't create knowledge base \"%(name)s\".\n"
                "Probabily the server is busy! "
                "Try again later.",
                name=kb_name))

    return kb.id
예제 #12
0
파일: models.py 프로젝트: mhellmic/b2share
    def filter_communities(cls, p, so):
        """
            Helper function which takes from database
            only those communities which match search
            criteria. Uses parameter 'so' to set
            communities in the correct order.

            Parameter 'page' is introduced to restrict results
            and return only slice of them for the current page.
            If page == 0 function will return all communities
            that match the pattern.
        """
        query = Community.query
        if p:
            query = query.filter(Community.title.like(p + "%"))
        if so in cfg['COMMUNITIES_SORTING_OPTIONS']:
            order = so == 'title' and db.asc or db.desc
            query = query.order_by(order(getattr(Community, so)))
        else:
            query = query.order_by(db.desc(Community.ranking))
        return query