changeset 8723:247de7d8efb6

lib: move fmt_date to utils2 - less use of helpers in model
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 30 Oct 2020 14:56:50 +0100
parents 5dfb757197c9
children 7e7489e1672d
files kallithea/controllers/admin/users.py kallithea/controllers/feed.py kallithea/lib/helpers.py kallithea/lib/utils2.py kallithea/model/notification.py
diffstat 5 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/users.py	Thu Oct 29 15:51:01 2020 +0100
+++ b/kallithea/controllers/admin/users.py	Fri Oct 30 14:56:50 2020 +0100
@@ -44,7 +44,7 @@
 from kallithea.lib.base import BaseController, IfSshEnabled, render
 from kallithea.lib.exceptions import DefaultUserException, UserCreationError, UserOwnsReposException
 from kallithea.lib.utils import action_logger
-from kallithea.lib.utils2 import datetime_to_time, generate_api_key, safe_int
+from kallithea.lib.utils2 import datetime_to_time, fmt_date, generate_api_key, safe_int
 from kallithea.lib.webutils import url
 from kallithea.model import db, meta
 from kallithea.model.api_key import ApiKeyModel
@@ -90,7 +90,7 @@
                 "username": username(user.user_id, user.username),
                 "firstname": webutils.escape(user.name),
                 "lastname": webutils.escape(user.lastname),
-                "last_login": h.fmt_date(user.last_login),
+                "last_login": fmt_date(user.last_login),
                 "last_login_raw": datetime_to_time(user.last_login),
                 "active": h.boolicon(user.active),
                 "admin": h.boolicon(user.admin),
--- a/kallithea/controllers/feed.py	Thu Oct 29 15:51:01 2020 +0100
+++ b/kallithea/controllers/feed.py	Fri Oct 30 14:56:50 2020 +0100
@@ -40,7 +40,7 @@
 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 from kallithea.lib.base import BaseRepoController
 from kallithea.lib.diffs import DiffProcessor
-from kallithea.lib.utils2 import asbool, safe_int, safe_str, shorter
+from kallithea.lib.utils2 import asbool, fmt_date, safe_int, safe_str, shorter
 
 
 log = logging.getLogger(__name__)
@@ -58,7 +58,7 @@
 
     def __get_desc(self, cs):
         desc_msg = [(_('%s committed on %s')
-                     % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>']
+                     % (h.person(cs.author), fmt_date(cs.date))) + '<br/>']
         # branches, tags, bookmarks
         for branch in cs.branches:
             desc_msg.append('branch: %s<br/>' % branch)
--- a/kallithea/lib/helpers.py	Thu Oct 29 15:51:01 2020 +0100
+++ b/kallithea/lib/helpers.py	Fri Oct 30 14:56:50 2020 +0100
@@ -38,7 +38,8 @@
 from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE
 from kallithea.lib.markup_renderer import url_re
 from kallithea.lib.pygmentsutils import get_custom_lexer
-from kallithea.lib.utils2 import MENTIONS_REGEX, AttributeDict, age, asbool, credentials_filter, safe_bytes, safe_int, safe_str, shorter, time_to_datetime
+from kallithea.lib.utils2 import (MENTIONS_REGEX, AttributeDict, age, asbool, credentials_filter, fmt_date, safe_bytes, safe_int, safe_str, shorter,
+                                  time_to_datetime)
 from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
 #==============================================================================
@@ -80,6 +81,7 @@
 assert HasRepoPermissionLevel
 # from utils2
 assert age
+assert fmt_date
 assert shorter
 assert time_to_datetime
 # from vcs
@@ -419,12 +421,6 @@
         return raw_id
 
 
-def fmt_date(date):
-    if date:
-        return date.strftime("%Y-%m-%d %H:%M:%S")
-    return ""
-
-
 def is_git(repository):
     if hasattr(repository, 'alias'):
         _type = repository.alias
--- a/kallithea/lib/utils2.py	Thu Oct 29 15:51:01 2020 +0100
+++ b/kallithea/lib/utils2.py	Fri Oct 30 14:56:50 2020 +0100
@@ -265,6 +265,12 @@
     return _('just now')
 
 
+def fmt_date(date):
+    if date:
+        return date.strftime("%Y-%m-%d %H:%M:%S")
+    return ""
+
+
 def uri_filter(uri):
     """
     Removes user:password from given url string
--- a/kallithea/model/notification.py	Thu Oct 29 15:51:01 2020 +0100
+++ b/kallithea/model/notification.py	Fri Oct 30 14:56:50 2020 +0100
@@ -33,6 +33,7 @@
 from tg import tmpl_context as c
 from tg.i18n import ugettext as _
 
+from kallithea.lib.utils2 import fmt_date
 from kallithea.model import db
 
 
@@ -102,7 +103,7 @@
             headers['References'] = ' '.join('<%s>' % x for x in email_kwargs['threading'])
 
         # this is passed into template
-        created_on = h.fmt_date(datetime.datetime.now())
+        created_on = fmt_date(datetime.datetime.now())
         html_kwargs = {
                   'subject': subject,
                   'body': h.render_w_mentions(body, repo_name),