Exemple #1
0
def filter_all_messages_from_user(uid):
    """
    Filter all message from user with status code not 'reminder'.
    @param uid: user id
    @return: sqlalchemy.sql.expression.ClauseElement
    """
    reminder = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
    return db.not_(UserMsgMESSAGE.status.__eq__(reminder)) & \
        (UserMsgMESSAGE.id_user_to == uid)
Exemple #2
0
def _queries():
    """Preprocess collection queries."""
    from invenio_ext.sqlalchemy import db
    from invenio_collections.models import Collection
    return dict(
        (collection.name,
         dict(query=Query(
             COLLECTIONS_DELETED_RECORDS.format(dbquery=collection.dbquery)),
              ancestors=set(c.name for c in collection.ancestors
                            if c.dbquery is None)))
        for collection in Collection.query.filter(
            Collection.dbquery.isnot(None),
            db.not_(Collection.dbquery.like('hostedcollection:%'))).all())
def _queries():
    """Preprocess collection queries."""
    from invenio_ext.sqlalchemy import db
    from invenio_collections.models import Collection

    return dict(
        (
            collection.name,
            dict(
                query=Query(COLLECTIONS_DELETED_RECORDS.format(dbquery=collection.dbquery)),
                ancestors=set(c.name for c in collection.ancestors if c.dbquery is None),
            ),
        )
        for collection in Collection.query.filter(
            Collection.dbquery.isnot(None), db.not_(Collection.dbquery.like("hostedcollection:%"))
        ).all()
    )
Exemple #4
0
def check_if_need_to_delete_message_permanently(msg_ids):
    """
    Checks if a list of messages exist in anyone's inbox, if not,
    delete them permanently
    @param msg_id: sequence of message ids
    @return: number of deleted messages
    """
    if not((isinstance(msg_ids, list)) or (isinstance(msg_ids, tuple))):
        msg_ids = [msg_ids]

    msg_used = db.session.query(UserMsgMESSAGE.id_msgMESSAGE).\
        filter(UserMsgMESSAGE.id_msgMESSAGE.in_(msg_ids)).\
        group_by(UserMsgMESSAGE.id_msgMESSAGE).\
        having(db.func.count(UserMsgMESSAGE.id_user_to) > 0).\
        subquery()

    return MsgMESSAGE.query.filter(MsgMESSAGE.id.in_(msg_ids) &
                                   db.not_(MsgMESSAGE.id.in_(msg_used))).\
        delete(synchronize_session=False)
Exemple #5
0
 def sent_to_group_names(self, value):
     old_group_names = self.group_names
     self._sent_to_group_names = value
     groups_to_add = set(self.group_names) - set(old_group_names)
     groups_to_del = set(old_group_names) - set(self.group_names)
     if len(groups_to_del):
         to_del = set([u.nickname for u in User.query.
                       join(User.groups).filter(
                           Group.name.in_(groups_to_del)).
                       all()]) - set(self.user_nicks)
         is_to_del = lambda u: u.nickname in to_del
         remove_old = filter(is_to_del, self.recipients)
         for u in remove_old:
             self.recipients.remove(u)
     if len(groups_to_add):
         for u in User.query.join(User.groups).filter(db.and_(
                 Group.name.in_(groups_to_add),
                 db.not_(User.nickname.in_(self.user_nicks)))).all():
             if u not in self.recipients:
                 self.recipients.append(u)
def tokenize(id_bibrec, q):
    """Data for tokeninput."""
    id_user = current_user.get_id()

    # Output only tags unattached to this record
    record = Record.query.get(id_bibrec)

    tags = WtgTAG.query\
        .filter_by(id_user=id_user)\
        .filter(WtgTAG.name.like('%' + q + '%'))\
        .filter(db.not_(WtgTAG.records.contains(record)))\
        .order_by(WtgTAG.name)

    # If a tag with searched name does not exist, lets suggest creating it
    # Clean the name
    new_name = wash_tag(q)
    add_new_name = True

    response_tags = []
    for tag in tags.all():
        tag_json = tag.serializable_fields(set(['id', 'name']))
        response_tags.append(tag_json)

        # Check if it matches the search name
        if tag_json['name'] == new_name:
            add_new_name = False

    # If the name was not found
    if add_new_name:
        # Check if a tag with this name is already attached
        already_attached = WtgTAG.query\
            .join(WtgTAGRecord)\
            .filter(WtgTAG.name == new_name)\
            .filter(WtgTAGRecord.id_bibrec == id_bibrec)\
            .count()

        if not already_attached:
            tag_json = {'id': 0, 'name': new_name}
            response_tags.append(tag_json)

    return jsonify(dict(results=response_tags, query=q))
def tokenize(id_bibrec, q):
    """Data for tokeninput."""
    id_user = current_user.get_id()

    # Output only tags unattached to this record
    record = Record.query.get(id_bibrec)

    tags = WtgTAG.query\
        .filter_by(id_user=id_user)\
        .filter(WtgTAG.name.like('%' + q + '%'))\
        .filter(db.not_(WtgTAG.records.contains(record)))\
        .order_by(WtgTAG.name)

    # If a tag with searched name does not exist, lets suggest creating it
    # Clean the name
    new_name = wash_tag(q)
    add_new_name = True

    response_tags = []
    for tag in tags.all():
        tag_json = tag.serializable_fields(set(['id', 'name']))
        response_tags.append(tag_json)

        # Check if it matches the search name
        if tag_json['name'] == new_name:
            add_new_name = False

    # If the name was not found
    if add_new_name:
        # Check if a tag with this name is already attached
        already_attached = WtgTAG.query\
            .join(WtgTAGRecord)\
            .filter(WtgTAG.name == new_name)\
            .filter(WtgTAGRecord.id_bibrec == id_bibrec)\
            .count()

        if not already_attached:
            tag_json = {'id': 0, 'name': new_name}
            response_tags.append(tag_json)

    return jsonify(dict(results=response_tags, query=q))