Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wardi/django-page-cms
base: 671d3eaa52
...
head fork: wardi/django-page-cms
compare: 7f7f0c4d97
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
22 pages/admin/actions.py
@@ -5,6 +5,7 @@
from django.template.response import TemplateResponse
from django.conf import settings as global_settings
from django.db import transaction
+from django.shortcuts import redirect
from pages import settings
from pages.http import get_language_from_request
@@ -32,14 +33,15 @@ def export_pages_as_json(modeladmin, request, queryset):
@transaction.commit_on_success
def import_pages_from_json(request,
template_name='admin/pages/page/import_pages.html'):
- d = simplejson.load(request.FILES['json'])
+ try:
+ d = simplejson.load(request.FILES['json'])
+ except KeyError:
+ return redirect('admin:page-index')
try:
- errors, warnings = validate_pages_json_data(d,
- get_language_from_request(request))
+ errors = validate_pages_json_data(d, get_language_from_request(request))
except KeyError, e:
errors = [_('JSON file is invalid: %s') % (e.args[0],)]
- warnings = []
pages_created = []
if not errors:
@@ -49,7 +51,6 @@ def import_pages_from_json(request,
return TemplateResponse(request, template_name, {
'errors': errors,
- 'warnings': warnings,
'pages_created': pages_created,
'app_label': 'pages',
'opts': Page._meta,
@@ -57,13 +58,12 @@ def import_pages_from_json(request,
def validate_pages_json_data(d, preferred_lang):
"""
- Check if an import of d will succeed, and return errors, warnings.
+ Check if an import of d will succeed, and return errors.
- errors, warnings are lists of strings. If errors is not empty then
- the import should not proceed.
+ errors is a list of strings. The import should proceed only if errors
+ is empty.
"""
errors = []
- warnings = []
seen_complete_slugs = dict(
(lang[0], set()) for lang in settings.PAGE_LANGUAGES)
@@ -76,7 +76,7 @@ def validate_pages_json_data(d, preferred_lang):
d[JSON_PAGE_EXPORT_NAME])], []
pages = d['pages']
for p in pages:
- # use the complete slug as a way to identify pages in errors/warnings
+ # use the complete slug as a way to identify pages in errors
slug = p['complete_slug'].get(preferred_lang, None)
seen_parent = False
for lang, s in p['complete_slug'].items():
@@ -117,7 +117,7 @@ def validate_pages_json_data(d, preferred_lang):
"template: %s") % (slug, p['template']))
continue
- return errors, warnings
+ return errors
View
25 pages/managers.py
@@ -11,6 +11,7 @@
from django.db.models import Avg, Max, Min, Count
from django.contrib.sites.models import Site
from django.conf import settings as global_settings
+from django.utils.translation import ugettext_lazy as _
from datetime import datetime
@@ -143,18 +144,24 @@ def create_and_update_from_json_data(self, d, user):
user is the User instance that will be used if the author can't
be found in the DB.
- return (page object, created) where created is True if this was a
- new page or False if an existing page was updated.
+ returns (page object, created, messages).
+
+ created is True if this was a new page or False if an existing page
+ was updated.
+
+ messages is a list of strings warnings/messages about this import
"""
page = None
parent = None
parent_required = True
created = False
+ messages = []
languages = set(lang[0] for lang in settings.PAGE_LANGUAGES)
for lang, s in d['complete_slug'].items():
if lang not in languages:
+ messages.append(_("Language '%s' not imported") % (lang,))
continue
page = self.from_path(s, lang, exclude_drafts=False)
@@ -175,14 +182,23 @@ def create_and_update_from_json_data(self, d, user):
page.author = User.objects.get(email=d['author_email'])
except User.DoesNotExist:
page.author = user
+ messages.append(_("Original author '%s' not found")
+ % (d['author_email'],))
rtcs = d['redirect_to_complete_slug']
if rtcs:
+ s = ''
for lang, s in rtcs.items():
+ if lang not in langyages:
+ continue
r = self.from_path(s, lang, exclude_drafts=False)
if r:
page.redirect_to = r
break
+ else:
+ messages.append(_("Could not find page for redirect-to field"
+ " '%s' (import again if page was created below)")
+ % (s,))
page.creation_date = datetime.strptime(d['creation_date'],
ISODATE_FORMAT)
@@ -210,7 +226,8 @@ def create_and_update_from_json_data(self, d, user):
try:
page.sites.add(Site.objects.get(domain=site))
except Site.DoesNotExist:
- pass
+ messages.append(_("Could not add site '%s' to page")
+ % (site,))
if not page.sites.count(): # need at least one site
page.sites.add(Site.objects.get(pk=global_settings.SITE_ID))
@@ -233,7 +250,7 @@ def create_content(ctype, langs_bodies):
for ctype, langs_bodies in d['content'].items():
create_content(ctype, langs_bodies.items())
- return page, created
+ return page, created, messages
View
7 pages/templates/admin/pages/page/import_pages.html
@@ -23,7 +23,7 @@
{% else %}
<p>{% blocktrans %}Import completed.{% endblocktrans %}</p>
<ul>
- {% for page, created in pages_created %}
+ {% for page, created, messages in pages_created %}
<li>
<a href="../{{ page.id }}/">{{ page.get_complete_slug }} "{{ page.title }}"</a>
{% if created %}
@@ -31,6 +31,11 @@
{% else %}
{% trans "modified" %}
{% endif %}
+ {% if messages %}
+ <ul>
+ {% for m in messages %}<li>{{ m }}</li>{% endfor %}
+ </ul>
+ {% endif %}
</li>
{% endfor %}
</ul>

No commit comments for this range

Something went wrong with that request. Please try again.