[PATCH 3 of 3 v3] UserModel: remove code duplication of User.get_by_username()

Thomas De Schampheleire patrickdepinguin at gmail.com
Wed Jun 3 16:05:55 EDT 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1433173231 -7200
#      Mon Jun 01 17:40:31 2015 +0200
# Node ID 5761677bd62f660cb44a4af44b59881d61f07632
# Parent  6e18642dd51a2257cd0e8d05926a9244b37e0a70
UserModel: remove code duplication of User.get_by_username()

UserModel.get_by_username() and User.get_by_username() implement the same
logic and thus one should use the other instead of duplicating.

diff --git a/kallithea/model/user.py b/kallithea/model/user.py
--- a/kallithea/model/user.py
+++ b/kallithea/model/user.py
@@ -60,16 +60,7 @@ class UserModel(BaseModel):
         return self._get_user(user)
 
     def get_by_username(self, username, cache=False, case_insensitive=False):
-
-        if case_insensitive:
-            user = self.sa.query(User).filter(User.username.ilike(username))
-        else:
-            user = self.sa.query(User)\
-                .filter(User.username == username)
-        if cache:
-            user = user.options(FromCache("sql_cache_short",
-                                          "get_user_%s" % username))
-        return user.scalar()
+        return User.get_by_username(username, case_insensitive, cache)
 
     def get_by_email(self, email, cache=False, case_insensitive=False):
         return User.get_by_email(email, case_insensitive, cache)


More information about the kallithea-general mailing list