Skip to content

Commit

Permalink
Added default list order #37
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Oct 16, 2013
1 parent 7b733a1 commit f92f4b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/detective/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def __init__(self, api_name=None):
# Register relationships fields automaticly
self.generate_to_many_fields(True)

def apply_sorting(self, obj_list, options=None):
options_copy = options.copy()
# No failling sorting,
if "order_by" in options and not options["order_by"] in self.fields:
# remove invalid order_by key
options_copy.pop("order_by", None)
return super(IndividualResource, self).apply_sorting(obj_list, options_copy)


def build_schema(self):
"""
Description and scope for each Resource
Expand Down
6 changes: 5 additions & 1 deletion app/static/detective/js/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ detective = angular
templateUrl: "/partial/contribute.html"
auth: true
# Resolve the Summary service before load this page
resolve: data: (Summary)-> Summary.get("forms")
resolve: data: (Summary)-> Summary.get(id: "forms")
})
.when('/:scope', {
controller: ExploreCtrl
Expand All @@ -62,12 +62,16 @@ detective = angular
templateUrl: "/partial/individual-list.html"
reloadOnSearch: false
auth: true
# Resolve the Summary service before load this page
resolve: data: (Summary)-> Summary.get(id: "forms")
})
.when('/:scope/:type/:id', {
controller: IndividualSingleCtrl
templateUrl: "/partial/individual-single.html"
reloadOnSearch: false
auth: true
# Resolve the Summary service before load this page
resolve: data: (Summary)-> Summary.get(id: "forms")
})
.otherwise redirectTo: '/404'
]
Expand Down
5 changes: 3 additions & 2 deletions app/static/detective/js/controllers/IndividualListCtrl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class IndividualListCtrl
getVerbose: =>
# Get meta information for this type
@Summary.get id: "forms", (data)=>
meta = data[@scope.type.toLowerCase()]
@scope.meta = meta = data[@scope.type.toLowerCase()]
if meta?
@scope.verbose_name = meta.verbose_name
@scope.verbose_name_plural = meta.verbose_name_plural
Expand All @@ -63,7 +63,8 @@ class IndividualListCtrl
type : @scope.type
scope : @scope.scope
limit : @scope.limit
offset : (@scope.page-1)*@scope.limit
offset : (@scope.page-1)*@scope.limit
order_by: "name"

singleUrl: (individual)=>
type = (@scope.type or individual.model).toLowerCase()
Expand Down

0 comments on commit f92f4b8

Please sign in to comment.