How to use the invenio.ext.sqlalchemy.db function in invenio

To help you get started, we’ve selected a few invenio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inveniosoftware / invenio / invenio / modules / communities / testsuite / test_communities.py View on Github external
def setUp(self):
        Community.query.delete()
        self.login('admin', '')
        uid = current_user.get_id()
        data = {'id': self.test_name,
                'title': self.test_name}
        self.c = Community(id_user=uid, **data)
        db.session.add(self.c)
        db.session.commit()
        self.c.save_collections()
github inveniosoftware / invenio / invenio / modules / ranker / models.py View on Github external
__table_args__ = (db.Index('rnkSELFCITEDICT_reverse', citer, citee),
                      db.Model.__table_args__)


class CollectionRnkMETHOD(db.Model):

    """Represent a CollectionRnkMETHOD record."""

    __tablename__ = 'collection_rnkMETHOD'
    id_collection = db.Column(db.MediumInteger(9, unsigned=True),
                              db.ForeignKey(Collection.id), primary_key=True,
                              nullable=False)
    id_rnkMETHOD = db.Column(db.MediumInteger(9, unsigned=True),
                             db.ForeignKey(RnkMETHOD.id), primary_key=True,
                             nullable=False)
    score = db.Column(db.TinyInteger(4, unsigned=True), nullable=False,
                      server_default='0')
    collection = db.relationship(Collection, backref='rnkMETHODs')
    rnkMETHOD = db.relationship(RnkMETHOD, backref='collections')


__all__ = ('RnkMETHOD',
           'RnkMETHODDATA',
           'RnkMETHODNAME',
           'RnkCITATIONDICT',
           'RnkCITATIONDATAERR',
           'RnkCITATIONDATAEXT',
           'RnkCITATIONLOG',
           'RnkAUTHORDATA',
           'RnkDOWNLOADS',
           'RnkPAGEVIEWS',
           'RnkWORD01F',
github inveniosoftware / invenio / invenio / modules / messages / models.py View on Github external
# Create your models here.
from string import strip
from invenio.modules.accounts.models import User, Usergroup
from sqlalchemy.ext.associationproxy import association_proxy


class MsgMESSAGE(db.Model):
    """Represents a MsgMESSAGE record."""
    def __str__(self):
        return "From: %s<%s>, Subject: <%s> %s" % \
            (self.user_from.nickname or _('None'),
            self.user_from.email or _('unknown'),
            self.subject, self.body)
    __tablename__ = 'msgMESSAGE'
    id = db.Column(db.Integer(15, unsigned=True), nullable=False,
                primary_key=True,
                autoincrement=True)
    id_user_from = db.Column(db.Integer(15, unsigned=True),
                db.ForeignKey(User.id),
                nullable=True, server_default='0')
    _sent_to_user_nicks = db.Column(db.Text, name='sent_to_user_nicks',
                nullable=False)
    _sent_to_group_names = db.Column(db.Text, name='sent_to_group_names',
                nullable=False)
    subject = db.Column(db.Text, nullable=False)
    body = db.Column(db.Text, nullable=True)
    sent_date = db.Column(db.DateTime, nullable=False,
        server_default='1900-01-01 00:00:00') # db.func.now() -> 'NOW()'
    received_date = db.Column(db.DateTime,
        server_default='1900-01-01 00:00:00')
    user_from = db.relationship(User, backref='sent_messages')
github inveniosoftware / invenio / invenio / modules / oauth2server / models.py View on Github external
self.reset_client_secret()

    def reset_client_id(self):
        """Reset client id."""
        self.client_id = gen_salt(
            current_app.config.get('OAUTH2_CLIENT_ID_SALT_LEN')
        )

    def reset_client_secret(self):
        """Reset client secret."""
        self.client_secret = gen_salt(
            current_app.config.get('OAUTH2_CLIENT_SECRET_SALT_LEN')
        )


class Token(db.Model):

    """A bearer token is the final token that can be used by the client."""

    __tablename__ = 'oauth2TOKEN'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    """Object ID."""

    client_id = db.Column(
        db.String(255), db.ForeignKey('oauth2CLIENT.client_id'),
        nullable=False,
    )
    """Foreign key to client application."""

    client = db.relationship(
        'Client',
github inveniosoftware / invenio / invenio / modules / indexer / models.py View on Github external
db.ForeignKey(IdxINDEX.id), primary_key=True)
    ln = db.Column(db.Char(5), primary_key=True,
                   server_default='')
    type = db.Column(db.Char(3), primary_key=True,
                     server_default='sn')
    value = db.Column(db.String(255), nullable=False)
    idxINDEX = db.relationship(IdxINDEX, backref='names')


class IdxINDEXField(db.Model):

    """Represent a IdxINDEXField record."""

    __tablename__ = 'idxINDEX_field'
    id_idxINDEX = db.Column(db.MediumInteger(9, unsigned=True),
                            db.ForeignKey(IdxINDEX.id), primary_key=True)
    id_field = db.Column(db.MediumInteger(9, unsigned=True),
                         db.ForeignKey(Field.id), primary_key=True)
    regexp_punctuation = db.Column(db.String(255),
                                   nullable=False,
                                   server_default='[.,:;?!"]')
    regexp_alphanumeric_separators = db.Column(db.String(255),
                                               nullable=False)  # FIX ME ,
    # server_default='[!"#$\\%&''()*+,-./:;<=>?@[\\]^\\_`{|}~]')
    idxINDEX = db.relationship(IdxINDEX, backref='fields', lazy='joined',
                               innerjoin=True)
    field = db.relationship(Field, backref='idxINDEXes', lazy='joined',
                            innerjoin=True)

    @classmethod
    def get_field_tokenizers(cls):
        """Get field tokenizers."""
github inveniosoftware / invenio / invenio / modules / exporter / models.py View on Github external
output_fields = db.Column(db.Text, nullable=False)
    notes = db.Column(db.Text, nullable=True)
    deleted = db.Column(db.MediumInteger(12), nullable=False,
                server_default='0')

class ExpJOBExpQUERY(db.Model):
    """Represents a ExpJOBExpQUERY record."""
    __tablename__ = 'expJOB_expQUERY'
    id_expJOB = db.Column(db.Integer(15, unsigned=True),
                    db.ForeignKey(ExpJOB.id), nullable=False,
                    primary_key=True)
    id_expQUERY = db.Column(db.Integer(15, unsigned=True),
                    db.ForeignKey(ExpQUERY.id), nullable=False,
                    primary_key=True)

    query = db.relationship(ExpQUERY, backref='jobs')
    job = db.relationship(ExpJOB, backref='queries')

class ExpQUERYRESULT(db.Model):
    """Represents a ExpQUERYRESULT record."""
    __tablename__ = 'expQUERYRESULT'
    id = db.Column(db.Integer(15, unsigned=True), nullable=False,
                primary_key=True,
                autoincrement=True)
    id_expQUERY = db.Column(db.Integer(15, unsigned=True),
                db.ForeignKey(ExpQUERY.id),
                nullable=False)
    result = db.Column(db.Text, nullable=False)
    status = db.Column(db.MediumInteger(12), nullable=False,
                server_default='0')
    status_message = db.Column(db.Text, nullable=False)
    query = db.relationship(ExpQUERY, backref='queryresults')
github inveniosoftware / invenio / invenio / base / decorators.py View on Github external
(cond, values))

                        # Multi-values support
                        if len(values) > 0:
                            # Ignore empty values when using start with,
                            # contains or similar.
                            # FIXME: add per field configuration
                            values = [value for value in values
                                      if len(value) > 0 or filter_empty]
                            if op == operators.eq:
                                where.append(db.in_(values))
                            else:
                                or_list = []
                                for value in values:
                                    or_list.append(op(cond, value))
                                where.append(db.or_(*or_list))
                        else:
                            where.append(op(cond, value))
                except:
                    flash(g._("Invalid filtering key '%(x_key)s'.", x_key=column))
            if form is not None:
                filter_form = form(request.values)

                @register_template_context_processor
                def inject_filter_form():
                    return dict(filter_form=filter_form)
            # Generate ClauseElement for filtered columns.
            kwargs['filter'] = db.and_(*where)
            return f(*args, **kwargs)
        return decorated_function
github inveniosoftware / invenio / invenio / ext / login / __init__.py View on Github external
def authenticate(nickname_or_email=None, password=None,
                 login_method=None, remember=False):
    """
    Find user identified by given information and login method.

    :param nickname_or_email: User nickname or email address
    :param password: Password used only in login methods that need it
    :param login_method: Login method (default: 'Local')
    :return: UserInfo
    """
    from invenio_base.i18n import _
    from invenio.ext.sqlalchemy import db
    from invenio_accounts.models import User
    from sqlalchemy.orm.exc import NoResultFound

    where = [db.or_(User.nickname == nickname_or_email,
                    User.email == nickname_or_email)]

    try:
        user = User.query.filter(*where).one()
        if login_method == 'Local' and password is not None:
            if not user.verify_password(password, migrate=True):
                return False
    except NoResultFound:
        return None
    except Exception:
        current_app.logger.exception("Problem checking password.")
        return False

    if login_method is not None and \
            user.settings['login_method'] != login_method:
        flash(_("You are not authorized to use '%(x_login_method)s' login "
github inveniosoftware / invenio / invenio / modules / records / models.py View on Github external
field_number = db.Column(db.SmallInteger(5, unsigned=True),
                             primary_key=True)

    @declared_attr
    def bibrec(cls):
        return db.relationship(Record)

    @declared_attr
    def bibxxx(cls):
        return db.relationship(cls._bibxxx, backref='bibrecs')

models = []

for idx in range(100):
    Bibxxx = "Bib{0:02d}x".format(idx)
    globals()[Bibxxx] = type(Bibxxx, (db.Model, BibxxxMixin), {})
    BibrecBibxxx = "BibrecBib{0:02d}x".format(idx)
    globals()[BibrecBibxxx] = type(BibrecBibxxx,
                                   (db.Model, BibrecBibxxxMixin), {})

    models += [Bibxxx, BibrecBibxxx]

__all__ = tuple([
    'Record',
    'RecordMetadata',
] + models)
github inveniosoftware / invenio / invenio / modules / accounts / models.py View on Github external
return self.note == "1"

    def is_guest(self):
        """Return if the user is a guest."""
        return self.guest

    def is_authenticated(self):
        """Return True if user is a authenticated user."""
        return True if self.email else False

    def is_active(self):
        """Return True if use is active."""
        return self.note != "0"


class UserEXT(db.Model):

    """Represent a UserEXT record."""

    __tablename__ = 'userEXT'

    id = db.Column(db.String(255), primary_key=True, nullable=False)
    method = db.Column(db.String(50), primary_key=True, nullable=False)
    id_user = db.Column(db.Integer(15, unsigned=True),
                        db.ForeignKey(User.id), nullable=False)

    user = db.relationship(User, backref="external_identifiers")

    __table_args__ = (db.Index('id_user', id_user, method, unique=True),
                      db.Model.__table_args__)

__all__ = ('User', 'UserEXT')