This PR is mainly to create a new view of rankings for a given community.
But I added some cool stuff that can serve others :
ranking code has been moved from the view to the Community model (sorry I discovered the get_stat method too late and anyways it doesn't do the same thing even if it's similar)
created a ranking method in the Community model to get the ranking data as a dict
this ranking method is served as a JSON on the url : /community/<slug>/ranking_api/?before_time=2021-1-1&after_time=2022-1-1 (yes it's a GET not a POST like the previous one, it made more sense I think since no data is modified.
Since we needed a datatable and needing a datatable seems something we want often, I created a datatable helper, details below.
Datatable helper
You can now add a datatable for your data very easily :)
Data provider
First you need to deliver data on an endpoint and the data need to have the form :
Next you need to prepare the datatable configuration in your view.py, with the following keys :
context = {
'datatable_config':{
'columns':[ # name (what is displayed) and key (the key name) of your columns
{ "title":"Column 1", "key":"col1"},
{ "title":"Column 2", "key":"col2"},
{ "title":"Column 3", "key":"col3"}
],
'id':'my_beautiful_table_id', # id you want for your datatable
'url':f'/my/data/provider' # where to fetch the data json
}
}
Template
Finally in the template you can use the datatable tag that will put all what is necessary (html and js) :
And this datatable is accessible via a small lib osr_datatable_loader as an object of window. For example you can change the source of the data by giving a new url :
This PR is mainly to create a new view of rankings for a given community.
But I added some cool stuff that can serve others :
get_stat
method too late and anyways it doesn't do the same thing even if it's similar)ranking
method in theCommunity
model to get the ranking data as a dict/community/<slug>/ranking_api/?before_time=2021-1-1&after_time=2022-1-1
(yes it's aGET
not aPOST
like the previous one, it made more sense I think since no data is modified.Datatable helper
You can now add a datatable for your data very easily :)
Data provider
First you need to deliver data on an endpoint and the data need to have the form :
controller
Next you need to prepare the datatable configuration in your view.py, with the following keys :
Template
Finally in the template you can use the datatable tag that will put all what is necessary (html and js) :
JS lib
And this datatable is accessible via a small lib
osr_datatable_loader
as an object of window. For example you can change the source of the data by giving a new url :