Repository: OCHA-DAP/hdx-ckan

Issue:
Organization Page: Last modified option should sort in reverse
Current version sorts oldest to newest, but should be newest to oldest.

![image](https://cloud.githubusercontent.com/assets/1654485/3243343/242e53c2-f157-11e3-880c-52b20a00be0e.png)



Discussion:

Resolving patch:
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/splash_page.py b/ckanext-hdx_theme/ckanext/hdx_theme/splash_page.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/splash_page.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/splash_page.py
@@ -20,86 +20,93 @@
 
 class SplashPageController(HomeController):
 
-	group_type = 'group'
-
-	def index(self):
-		group_type = None
-		context = {'model': model, 'session': model.Session,
-				   'user': c.user or c.author, 'for_view': True,
-				   'with_private': False}
-
-		q = c.q = request.params.get('q', '')
-		data_dict = {'all_fields': True, 'q': q}
-		sort_by = c.sort_by_selected = request.params.get('sort')
-		if sort_by:
-			data_dict['sort'] = sort_by
-		try:
-			self._check_access('site_read', context)
-		except NotAuthorized:
-			abort(401, _('Not authorized to see this page'))
-		if c.userobj:
-			context['user_id'] = c.userobj.id
-			context['user_is_admin'] = c.userobj.sysadmin
-		
-		
-		
-		c.group_package_stuff = caching.cached_get_group_package_stuff()
-
-		##Removing groups without geojson for the map
-		c.group_map = []
-		for gp in c.group_package_stuff:
-			for e in gp['extras']:
-				if e['key'] == 'geojson' and e['value']:
-					c.group_map.append(gp)
-
-		#print c.group_package_stuff
-
-		if c.userobj is not None:
-			msg = None
-			url = h.url_for(controller='user', action='edit')
-			is_google_id = \
-				c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
-			if not c.userobj.email and (is_google_id and not c.userobj.fullname):
-				msg = _(u'Please <a href="{link}">update your profile</a>'
-						u' and add your email address and your full name. '
-						u'{site} uses your email address'
-						u' if you need to reset your password.'.format(
-							link=url, site=g.site_title))
-			elif not c.userobj.email:
-				msg = _('Please <a href="%s">update your profile</a>'
-						' and add your email address. ') % url + \
-					_('%s uses your email address'
-						' if you need to reset your password.') \
-					% g.site_title
-			elif is_google_id and not c.userobj.fullname:
-				msg = _('Please <a href="%s">update your profile</a>'
-						' and add your full name.') % (url)
-			if msg:
-				h.flash_notice(msg, allow_html=True)
-
-		return base.render('home/index.html', cache_force=True)
-
-	def _check_access(self, action_name, *args, **kw):
-		''' select the correct group/org check_access '''
-		return check_access(self._replace_group_org(action_name), *args, **kw)
-
-	def _replace_group_org(self, string):
-		''' substitute organization for group if this is an org'''
-		if self.group_type == 'organization':
-			string = re.sub('^group', 'organization', string)
-		return string
-
-	def _action(self, action_name):
-		''' select the correct group/org action '''
-		return get_action(self._replace_group_org(action_name))
-
-	def about(self, page):
-		title = {'license': _('Data Licenses'),
-				 'terms': _('Terms of Service')}
-		html =  {'license': 'home/snippets/hdx_licenses.html',
-				 'terms': 'home/snippets/hdx_terms_of_service.html'}
-
-		extraVars = {'title': title.get(page), 'html': html.get(page), 'page': page}
-		return base.render('home/about2.html',  extra_vars = extraVars)
+    group_type = 'group'
+
+    def index(self):
+        group_type = None
+        context = {'model': model, 'session': model.Session,
+                   'user': c.user or c.author, 'for_view': True,
+                   'with_private': False}
+
+        q = c.q = request.params.get('q', '')
+        data_dict = {'all_fields': True, 'q': q}
+        sort_by = c.sort_by_selected = request.params.get('sort')
+        if sort_by:
+            data_dict['sort'] = sort_by
+        try:
+            self._check_access('site_read', context)
+        except NotAuthorized:
+            abort(401, _('Not authorized to see this page'))
+        if c.userobj:
+            context['user_id'] = c.userobj.id
+            context['user_is_admin'] = c.userobj.sysadmin
+
+
+
+        c.group_package_stuff = caching.cached_get_group_package_stuff()
+
+        ##Removing groups without geojson for the map
+        c.group_map = []
+        for gp in c.group_package_stuff:
+            for e in gp['extras']:
+                if e['key'] == 'geojson' and e['value']:
+                    c.group_map.append(gp)
+
+        #print c.group_package_stuff
+
+        if c.userobj is not None:
+            msg = None
+            url = h.url_for(controller='user', action='edit')
+            is_google_id = \
+                c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
+            if not c.userobj.email and (is_google_id and not c.userobj.fullname):
+                msg = _(u'Please <a href="{link}">update your profile</a>'
+                        u' and add your email address and your full name. '
+                        u'{site} uses your email address'
+                        u' if you need to reset your password.'.format(
+                            link=url, site=g.site_title))
+            elif not c.userobj.email:
+                msg = _('Please <a href="%s">update your profile</a>'
+                        ' and add your email address. ') % url + \
+                    _('%s uses your email address'
+                        ' if you need to reset your password.') \
+                    % g.site_title
+            elif is_google_id and not c.userobj.fullname:
+                msg = _('Please <a href="%s">update your profile</a>'
+                        ' and add your full name.') % (url)
+            if msg:
+                h.flash_notice(msg, allow_html=True)
+
+        return base.render('home/index.html', cache_force=True)
+
+    def _check_access(self, action_name, *args, **kw):
+        ''' select the correct group/org check_access '''
+        return check_access(self._replace_group_org(action_name), *args, **kw)
+
+    def _replace_group_org(self, string):
+        ''' substitute organization for group if this is an org'''
+        if self.group_type == 'organization':
+            string = re.sub('^group', 'organization', string)
+        return string
+
+    def _action(self, action_name):
+        ''' select the correct group/org action '''
+        return get_action(self._replace_group_org(action_name))
+
+    def about(self, page):
+        title = {'license': _('Data Licenses'),
+                 'terms': _('Terms of Service')}
+        html =  {'license': 'home/snippets/hdx_licenses.html',
+                 'terms': 'home/snippets/hdx_terms_of_service.html'}
+
+        titleItem = title.get(page)
+        htmlItem = html.get(page)
+
+        if titleItem is None:
+            message=_("The requested about page doesn't exist")
+            raise logic.ValidationError({'message': message}, error_summary=message)
+
+        extraVars = {'title': titleItem, 'html': htmlItem, 'page': page}
+        return base.render('home/about2.html',  extra_vars = extraVars)
 
 
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/version.py b/ckanext-hdx_theme/ckanext/hdx_theme/version.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/version.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/version.py
@@ -1 +1 @@
-hdx_version='v0.2.4'
\ No newline at end of file
+hdx_version='v0.2.6'
\ No newline at end of file


Test patch:
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_about_page_controller.py b/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_about_page_controller.py
new file mode 100644
--- /dev/null
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_about_page_controller.py
@@ -0,0 +1,81 @@
+import ckan
+import ckan.logic as logic
+import ckan.tests as tests
+import webtest
+import ckan.lib.helpers as h
+import ckan.lib.create_test_data as ctd
+import ckan.lib.search as search
+import ckan.model as model
+import unicodedata
+from ckan.config.middleware import make_app
+from pylons import config
+
+def _get_test_app():
+    config['ckan.legacy_templates'] = False
+    app = ckan.config.middleware.make_app(config['global_conf'], **config)
+    app = webtest.TestApp(app)
+    return app
+
+def _load_plugin(plugin):
+    plugins = set(config['ckan.plugins'].strip().split())
+    plugins.add(plugin.strip())
+    config['ckan.plugins'] = ' '.join(plugins)
+
+class TestAboutPageController(object):
+
+    @classmethod
+    def setup_class(cls):
+        cls.original_config = config.copy()
+
+        _load_plugin('hdx_theme')
+        cls.app = _get_test_app()
+
+        search.clear()
+        model.Session.remove()
+        ctd.CreateTestData.create()
+
+
+
+    @classmethod
+    def teardown_class(cls):
+        model.Session.remove()
+        model.repo.rebuild_db()
+
+        config.clear()
+        config.update(cls.original_config)
+
+    def test_resulting_page(self):
+        testsysadmin = model.User.by_name('testsysadmin')
+
+        page = self._getAboutPage('license')
+        assert 'Data Licenses' in str(page.response), 'the url /about/license should redirect to the Data Licenses page when no user is logged in'
+        page = self._getAboutPage('license', testsysadmin.apikey)
+        assert 'Data Licenses' in str(page.response), 'the url /about/license should redirect to the Data Licenses page, even when the user is logged in'
+
+        page = self._getAboutPage('terms')
+        assert 'Terms of Service' in str(page.response), 'the url /about/terms should redirect to the Terms of Service page when no user is logged in'
+        page = self._getAboutPage('terms', testsysadmin.apikey)
+        assert 'Terms of Service' in str(page.response), 'the url /about/terms should redirect to the Terms of Service page, even when the user is logged in'
+
+        try:
+            page = self._getAboutPage('fake')
+            assert "The requested about page doesn't exist" in str(page.response), 'the url /about/fake should throw an error when no user is logged in'
+        except logic.ValidationError:
+            assert True
+
+        try:
+            page = self._getAboutPage('fake', testsysadmin.apikey)
+            assert "The requested about page doesn't exist" in str(page.response), 'the url /about/terms should throw an error, even when the user is logged in'
+        except logic.ValidationError:
+            assert True
+
+
+    def _getAboutPage(self, page, apikey=None):
+        url = '/about/' + page
+        if apikey:
+            page = self.app.get(url,headers={'Authorization':unicodedata.normalize('NFKD', apikey).encode('ascii','ignore')})
+        else:
+            page = self.app.get(url)
+        return page
+
+
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_dataset_output.py b/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_dataset_output.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_dataset_output.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/tests/test_ui/test_dataset_output.py
@@ -9,13 +9,9 @@
 import ckan.tests as tests
 import webtest
 import ckan.lib.helpers as h
-import ckan.plugins as p
-import ckan.lib.plugins as pl
 import ckan.lib.create_test_data as ctd
 import ckan.lib.search as search
 import ckan.model as model
-import ckan.plugins.toolkit as tk
-import ckanext.metadata_fields.plugin as thisplugin
 import unicodedata
 
 from ckan.config.middleware import make_app