Пример #1
0
        for key in ('all_events', 'all_projects', 'all_stories', 'all_issues',
                    'upcoming_events', 'past_events', 'api_url',
                    'all_attendance'):
            organization_dict[key] = getattr(self, key)()

        if include_extras:
            for key in ('current_events', 'current_projects',
                        'current_stories'):
                organization_dict[key] = getattr(self, key)()

        return organization_dict


tbl = Organization.__table__
# Index the tsvector column
db.Index('index_org_tsv_body', tbl.c.tsv_body, postgresql_using='gin')

# Trigger to populate the search index column
trig_ddl = DDL("""
    CREATE TRIGGER tsvupdate_orgs_trigger BEFORE INSERT OR UPDATE ON organization FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(tsv_body, 'pg_catalog.english', name);
""")
# Initialize the trigger after table is created
event.listen(tbl, 'after_create', trig_ddl.execute_if(dialect='postgresql'))


class Story(db.Model):
    '''
        Blog posts from a Brigade.
    '''
    # Columns
    id = db.Column(db.Integer(), primary_key=True)
Пример #2
0
    @password.setter
    def password(self, password):
        if password == None:
            self.password_hash = None
        else:
            self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        if password == None or self.password_hash == None:
            return False
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<Account email: "%s">' % (self.email,)

db.Index('idx_account_email', Account.email, unique=True)


class User(db.Model):
    user_id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False)
    name = db.Column(db.String(256), nullable=False)
    account_id = db.Column(db.Integer, db.ForeignKey(Account.account_id), nullable=True)

    #TODO: move to Account
    paypal_email = db.Column(db.String(256), nullable=True)

    def __init__(self, project_id, name):
        self.project_id = project_id
        self.name = name
        paypal_email = None
Пример #3
0

class Link(db.Model):
    __tablename__ = 'links'

    id = db.Column(db.Integer, primary_key=True)
    # An opaque UUID to avoid exposing primary keys to API.
    uuid = db.Column(pg.UUID,
                     server_default=uuid_generate_v4(),
                     default=lambda: uuid.uuid4().hex,
                     nullable=False)
    geom = db.Column(Geometry('LINESTRING', srid=4326), nullable=False)


# An index to enable efficient retrieval and ordering of links by uuid.
db.Index('ix_link_uuid', Link.uuid, unique=True)

# An index to enable efficient spatial quesies for links
db.Index('ix_link_geom', Link.geom, postgresql_using='gist')


class Observation(db.Model):
    __tablename__ = 'observations'

    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.Float, nullable=False)
    type = db.Column(PythonEnum(ObservationType, name='observation_types'),
                     nullable=False)
    observed_at = db.Column(db.DateTime(timezone=True), nullable=False)
    link_id = db.Column(db.Integer, db.ForeignKey('links.id'), nullable=False)
Пример #4
0
    issues_count = db.Column(db.Integer)
    # `updated_at`
    last_updated = db.Column(db.DateTime)

    owner_id = db.Column(db.Integer, db.ForeignKey("gh_users.id"))
    owner = db.relationship(User, backref=db.backref("repos", lazy="dynamic"))

    def short_dict(self):
        return dict(
            id=self.id,
            name=self.fullname,
            username=self.fullname.split("/")[0],
            reponame="/".join(self.fullname.split("/")[1:]),
        )

    def basic_dict(self):
        return dict(
            self.short_dict(),
            description=self.description,
            language=self.language,
            stars=self.star_count,
            watchers=self.watcher_count,
            forks=self.fork_count,
            issues=self.issues_count,
        )

db.Index("ix_gh_users_login_lower",
         db.func.lower(db.metadata.tables["gh_users"].c.login))
db.Index("ix_gh_repos_fullaname_lower",
         db.func.lower(db.metadata.tables["gh_repos"].c.fullname))