---
# System prepended metadata

title: 'OD-1365: Statistics link in footer causes internal server error'

---

# OD-1365: Statistics link in footer causes internal server error

The stats plugin is part of core ckan and has changed since ckan 2.8. The main difference being that ckan 2.9 doesn't support revisions in the database, but some of the functions previously used in the stats plugin used ckan revisions.

Firstly, these are the stats that the ed extension was using:

***These are still available, and just need to be called without the context `c` as they are now passed as template variables: https://github.com/ckan/ckan/blob/ckan-2.9.5/ckanext/stats/blueprint.py#L15-L20 .***
```python=
c.top_rated_packages
c.largest_groups
c.top_tags
c.top_package_creators
```
***These are no longer being offered in ckan 2.9.x as they depended on revisions: https://github.com/ckan/ckan/blob/ckan-2.8.8/ckanext/stats/stats.py#L120-L372***
```python=
c.raw_packages_by_week
c.raw_all_package_revisions
c.raw_new_datasets
c.most_edited_packages
```

These are all the functions that were available for the stats plugin in ckan 2.8: https://github.com/ckan/ckan/blob/ckan-2.8.8/ckanext/stats/controller.py#L15-L39 they are exposed to the html template using the context `c`. We only need the 8 listed above, but they depend on other functions, so we might need to add implementations for all these if we want to continue using them.
```python=
c.top_rated_packages ✔️
c.largest_groups ✔️
c.top_tags ✔️
c.top_package_creators ✔️
c.most_edited_packages
c.new_packages_by_week
c.deleted_packages_by_week
c.num_packages_by_week
c.package_revisions_by_week
c.raw_packages_by_week
c.all_package_revisions
c.raw_all_package_revisions
c.new_datasets
c.raw_new_datasets
c.new_packages_by_week
```

## Required changes

### Edit the html template
To get the stats working with the ed portal, the only thing needed is to enable the stats plugin by adding `stats` to `ckan.plugins` and then removing the `c.` from these lines:
* [ ] [Line 85](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L85): replace `c.top_rated_packages` with `top_rated_packages`.
* [ ] [Line 95](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L95): replace `c.top_rated_packages` with `top_rated_packages`.
* [ ] [Line 135](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L135): replace `c.largest_groups` with `largest_groups`.
* [ ] [Line 144](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L144): replace `c.largest_groups` with `largest_groups`.
* [ ] [Line 167](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L167): replace `c.top_tags` with `top_tags`.
* [ ] [Line 187](https://github.com/CivicActions/ckanext-ed/blob/v2.8.2-nc/ckanext/ed/templates/ckanext/stats/index.html#L187): replace `c.top_package_creators` with `top_package_creators`.

These are how the working pages look when fixed:

**top_package_creators**:

![](https://i.imgur.com/pcnQ77s.png)

**top_tags**:

![](https://i.imgur.com/v8AvykT.png)

**largest_groups**

![](https://i.imgur.com/V3a06Lw.png)


The same would also need to be done for the other functions when they are fixed


### Fix the revision methods

The methods defined here: https://github.com/ckan/ckan/blob/ckan-2.8.8/ckanext/stats/stats.py#L120-L372 would have to be refactored to get their data from ckan activities instead or directly from the db using the model commands.
We would need to override the stats blueprint in our ed extension to enable these commands: https://github.com/ckan/ckan/blob/ckan-2.9.5/ckanext/stats/blueprint.py