Permalink
Browse files

Fix moving pages through API.

Moving pages using fancypages' internal API had a few issues introduced
by the recent refactoring. It is now ensured that the JS code is using
the UUID rather than the PK of the page. In addition, creating
containers ignored the language code currently set in the request cycle
and would attempt to create containers without a proper language code
which caused additional errors. Both issues are now resolved.

Resolves #25.
  • Loading branch information...
1 parent 5407a27 commit 0c63c343901ec1126f62a85638e3558b4a1ceb0b Sebastian Vetter committed Apr 12, 2014
View
@@ -12,6 +12,14 @@ Changelog
``wysihtml5-config.js``.
* Minify ``wysihtml5-config.js`` used for customising ``wyshtmls5`` to
reduce size.
+* Fixes #25 (1): getting the child pages of a ``FancyPage`` used the
+ ``PageNode``'s method ``get_children`` which would return a queryset
+ of ``PageNode`` instances. ``FancyPage`` now provides its own
+ ``get_children`` method that returns the corresponding queryset of
+ ``FancyPage`` instances.
+* Fixes #25 (2): using the API to move pages in the hierarchy failed with
+ an internal server error caused by changes during refactoring. The calls
+ to the API are now using the UUID as expected instead of the model's PK.
0.3.0
@@ -221,9 +221,6 @@ def delete(self, using=None):
delete.alters_data = True
def __getattr__(self, name):
- """
- Try to find
- """
if name.startswith('_'):
raise AttributeError
try:
@@ -250,22 +247,45 @@ def __unicode__(self):
return u"FancyPage '{0}'".format(self.name)
def save(self, update_slugs=True, *args, **kwargs):
+ """
+ Saving this page has several additional responsibilities to ensure
+ the consistency of the data. Before actually saving the model to the
+ database, it is ensured that *slug* and *status* are set on the page
+ if either of them is not defined. If not set, the slug is generated
+ from the page name. If the status is not set, the default status
+ defined in ``FP_DEFAULT_PAGE_STATUS`` is used.
+ After saving, all containers specified in the template for this page
+ that don't exist are created. Using the current language code used in
+ the overall context of this model.
+ """
if not self.slug:
self.slug = slugify(self.name)
if not self.status:
self.status = getattr(
settings, 'FP_DEFAULT_PAGE_STATUS', self.DRAFT)
+
super(AbstractFancyPage, self).save(*args, **kwargs)
+ language_code = get_language()
+ for cname in self._get_missing_containers(language_code=language_code):
+ self.containers.create(
+ page_object=self, name=cname, language_code=language_code)
+
+ def _get_missing_containers(self, language_code=None):
+ language_code = language_code or get_language()
+
try:
template_name = self.page_type.template_name
except AttributeError:
template_name = settings.FANCYPAGES_DEFAULT_TEMPLATE
- existing_containers = [c.name for c in self.containers.all()]
+ cnames = self.containers.filter(
+ language_code=language_code).values_list('name')
+ existing_containers = [i[0] for i in cnames]
+
for cname in get_container_names_from_template(template_name):
if cname not in existing_containers:
- self.containers.create(page_object=self, name=cname)
+ yield cname
class Meta:
app_label = 'fancypages'
@@ -3,7 +3,7 @@
{% load url from future %}
{% for fancypage in fancypage_list %}
-<li id="page-{{ fancypage.id }}" class="sortable {% if forloop.last %}last{% endif %}" data-page-id="{{ fancypage.id }}">
+<li id="page-{{ fancypage.uuid }}" class="sortable {% if forloop.last %}last{% endif %}" data-page-id="{{ fancypage.uuid }}">
<div class="row-fluid" >
<h5 class="span10">
{% if fancypage.numchild %}
@@ -1,4 +1,6 @@
{% extends "fancypages/base.html" %}
+
+{% load i18n %}
{% load staticfiles %}
{% load url from future %}
@@ -17,15 +19,17 @@
<div class="container-fluid">
<div class="brand">Fancy Sandbox</div>
<ul class="nav">
- <li><a href="/">Home</a></li>
- <li><a href="{% url "post-list" %}">Blog</a></li>
+ <li><a href="/">{% trans "Home" %}</a></li>
+ <li><a href="{% url "post-list" %}">{% trans "Blog" %}</a></li>
</ul>
+ {% url "fancypages:page-list" as dashboard_url %}
<div class="pull-right">
<ul class="nav">
{% if not request.user.is_authenticated %}
- <li><a href="/admin/login/">Login</a></li>
+ <li><a href="/admin/login/?next={{ dashboard_url }}">{% trans "Login" %}</a></li>
{% else %}
- <li><a href="/admin/logout/">Logout</a></li>
+ <li><a href="{{ dashboard_url }}">{% trans "Dashboard" %}</a></li>
+ <li><a href="/admin/logout/">{% trans "Logout" %}</a></li>
{% endif %}
</ul>
</div>

0 comments on commit 0c63c34

Please sign in to comment.