diff --git a/kallithea/controllers/admin/auth_settings.py b/kallithea/controllers/admin/auth_settings.py --- a/kallithea/controllers/admin/auth_settings.py +++ b/kallithea/controllers/admin/auth_settings.py @@ -76,7 +76,7 @@ class AuthSettingsController(BaseControl c.defaults[fullname] = v["default"] # Current values will be the default on the form, if there are any setting = Setting.get_by_name(fullname) - if setting: + if setting is not None: c.defaults[fullname] = setting.app_settings_value # we want to show , separated list of enabled plugins c.defaults['auth_plugins'] = ','.join(c.enabled_plugins) diff --git a/kallithea/controllers/admin/my_account.py b/kallithea/controllers/admin/my_account.py --- a/kallithea/controllers/admin/my_account.py +++ b/kallithea/controllers/admin/my_account.py @@ -259,7 +259,7 @@ class MyAccountController(BaseController user_id = self.authuser.user_id if request.POST.get('del_api_key_builtin'): user = User.get(user_id) - if user: + if user is not None: user.api_key = generate_api_key() Session().add(user) Session().commit() diff --git a/kallithea/controllers/admin/notifications.py b/kallithea/controllers/admin/notifications.py --- a/kallithea/controllers/admin/notifications.py +++ b/kallithea/controllers/admin/notifications.py @@ -160,7 +160,7 @@ class NotificationsController(BaseContro # if this association to user is not valid, we don't want to show # this message - if unotification: + if unotification is not None: if not unotification.read: unotification.mark_as_read() Session().commit() diff --git a/kallithea/controllers/admin/repos.py b/kallithea/controllers/admin/repos.py --- a/kallithea/controllers/admin/repos.py +++ b/kallithea/controllers/admin/repos.py @@ -217,7 +217,7 @@ class ReposController(BaseRepoController h.url('summary_home', repo_name=repo.repo_name)) fork = repo.fork - if fork: + if fork is not None: fork_name = fork.repo_name h.flash(h.literal(_('Forked repository %s as %s') % (fork_name, repo_url)), category='success') diff --git a/kallithea/controllers/admin/users.py b/kallithea/controllers/admin/users.py --- a/kallithea/controllers/admin/users.py +++ b/kallithea/controllers/admin/users.py @@ -316,7 +316,7 @@ class UsersController(BaseController): api_key = request.POST.get('del_api_key') if request.POST.get('del_api_key_builtin'): user = User.get(c.user.user_id) - if user: + if user is not None: user.api_key = generate_api_key() Session().add(user) Session().commit() diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py +++ b/kallithea/controllers/api/api.py @@ -463,7 +463,7 @@ class ApiController(JSONRPCController): if time_: _api_data = r.get_api_data() # if we use userfilter just show the locks for this user - if user: + if user is not None: if safe_int(userid) == user.user_id: ret.append(_api_data) else: diff --git a/kallithea/controllers/changeset.py b/kallithea/controllers/changeset.py --- a/kallithea/controllers/changeset.py +++ b/kallithea/controllers/changeset.py @@ -398,7 +398,7 @@ class ChangesetController(BaseRepoContro data = { 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))), } - if comment: + if comment is not None: data.update(comment.get_dict()) data.update({'rendered_text': render('changeset/changeset_comment_block.html')}) diff --git a/kallithea/controllers/pullrequests.py b/kallithea/controllers/pullrequests.py --- a/kallithea/controllers/pullrequests.py +++ b/kallithea/controllers/pullrequests.py @@ -751,7 +751,7 @@ class PullrequestsController(BaseRepoCon data = { 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))), } - if comment: + if comment is not None: c.comment = comment data.update(comment.get_dict()) data.update({'rendered_text': diff --git a/kallithea/model/__init__.py b/kallithea/model/__init__.py --- a/kallithea/model/__init__.py +++ b/kallithea/model/__init__.py @@ -94,7 +94,7 @@ class BaseModel(object): elif isinstance(instance, (int, long)) or safe_str(instance).isdigit(): return cls.get(instance) else: - if instance: + if instance is not None: if callback is None: raise Exception( 'given object must be int, long or Instance of %s ' diff --git a/kallithea/model/api_key.py b/kallithea/model/api_key.py --- a/kallithea/model/api_key.py +++ b/kallithea/model/api_key.py @@ -65,7 +65,7 @@ class ApiKeyModel(BaseModel): """ api_key = UserApiKeys.query().filter(UserApiKeys.api_key == api_key) - if user: + if user is not None: user = self._get_user(user) api_key = api_key.filter(UserApiKeys.user_id == user.user_id) diff --git a/kallithea/model/comment.py b/kallithea/model/comment.py --- a/kallithea/model/comment.py +++ b/kallithea/model/comment.py @@ -181,9 +181,9 @@ class ChangesetCommentsModel(BaseModel): comment.f_path = f_path comment.line_no = line_no - if revision: + if revision is not None: comment.revision = revision - elif pull_request: + elif pull_request is not None: pull_request = self.__get_pull_request(pull_request) comment.pull_request = pull_request else: diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -130,7 +130,7 @@ class BaseModel(object): raise HTTPNotFound res = cls.query().get(id_) - if not res: + if res is None: raise HTTPNotFound return res @@ -232,7 +232,7 @@ class Setting(Base, BaseModel): @classmethod def get_by_name_or_create(cls, key, val='', type='unicode'): res = cls.get_by_name(key) - if not res: + if res is None: res = cls(key, val, type) return res @@ -248,7 +248,7 @@ class Setting(Base, BaseModel): :return: """ res = cls.get_by_name(key) - if not res: + if res is None: val = Optional.extract(val) type = Optional.extract(type) res = cls(key, val, type) @@ -270,7 +270,7 @@ class Setting(Base, BaseModel): if cache: ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) - if not ret: + if ret is None: raise Exception('Could not get application settings !') settings = {} for each in ret: @@ -624,12 +624,12 @@ class User(Base, BaseModel): _email = email(author) if _email: user = cls.get_by_email(_email, case_insensitive=True) - if user: + if user is not None: return user # Maybe we can match by username? _author = author_name(author) user = cls.get_by_username(_author, case_insensitive=True) - if user: + if user is not None: return user def update_lastlogin(self): @@ -2488,7 +2488,7 @@ class Gist(Base, BaseModel): @classmethod def get_or_404(cls, id_): res = cls.query().filter(cls.gist_access_id == id_).scalar() - if not res: + if res is None: raise HTTPNotFound return res diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -53,7 +53,7 @@ class NotificationModel(BaseModel): elif isinstance(notification, (int, long)): return Notification.get(notification) else: - if notification: + if notification is not None: raise Exception('notification must be int, long or Instance' ' of Notification got %s' % type(notification)) @@ -85,7 +85,7 @@ class NotificationModel(BaseModel): if recipients: for u in recipients: obj = self._get_user(u) - if obj: + if obj is not None: recipients_objs.append(obj) else: # TODO: inform user that requested operation couldn't be completed diff --git a/kallithea/model/repo.py b/kallithea/model/repo.py --- a/kallithea/model/repo.py +++ b/kallithea/model/repo.py @@ -535,7 +535,7 @@ class RepoModel(BaseModel): if not cur_user: cur_user = getattr(get_current_authuser(), 'username', None) repo = self._get_repo(repo) - if repo: + if repo is not None: if forks == 'detach': for r in repo.forks: r.fork = None @@ -602,7 +602,7 @@ class RepoModel(BaseModel): .filter(UserRepoToPerm.repository == repo) \ .filter(UserRepoToPerm.user == user) \ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm on %s on %s' % (repo, user)) @@ -652,7 +652,7 @@ class RepoModel(BaseModel): .filter(UserGroupRepoToPerm.repository == repo) \ .filter(UserGroupRepoToPerm.users_group == group_name) \ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm to %s on %s' % (repo, group_name)) @@ -666,7 +666,7 @@ class RepoModel(BaseModel): try: obj = self.sa.query(Statistics) \ .filter(Statistics.repository == repo).scalar() - if obj: + if obj is not None: self.sa.delete(obj) except Exception: log.error(traceback.format_exc()) diff --git a/kallithea/model/repo_group.py b/kallithea/model/repo_group.py --- a/kallithea/model/repo_group.py +++ b/kallithea/model/repo_group.py @@ -485,7 +485,7 @@ class RepoGroupModel(BaseModel): .filter(UserRepoGroupToPerm.user == user)\ .filter(UserRepoGroupToPerm.group == repo_group)\ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm on %s on %s' % (repo_group, user)) @@ -537,6 +537,6 @@ class RepoGroupModel(BaseModel): .filter(UserGroupRepoGroupToPerm.group == repo_group)\ .filter(UserGroupRepoGroupToPerm.users_group == group_name)\ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm to %s on %s' % (repo_group, group_name)) diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py --- a/kallithea/model/scm.py +++ b/kallithea/model/scm.py @@ -247,7 +247,7 @@ class ScmModel(BaseModel): return cls.get(instance) elif isinstance(instance, basestring): return cls.get_by_repo_name(instance) - elif instance: + elif instance is not None: raise Exception('given object must be int, basestr or Instance' ' of %s got %s' % (type(cls), type(instance))) @@ -340,7 +340,7 @@ class ScmModel(BaseModel): """ CacheInvalidation.set_invalidate(repo_name, delete=delete) repo = Repository.get_by_repo_name(repo_name) - if repo: + if repo is not None: repo.update_changeset_cache() def toggle_following_repo(self, follow_repo_id, user_id): @@ -807,7 +807,7 @@ class ScmModel(BaseModel): repo = self.__get_repo(repo) hist_l.append(['rev:tip', _('latest tip')]) choices.append('rev:tip') - if not repo: + if repo is None: return choices, hist_l repo = repo.scm_instance diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -249,7 +249,7 @@ class UserModel(BaseModel): return user def delete(self, user, cur_user=None): - if not cur_user: + if cur_user is None: cur_user = getattr(get_current_authuser(), 'username', None) user = self._get_user(user) @@ -287,7 +287,7 @@ class UserModel(BaseModel): user_email = data['email'] user = User.get_by_email(user_email) - if user: + if user is not None: log.debug('password reset user found %s' % user) link = h.canonical_url('reset_password_confirmation', key=user.api_key) @@ -316,7 +316,7 @@ class UserModel(BaseModel): user = User.get_by_email(user_email) new_passwd = auth.PasswordGenerator().gen_password( 8, auth.PasswordGenerator.ALPHABETS_BIG_SMALL) - if user: + if user is not None: user.password = auth.get_crypt_password(new_passwd) Session().add(user) Session().commit() @@ -433,7 +433,7 @@ class UserModel(BaseModel): """ user = self._get_user(user) obj = UserEmailMap.query().get(email_id) - if obj: + if obj is not None: self.sa.delete(obj) def add_extra_ip(self, user, ip): diff --git a/kallithea/model/user_group.py b/kallithea/model/user_group.py --- a/kallithea/model/user_group.py +++ b/kallithea/model/user_group.py @@ -253,7 +253,7 @@ class UserGroupModel(BaseModel): obj = UserGroupToPerm.query()\ .filter(UserGroupToPerm.users_group == user_group)\ .filter(UserGroupToPerm.permission == perm).scalar() - if obj: + if obj is not None: self.sa.delete(obj) def grant_user_permission(self, user_group, user, perm): @@ -302,7 +302,7 @@ class UserGroupModel(BaseModel): .filter(UserUserGroupToPerm.user == user)\ .filter(UserUserGroupToPerm.user_group == user_group)\ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm on %s on %s' % (user_group, user)) @@ -351,7 +351,7 @@ class UserGroupModel(BaseModel): .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group)\ .filter(UserGroupUserGroupToPerm.user_group == user_group)\ .scalar() - if obj: + if obj is not None: self.sa.delete(obj) log.debug('Revoked perm on %s on %s' % (target_user_group, user_group)) diff --git a/kallithea/model/validators.py b/kallithea/model/validators.py --- a/kallithea/model/validators.py +++ b/kallithea/model/validators.py @@ -228,7 +228,7 @@ def ValidRepoGroup(edit=False, old_data= .filter(RepoGroup.group_parent_id == group_parent_id)\ .scalar() - if gr: + if gr is not None: msg = M(self, 'group_exists', state, group_name=slug) raise formencode.Invalid(msg, value, state, error_dict=dict(group_name=msg) @@ -239,7 +239,7 @@ def ValidRepoGroup(edit=False, old_data= .filter(Repository.repo_name == slug)\ .scalar() - if repo: + if repo is not None: msg = M(self, 'repo_exists', state, group_name=slug) raise formencode.Invalid(msg, value, state, error_dict=dict(group_name=msg) @@ -715,7 +715,7 @@ def UniqSystemEmail(old_data={}): def validate_python(self, value, state): if (old_data.get('email') or '').lower() != value: user = User.get_by_email(value, case_insensitive=True) - if user: + if user is not None: msg = M(self, 'email_taken', state) raise formencode.Invalid(msg, value, state, error_dict=dict(email=msg)