Changeset - 4eef5eeb81a3
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2012-08-07 23:02:50
marcin@python-works.com
fixed sorting by last_login in users admin page
4 files changed with 22 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/users.py
Show inline comments
 
@@ -44,12 +44,13 @@ import rhodecode
 
from rhodecode.model.db import User, Permission, UserEmailMap
 
from rhodecode.model.forms import UserForm
 
from rhodecode.model.user import UserModel
 
from rhodecode.model.meta import Session
 
from rhodecode.lib.utils import action_logger
 
from rhodecode.lib.compat import json
 
from rhodecode.lib.utils2 import datetime_to_time
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class UsersController(BaseController):
 
    """REST Controller styled on the Atom Publishing Protocol"""
 
@@ -86,19 +87,21 @@ class UsersController(BaseController):
 

	
 
        user_actions = lambda user_id, username: (
 
                template.get_def("user_actions")
 
                .render(user_id, username, _=_, h=h, c=c))
 

	
 
        for user in c.users_list:
 

	
 
            users_data.append({
 
                "gravatar": grav_tmpl(user. email, 24),
 
                "raw_username": user.username,
 
                "username": user_lnk(user.user_id, user.username),
 
                "firstname": user.name,
 
                "lastname": user.lastname,
 
                "last_login": h.fmt_date(user.last_login),
 
                "last_login_raw": datetime_to_time(user.last_login),
 
                "active": h.bool2icon(user.active),
 
                "admin": h.bool2icon(user.admin),
 
                "ldap": h.bool2icon(bool(user.ldap_dn)),
 
                "action": user_actions(user.user_id, user.username),
 
            })
 

	
rhodecode/lib/utils2.py
Show inline comments
 
@@ -21,12 +21,13 @@
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import re
 
import time
 
from datetime import datetime
 
from pylons.i18n.translation import _, ungettext
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 

	
 

	
 
def __get_lem():
 
@@ -426,12 +427,17 @@ def get_changeset_safe(repo, rev):
 
        cs = repo.get_changeset(rev)
 
    except RepositoryError:
 
        cs = EmptyChangeset(requested_revision=rev)
 
    return cs
 

	
 

	
 
def datetime_to_time(dt):
 
    if dt:
 
        return time.mktime(dt.timetuple())
 

	
 

	
 
MENTIONS_REGEX = r'(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)(?:\s{1})'
 

	
 

	
 
def extract_mentioned_users(s):
 
    """
 
    Returns unique usernames from given string s that have @mention
 
@@ -441,11 +447,12 @@ def extract_mentioned_users(s):
 
    usrs = set()
 
    for username in re.findall(MENTIONS_REGEX, s):
 
        usrs.add(username)
 

	
 
    return sorted(list(usrs), key=lambda k: k.lower())
 

	
 

	
 
class AttributeDict(dict):
 
    def __getattr__(self, attr):
 
        return self.get(attr, None)
 
    __setattr__ = dict.__setitem__
 
    __delattr__ = dict.__delitem__
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -1526,12 +1526,21 @@ var ageSort = function(a, b, desc, field
 
    
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var lastLoginSort = function(a, b, desc, field) {
 
	var a_ = a.getData('last_login_raw') || 0;
 
    var b_ = b.getData('last_login_raw') || 0;
 
    
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var nameSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 

	
 
    // extract name from table
 
    a_ = get_name(a_)
rhodecode/templates/admin/users/users.html
Show inline comments
 
@@ -41,12 +41,13 @@
 
          {key: "gravatar"},
 
          {key: "raw_username"},
 
          {key: "username"},
 
          {key: "firstname"},
 
          {key: "lastname"},
 
          {key: "last_login"},
 
          {key: "last_login_raw"},
 
          {key: "active"},
 
          {key: "admin"},
 
          {key: "ldap"},
 
          {key: "action"},
 
      ]
 
   };
 
@@ -75,13 +76,14 @@
 
      {key:"gravatar",label:"",sortable:false,},
 
      {key:"username",label:"${_('username')}",sortable:true,
 
    	  sortOptions: { sortFunction: linkSort }
 
      },
 
      {key:"firstname",label:"${_('firstname')}",sortable:true,},
 
      {key:"lastname",label:"${_('lastname')}",sortable:true,},
 
      {key:"last_login",label:"${_('last login')}",sortable:true,},
 
      {key:"last_login",label:"${_('last login')}",sortable:true,
 
    	  sortOptions: { sortFunction: lastLoginSort }},
 
      {key:"active",label:"${_('active')}",sortable:true,},
 
      {key:"admin",label:"${_('admin')}",sortable:true,},
 
      {key:"ldap",label:"${_('ldap')}",sortable:true,},
 
      {key:"action",label:"${_('action')}",sortable:false},
 
  ];
 

	
0 comments (0 inline, 0 general)