diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py index 728f98a1fe2..bf48c4310ea 100644 --- a/ckan/controllers/group.py +++ b/ckan/controllers/group.py @@ -884,39 +884,3 @@ def _get_group_dict(self, id): abort(404, _('Group not found')) except NotAuthorized: abort(401, _('Unauthorized to read group %s') % id) - - def _render_edit_form(self, fs): - # errors arrive in c.error and fs.errors - c.fieldset = fs - return render('group/edit_form.html') - - def _update(self, fs, group_name, group_id): - ''' - Writes the POST data (associated with a group edit) to the database - @input c.error - ''' - validation = fs.validate() - if not validation: - c.form = self._render_edit_form(fs) - raise base.ValidationException(fs) - - try: - fs.sync() - except Exception, inst: - model.Session.rollback() - raise - else: - model.Session.commit() - - def _update_authz(self, fs): - validation = fs.validate() - if not validation: - c.form = self._render_edit_form(fs) - raise base.ValidationException(fs) - try: - fs.sync() - except Exception, inst: - model.Session.rollback() - raise - else: - model.Session.commit() diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index 47a00438833..2b2443a2c43 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -14,7 +14,6 @@ import ckan.logic as logic import ckan.lib.base as base import ckan.lib.maintain as maintain -import ckan.lib.package_saver as package_saver import ckan.lib.i18n as i18n import ckan.lib.navl.dictization_functions as dict_fns import ckan.lib.accept as accept @@ -421,8 +420,6 @@ def read(self, id, format='html'): self._setup_template_variables(context, {'id': id}, package_type=package_type) - package_saver.PackageSaver().render_package(c.pkg_dict, context) - template = self._read_template(package_type) template = template[:template.index('.') + 1] + format diff --git a/ckan/lib/package_saver.py b/ckan/lib/package_saver.py deleted file mode 100644 index d93653c77da..00000000000 --- a/ckan/lib/package_saver.py +++ /dev/null @@ -1,116 +0,0 @@ -import ckan.lib.helpers as h -import ckan.lib.base as base -import ckan.model as model -import ckan.rating - -from ckan.common import g, c, _ - -# Todo: Factor out unused original_name argument. - -class PackageSaver(object): - '''Use this to validate and save packages to the db. - @param log_message: optional - only supply this if you want it validated - @param author: optional - only supply this if you want it validated - ''' - - # TODO: rename to something more correct like prepare_for_render - @classmethod - def render_package(cls, pkg, context): - '''Prepares for rendering a package. Takes a Package object and - formats it for the various context variables required to call - render. - Note that the actual calling of render('package/read') is left - to the caller.''' - c.pkg_notes_formatted = h.render_markdown(pkg.get('notes')) - - c.current_rating, c.num_ratings = ckan.rating.get_rating(context['package']) - url = pkg.get('url', '') - c.pkg_url_link = h.link_to(url, url, rel='foaf:homepage', target='_blank') \ - if url else _("No web page given") - - c.pkg_author_link = cls._person_email_link( - name=pkg.get('author'), email=pkg.get('author_email'), - fallback=_("Author not given")) - c.pkg_maintainer_link = cls._person_email_link( - name=pkg.get('maintainer'), email=pkg.get('maintainer_email'), - fallback=_("Maintainer not given")) - - c.package_relationships = context['package'].get_relationships_printable() - c.pkg_extras = [] - for extra in sorted(pkg.get('extras',[]), key=lambda x:x['key']): - if extra.get('state') == 'deleted': - continue - k, v = extra['key'], extra['value'] - if k in g.package_hide_extras: - continue - if isinstance(v, (list, tuple)): - v = ", ".join(map(unicode, v)) - c.pkg_extras.append((k, v)) - if context.get('revision_id') or context.get('revision_date'): - # request was for a specific revision id or date - c.pkg_revision_id = c.pkg_dict[u'revision_id'] - c.pkg_revision_timestamp = c.pkg_dict[u'revision_timestamp'] - c.pkg_revision_not_latest = c.pkg_dict[u'revision_id'] != c.pkg.revision.id - - @classmethod - def commit_pkg(cls, fs, log_message, author, client=None): - '''Writes the POST data (associated with a package edit) to the - database - @input c.error - @input fs FieldSet with the param data bound to it - ''' - cls._update(fs, log_message, author, client=client) - - @classmethod - def _update(cls, fs, log_message, author, client=None): - # Todo: Consolidate log message field (and validation). - rev = None - # validation - errors = cls._revision_validation(log_message) - if client: - client.errors = errors - fs.validate() - validates = not (errors or fs.errors) - if not validates: - raise base.ValidationException(fs) - # sync - try: - rev = model.repo.new_revision() - rev.author = author - rev.message = log_message - fs.sync() - except Exception: - model.Session.rollback() - raise - else: - # only commit if it validates ok - if validates: - model.Session.commit() - - @classmethod - def _revision_validation(cls, log_message): - errors = [] - if log_message and 'http:' in log_message: - errors.append(_('No links are allowed in the log_message.')) - return errors - - @classmethod - def _person_email_link(cls, name, email, fallback): - if email: - return h.mail_to(email_address=email, name=name or email, - encode='hex') - else: - return name or fallback - -class WritePackageFromBoundFieldset(object): - - def __init__(self, fieldset, log_message='', author='', client=None): - self.fieldset = fieldset - self.log_message = log_message - self.author = author - self.client = None - self.write_package() - - def write_package(self): - PackageSaver().commit_pkg(self.fieldset, self.log_message, self.author, self.client) - diff --git a/ckan/lib/plugins.py b/ckan/lib/plugins.py index 17dda8182d9..420b22354db 100644 --- a/ckan/lib/plugins.py +++ b/ckan/lib/plugins.py @@ -221,6 +221,8 @@ def show_package_schema(self): return ckan.logic.schema.default_show_package_schema() def setup_template_variables(self, context, data_dict): + from ckan.lib.helpers import render_markdown + authz_fn = logic.get_action('group_list_authz') c.groups_authz = authz_fn(context, data_dict) data_dict.update({'available_only': True}) @@ -235,6 +237,12 @@ def setup_template_variables(self, context, data_dict): if c.pkg: c.related_count = c.pkg.related_count + c.pkg_notes_formatted = render_markdown(c.pkg.notes) + + if context.get('revision_id') or context.get('revision_date'): + c.pkg_revision_id = c.pkg_dict[u'revision_id'] + c.pkg_revision_timestamp = c.pkg_dict[u'revision_timestamp'] + c.pkg_revision_not_latest = c.pkg_dict[u'revision_id'] != c.pkg.revision.id ## This is messy as auths take domain object not data_dict context_pkg = context.get('package', None)