diff --git a/spa/api/v1/UserResource.py b/spa/api/v1/UserResource.py index 423e7bc..273a544 100755 --- a/spa/api/v1/UserResource.py +++ b/spa/api/v1/UserResource.py @@ -24,6 +24,8 @@ class UserProfileResource(BackboneCompatibleResource): always_return_data = True authorization = DjangoAuthorization() authentication = Authentication() + order_by = "-last_login" + ordering = ["-last_login"] def _hydrateBitmapOption(self, source, comparator): return True if (source & comparator) != 0 else False @@ -95,7 +97,7 @@ class UserResource(BackboneCompatibleResource): profile = fields.ToOneField(UserProfileResource, attribute='userprofile', related_name='user', full=True) class Meta: - queryset = User.objects.all() + queryset = User.objects.all().order_by('-last_login') resource_name = 'user' excludes = ['is_active', 'is_staff', 'is_superuser', 'password'] authorization = DjangoAuthorization() @@ -105,7 +107,7 @@ class UserResource(BackboneCompatibleResource): def prepend_urls(self): return [ url(r"^(?P%s)/(?P[\w\d_.-]+)/favourites%s$" % ( - self._meta.resource_name, trailing_slash()), + self._meta.resource_name, trailing_slash()), self.wrap_view('get_user_favourites'), name="api_get_user_favourites"), url(r"^(?P%s)/(?P\d+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"), @@ -133,5 +135,4 @@ class UserResource(BackboneCompatibleResource): del bundle.data['email'] del bundle.data['username'] - bundle.data['human_last_login'] = humanize.naturaltime(bundle.obj.last_login.replace(tzinfo=None)) return bundle diff --git a/static/js/app/models/user/userCollection.coffee b/static/js/app/models/user/userCollection.coffee index d2ebc68..3cd3ad0 100755 --- a/static/js/app/models/user/userCollection.coffee +++ b/static/js/app/models/user/userCollection.coffee @@ -7,48 +7,5 @@ define ['backbone', 'models/user/userItem', 'app.lib/backbone.dss.model.collecti url: -> com.podnoms.settings.urlRoot + "user/?limit=" + @limit + "&offset=" + @page * @limit - _columns: [ - property: 'last_login' - label: 'Name' - sortable: true - , - property: 'uploads' - label: 'Uploads' - sortable: true - , - property: 'likes' - label: 'Likes' - sortable: true - , - property: 'favourites' - label: 'Favourites' - sortable: true - , - property: 'followers' - label: 'Followers' - sortable: true - , - property: 'following' - label: 'Following' - sortable: true - , - property: 'lastseen' - label: 'Last seen' - sortable: true - ] - - columns: -> - console.log("UserCollection: columns") - @_columns - - data: -> - console.log("UserCollection: data") - @toJSON() - - formatter: (items) -> - console.log("UserCollection: formatter") - $.each items, (index, item) -> - item.image = '' - UserCollection diff --git a/static/js/app/models/user/userCollection.js b/static/js/app/models/user/userCollection.js index ecf52c0..1681d0f 100755 --- a/static/js/app/models/user/userCollection.js +++ b/static/js/app/models/user/userCollection.js @@ -23,55 +23,6 @@ return com.podnoms.settings.urlRoot + "user/?limit=" + this.limit + "&offset=" + this.page * this.limit; }; - UserCollection.prototype._columns = [ - { - property: 'last_login', - label: 'Name', - sortable: true - }, { - property: 'uploads', - label: 'Uploads', - sortable: true - }, { - property: 'likes', - label: 'Likes', - sortable: true - }, { - property: 'favourites', - label: 'Favourites', - sortable: true - }, { - property: 'followers', - label: 'Followers', - sortable: true - }, { - property: 'following', - label: 'Following', - sortable: true - }, { - property: 'lastseen', - label: 'Last seen', - sortable: true - } - ]; - - UserCollection.prototype.columns = function() { - console.log("UserCollection: columns"); - return this._columns; - }; - - UserCollection.prototype.data = function() { - console.log("UserCollection: data"); - return this.toJSON(); - }; - - UserCollection.prototype.formatter = function(items) { - console.log("UserCollection: formatter"); - return $.each(items, function(index, item) { - return item.image = ''; - }); - }; - return UserCollection; })(DssCollection); diff --git a/static/js/app/views/user/userItemView.coffee b/static/js/app/views/user/userItemView.coffee index fa8f0d3..e2535e4 100755 --- a/static/js/app/views/user/userItemView.coffee +++ b/static/js/app/views/user/userItemView.coffee @@ -1,5 +1,9 @@ -define ['app', 'marionette', 'text!/tpl/UserListItemView'], -(App, Marionette, Template)-> +define ['app', 'moment', 'marionette', 'text!/tpl/UserListItemView'], +(App, moment, Marionette, Template)-> class UserItemView extends Marionette.ItemView template: _.template(Template) tagName: "tr" + + templateHelpers: + humanise: (date)-> + moment(date).fromNow() diff --git a/static/js/app/views/user/userItemView.js b/static/js/app/views/user/userItemView.js index 90cc31d..0f70759 100755 --- a/static/js/app/views/user/userItemView.js +++ b/static/js/app/views/user/userItemView.js @@ -3,7 +3,7 @@ var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - define(['app', 'marionette', 'text!/tpl/UserListItemView'], function(App, Marionette, Template) { + define(['app', 'moment', 'marionette', 'text!/tpl/UserListItemView'], function(App, moment, Marionette, Template) { var UserItemView; return UserItemView = (function(_super) { @@ -17,6 +17,12 @@ UserItemView.prototype.tagName = "tr"; + UserItemView.prototype.templateHelpers = { + humanise: function(date) { + return moment(date).fromNow(); + } + }; + return UserItemView; })(Marionette.ItemView); diff --git a/templates/views/UserListItemView.html b/templates/views/UserListItemView.html index ec0b6c9..b547d78 100755 --- a/templates/views/UserListItemView.html +++ b/templates/views/UserListItemView.html @@ -12,4 +12,5 @@ <%= profile.follower_count %> <%= profile.following_count %> -<%= human_last_login %> +<%= humanise(date_joined) %> +<%= humanise(last_login) %> diff --git a/templates/views/UserListView.html b/templates/views/UserListView.html index 5044ef0..761b034 100755 --- a/templates/views/UserListView.html +++ b/templates/views/UserListView.html @@ -21,6 +21,7 @@ Favourites Followers Following + Join date Last seen