def give(self, dataset): """ Award a given badge to a given dataset. """ # Get the dataset self._get_dataset(dataset) # Get the badge badge_id = request.params.get('badge', None) badge = Badge.by_id(id=badge_id) if badge: # See if user can award this badge to a this dataset require.badge.give(badge, c.dataset) # Add the dataset to the badge datasets and commit to database badge.datasets.append(c.dataset) db.session.commit() else: # If we don't find the badge id we flash an error message h.flash_error(_('Badge not found.')) # Go to the dataset's main page redirect( h.url_for(controller='dataset', action='view', dataset=c.dataset.name))
def information(self, id, format='html'): """ Show information about the badge. Default is to present the user with the badge on an html site, but the user can request a json representation of the badge """ # Get the badge c.badge = Badge.by_id(id=id) # Return a json representation if the format requested is 'json' if format == 'json': return to_jsonp({"badge": badge_apply_links(c.badge.as_dict())}) # Return html representation return templating.render('badge/information.html')
def give(self, dataset): """ Award a given badge to a given dataset. """ # Get the dataset self._get_dataset(dataset) # Get the badge badge_id = request.params.get('badge', None) badge = Badge.by_id(id=badge_id) if badge: # See if user can award this badge to a this dataset require.badge.give(badge, c.dataset) # Add the dataset to the badge datasets and commit to database badge.datasets.append(c.dataset) db.session.commit() else: # If we don't find the badge id we flash an error message h.flash_error(_('Badge not found.')) # Go to the dataset's main page redirect(h.url_for(controller='dataset', action='view', dataset=c.dataset.name))