def edit(request, site, version): active_site = Site.objects.filter( id=site, ).select_related( 'forening', ).prefetch_related( # This is a bit backwards; based on our current active site, fetch the forening owning the site, and then # refetch *all* sites related to that forening - this will be used when rendering the template layout; for # example here: https://github.com/Turistforeningen/sherpa/blob/5d33684/templates/local/layout.html#L151 # (Note that we're faking the request site below) 'forening__sites', ).get() try: version = Version.objects.filter( id=version, page__site=active_site, ).prefetch_related( 'rows', 'rows__columns', 'rows__columns__contents', 'tags', ).select_related( 'page', 'page__parent', ).get() except Version.DoesNotExist: messages.error(request, 'version_does_not_exist') return redirect('admin:sites.pages.page.list', active_site.id) context = { 'active_site': active_site, 'version': version, 'widget_data': admin_context(active_site), 'image_search_length': settings.IMAGE_SEARCH_LENGTH, 'preview_context': True, # To prevent counting ad view. Should probably introduce `editor_context` instead } context.update(url_picker_context(active_site)) # Fake request.site to the edited site; this will make context processors behave accordingly request.site = active_site return render(request, 'central/admin/sites/pages/edit.html', context)
def edit(request, site, version): try: active_site = Site.get_cached_by_id(site) version = Version.objects.get(id=version) users = sorted(User.sherpa_users(), key=lambda u: u.get_first_name()) context = { 'active_site': active_site, 'version': version, 'users': users, 'image_search_length': settings.IMAGE_SEARCH_LENGTH, 'widget_data': admin_context(active_site), 'category_choices': Article.CATEGORY_CHOICES, } context.update(url_picker_context(active_site)) # Fake request.site to the edited site; this will make context processors behave accordingly request.site = active_site return render(request, 'central/admin/sites/articles/edit.html', context) except Version.DoesNotExist: messages.warning(request, 'article_does_not_exist') return redirect('admin:sites.articles.list', active_site.id)