:param str username: Username to lookup (may be non-unique) Usernames are not guaranteed to be unique within a service. An example is with Google, where the userid is a directed OpenID URL, unique but subject to change if the Lastuser site URL changes. The username is the email address, which will be the same despite different userids. """ param, value = require_one_of(True, userid=userid, username=username) return cls.query.filter_by(**{ param: value, 'service': service }).one_or_none() def permissions(self, user, inherited=None): perms = super(UserExternalId, self).permissions(user, inherited) if user and user == self.user: perms.add('delete_extid') return perms user_email_primary_table = add_primary_relationship(User, 'primary_email', UserEmail, 'user', 'user_id') user_phone_primary_table = add_primary_relationship(User, 'primary_phone', UserPhone, 'user', 'user_id') # Tail imports from .profile import Profile # isort:skip from .organization_membership import OrganizationMembership # isort:skip
:param str service: Service to lookup :param str userid: Userid to lookup :param str username: Username to lookup (may be non-unique) Usernames are not guaranteed to be unique within a service. An example is with Google, where the userid is a directed OpenID URL, unique but subject to change if the Lastuser site URL changes. The username is the email address, which will be the same despite different userids. """ param, value = require_one_of(True, userid=userid, username=username) return cls.query.filter_by(**{ param: value, 'service': service }).one_or_none() add_primary_relationship(User, 'primary_email', UserEmail, 'user', 'user_id') add_primary_relationship(User, 'primary_phone', UserPhone, 'user', 'user_id') create_userexternalid_index = DDL( 'CREATE INDEX ix_userexternalid_username_lower ON userexternalid (lower(username) varchar_pattern_ops);' ) event.listen(UserExternalId.__table__, 'after_create', create_userexternalid_index.execute_if(dialect='postgresql')) event.listen( UserExternalId.__table__, 'before_drop', DDL('DROP INDEX ix_userexternalid_username_lower;').execute_if( dialect='postgresql'))
parent = db.synonym('venue') description = MarkdownColumn('description', default=u'', nullable=False) bgcolor = db.Column(db.Unicode(6), nullable=False, default=u'229922') seq = db.Column(db.Integer, nullable=False) scheduled_sessions = db.relationship("Session", primaryjoin='and_(Session.venue_room_id == VenueRoom.id, Session.scheduled)') __table_args__ = (db.UniqueConstraint('venue_id', 'name'),) __roles__ = { 'all': { 'read': { 'id', 'name', 'title', 'description', 'bgcolor', 'seq', 'venue_details', 'scoped_name', 'suuid' }, }, } @property def venue_details(self): return {'name': self.venue.name, 'title': self.venue.title, 'suuid': self.venue.suuid} @property def scoped_name(self): return u'{parent}/{name}'.format(parent=self.parent.name, name=self.name) add_primary_relationship(Project, 'primary_venue', Venue, 'project', 'project_id')
def __repr__(self): return '<UserExternalId {service}:{username} of {user}>'.format( service=self.service, username=self.username, user=repr(self.user)[1:-1]) @classmethod def get(cls, service, userid=None, username=None): """ Return a UserExternalId with the given service and userid or username. :param str service: Service to lookup :param str userid: Userid to lookup :param str username: Username to lookup (may be non-unique) Usernames are not guaranteed to be unique within a service. An example is with Google, where the userid is a directed OpenID URL, unique but subject to change if the Lastuser site URL changes. The username is the email address, which will be the same despite different userids. """ param, value = require_one_of(True, userid=userid, username=username) return cls.query.filter_by(**{param: value, 'service': service}).one_or_none() def permissions(self, user, inherited=None): perms = super(UserExternalId, self).permissions(user, inherited) if user and user == self.user: perms.add('delete_extid') return perms add_primary_relationship(User, 'primary_email', UserEmail, 'user', 'user_id') add_primary_relationship(User, 'primary_phone', UserPhone, 'user', 'user_id')
__tablename__ = 'uuid_mixin_key' __uuid_primary_key__ = True class ParentForPrimary(BaseMixin, db.Model): __tablename__ = 'parent_for_primary' class ChildForPrimary(BaseMixin, db.Model): __tablename__ = 'child_for_primary' parent_for_primary_id = Column(None, ForeignKey('parent_for_primary.id'), nullable=False) parent_for_primary = db.relationship(ParentForPrimary) parent = db.synonym('parent_for_primary') add_primary_relationship(ParentForPrimary, 'primary_child', ChildForPrimary, 'parent', 'parent_for_primary_id') # Used for the tests below parent_child_primary = db.Model.metadata.tables['parent_for_primary_child_for_primary_primary'] class DefaultValue(BaseMixin, db.Model): __tablename__ = 'default_value' value = db.Column(db.Unicode(100), default='default') auto_init_default(DefaultValue.value) # --- Tests -------------------------------------------------------------------
'related': { 'id' # TODO: Used in SessionForm.venue_room_id; needs to be .venue_room 'uuid_b58', 'name', 'title', 'description', 'bgcolor', 'seq', 'scoped_name', }, } @property def scoped_name(self): return '{parent}/{name}'.format(parent=self.parent.name, name=self.name) add_primary_relationship(Project, 'primary_venue', Venue, 'project', 'project_id') with_roles(Project.primary_venue, read={'all'}, datasets={'primary', 'without_parent'}) @reopen(Project) class Project: @property def rooms(self): return [room for venue in self.venues for room in venue.rooms]