Exemplo n.º 1
0
def tokenize(id_bibrec, q):
    """ Data for tokeninput """
    user = db.session.query(User).get(current_user.get_id())

    # Output only tags unattached to this record
    record = db.session.query(Bibrec).get(id_bibrec)

    tags = db.session.query(WtgTAG)\
        .filter_by(user=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(['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:
        tag_json = {'id': 0, 'name': new_name}
        response_tags.append(tag_json)

    return jsonify(dict(results=response_tags, query=q))
Exemplo n.º 2
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)
Exemplo n.º 3
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 ((type(msg_ids) is list) or (type(msg_ids) is 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)
Exemplo n.º 4
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.usergroups).filter(
             Usergroup.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.usergroups).filter(
                 db.and_(Usergroup.name.in_(groups_to_add),
                         db.not_(User.nickname.in_(
                             self.user_nicks)))).all():
             if u not in self.recipients:
                 self.recipients.append(u)