# HG changeset patch # User Marcin Kuzminski # Date 1324428999 -7200 # Node ID 6c86c987cf93db69eac3ed375ce5c21ab808fd1d # Parent 2ee93fba129ed726bee76edd64d6a0c6798eebcd pep8ify diff -r 2ee93fba129e -r 6c86c987cf93 rhodecode/model/__init__.py --- a/rhodecode/model/__init__.py Wed Dec 21 02:26:15 2011 +0200 +++ b/rhodecode/model/__init__.py Wed Dec 21 02:56:39 2011 +0200 @@ -77,7 +77,7 @@ def _get_instance(self, cls, instance): """ Get's instance of given cls using some simple lookup mechanism - + :param cls: class to fetch :param instance: int or Instance """ diff -r 2ee93fba129e -r 6c86c987cf93 rhodecode/model/db.py --- a/rhodecode/model/db.py Wed Dec 21 02:26:15 2011 +0200 +++ b/rhodecode/model/db.py Wed Dec 21 02:56:39 2011 +0200 @@ -51,6 +51,7 @@ # BASE CLASSES #============================================================================== + class ModelSerializer(json.JSONEncoder): """ Simple Serializer for JSON, @@ -81,6 +82,7 @@ else: return json.JSONEncoder.default(self, obj) + class BaseModel(object): """ Base Model for all classess @@ -100,10 +102,10 @@ d = {} for k in self._get_keys(): d[k] = getattr(self, k) - + # also use __json__() if present to get additional fields if hasattr(self, '__json__'): - for k,val in self.__json__().iteritems(): + for k, val in self.__json__().iteritems(): d[k] = val return d @@ -179,7 +181,6 @@ return "<%s('%s:%s')>" % (self.__class__.__name__, self.app_settings_name, self.app_settings_value) - @classmethod def get_by_name(cls, ldap_key): return cls.query()\ @@ -228,12 +229,10 @@ ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) - @classmethod def get_by_key(cls, key): return cls.query().filter(cls.ui_key == key) - @classmethod def get_builtin_hooks(cls): q = cls.query() @@ -316,7 +315,6 @@ return "<%s('id:%s:%s')>" % (self.__class__.__name__, self.user_id, self.username) - @classmethod def get_by_username(cls, username, case_insensitive=False, cache=False): if case_insensitive: @@ -356,7 +354,6 @@ Session.add(self) log.debug('updated user %s lastlogin', self.username) - def __json__(self): return dict(email=self.email, full_name=self.full_name) @@ -414,6 +411,7 @@ "get_users_group_%s" % users_group_id)) return users_group.get(users_group_id) + class UsersGroupMember(Base, BaseModel): __tablename__ = 'users_groups_members' __table_args__ = {'extend_existing':True} @@ -438,6 +436,7 @@ Session.commit() return ugm + class Repository(Base, BaseModel): __tablename__ = 'repositories' __table_args__ = (UniqueConstraint('repo_name'), {'extend_existing':True},) @@ -456,7 +455,6 @@ fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) - user = relationship('User') fork = relationship('Repository', remote_side=repo_id) group = relationship('RepoGroup') @@ -568,7 +566,6 @@ baseui._ucfg = config.config() baseui._tcfg = config.config() - ret = RhodeCodeUi.query()\ .options(FromCache("sql_cache_short", "repository_repo_ui")).all() @@ -593,7 +590,6 @@ return is_valid_repo(repo_name, cls.base_path()) - #========================================================================== # SCM PROPERTIES #========================================================================== @@ -683,7 +679,6 @@ parent_group = relationship('RepoGroup', remote_side=group_id) - def __init__(self, group_name='', parent_group=None): self.group_name = group_name self.parent_group = parent_group @@ -840,6 +835,7 @@ def __repr__(self): return ' %s >' % (self.user, self.repository) + class UserToPerm(Base, BaseModel): __tablename__ = 'user_to_perm' __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'extend_existing':True}) @@ -875,6 +871,7 @@ def __repr__(self): return ' %s >' % (self.users_group, self.repository) + class UsersGroupToPerm(Base, BaseModel): __tablename__ = 'users_group_to_perm' users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) @@ -898,6 +895,7 @@ permission = relationship('Permission') group = relationship('RepoGroup') + class UsersGroupRepoGroupToPerm(Base, BaseModel): __tablename__ = 'users_group_repo_group_to_perm' __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True}) @@ -911,6 +909,7 @@ permission = relationship('Permission') group = relationship('RepoGroup') + class Statistics(Base, BaseModel): __tablename__ = 'statistics' __table_args__ = (UniqueConstraint('repository_id'), {'extend_existing':True}) @@ -923,6 +922,7 @@ repository = relationship('Repository', single_parent=True) + class UserFollowing(Base, BaseModel): __tablename__ = 'user_followings' __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), @@ -945,6 +945,7 @@ def get_repo_followers(cls, repo_id): return cls.query().filter(cls.follows_repo_id == repo_id) + class CacheInvalidation(Base, BaseModel): __tablename__ = 'cache_invalidation' __table_args__ = (UniqueConstraint('cache_key'), {'extend_existing':True}) @@ -1094,6 +1095,7 @@ from rhodecode.model.notification import NotificationModel return NotificationModel().make_description(self) + class UserNotification(Base, BaseModel): __tablename__ = 'user_to_notification' __table_args__ = (UniqueConstraint('user_id', 'notification_id'), @@ -1111,6 +1113,7 @@ self.read = True Session.add(self) + class DbMigrateVersion(Base, BaseModel): __tablename__ = 'db_migrate_version' __table_args__ = {'extend_existing':True} diff -r 2ee93fba129e -r 6c86c987cf93 rhodecode/model/meta.py --- a/rhodecode/model/meta.py Wed Dec 21 02:26:15 2011 +0200 +++ b/rhodecode/model/meta.py Wed Dec 21 02:56:39 2011 +0200 @@ -15,8 +15,8 @@ # Session = scoped_session( sessionmaker( - query_cls = caching_query.query_callable(cache_manager), - expire_on_commit = True, + query_cls=caching_query.query_callable(cache_manager), + expire_on_commit=True, ) ) diff -r 2ee93fba129e -r 6c86c987cf93 rhodecode/model/notification.py --- a/rhodecode/model/notification.py Wed Dec 21 02:26:15 2011 +0200 +++ b/rhodecode/model/notification.py Wed Dec 21 02:56:39 2011 +0200 @@ -4,8 +4,8 @@ ~~~~~~~~~~~~~~ Model for notifications - - + + :created_on: Nov 20, 2011 :author: marcink :copyright: (C) 2009-2011 Marcin Kuzminski @@ -61,9 +61,9 @@ type_=Notification.TYPE_MESSAGE, with_email=True, email_kwargs={}): """ - + Creates notification of given type - + :param created_by: int, str or User instance. User who created this notification :param subject: @@ -104,7 +104,7 @@ email_subject = NotificationModel().make_description(notif, False) type_ = type_ email_body = body - kwargs = {'subject':subject, 'body':h.rst_w_mentions(body)} + kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)} kwargs.update(email_kwargs) email_body_html = EmailNotificationModel()\ .get_email_tmpl(type_, **kwargs)