Added default orderby to user list

This commit is contained in:
Fergal Moran
2013-06-30 19:41:45 +01:00
parent dfefcea557
commit 76c5e4e878
7 changed files with 20 additions and 99 deletions

View File

@@ -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<resource_name>%s)/(?P<userprofile__slug>[\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<resource_name>%s)/(?P<pk>\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

View File

@@ -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 = '<img src="' + flickrUrl(item) + '"></a>'
UserCollection

View File

@@ -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 = '<img src="' + flickrUrl(item) + '"></a>';
});
};
return UserCollection;
})(DssCollection);

View File

@@ -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()

View File

@@ -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);

View File

@@ -12,4 +12,5 @@
<a href="/user/<%= profile.slug %>/followers"><%= profile.follower_count %></a>
</td>
<td><%= profile.following_count %></td>
<td><%= human_last_login %></td>
<td><%= humanise(date_joined) %></td>
<td><%= humanise(last_login) %></td>

View File

@@ -21,6 +21,7 @@
<th>Favourites</th>
<th>Followers</th>
<th>Following</th>
<th>Join date</th>
<th>Last seen</th>
</tr>
</thead>