Revision: 625
Author: batiste.bieler
Date: Mon Aug 3 07:26:03 2009
Log: Apply connected models patch from issue 135. Fix a template changing
issue.
http://code.google.com/p/django-page-cms/source/detail?r=625
Modified:
/trunk/pages/admin/__init__.py
/trunk/pages/admin/forms.py
/trunk/pages/admin/utils.py
/trunk/pages/media/pages/javascript/pages_form.js
/trunk/pages/models.py
/trunk/pages/templates/admin/pages/page/change_form.html
/trunk/pages/tests/pages_tests.py
=======================================
--- /trunk/pages/admin/__init__.py Mon Aug 3 05:40:39 2009
+++ /trunk/pages/admin/__init__.py Mon Aug 3 07:26:03 2009
@@ -20,7 +20,7 @@
from pages.admin import widgets
from pages.admin.forms import PageForm
-from pages.admin.utils import get_connected_models
+from pages.admin.utils import get_connected, make_inline_admin
from pages.admin.views import traduction, get_content, sub_menu,
change_status, modify_content
class PageAdmin(admin.ModelAdmin):
@@ -76,6 +76,11 @@
'javascript/pages_form.js',
)]
+ def __init__(self, *args, **kwds):
+ for model, options in get_connected():
+ self.inlines.append(make_inline_admin(model, options))
+ return super(PageAdmin, self).__init__(*args, **kwds)
+
def __call__(self, request, url):
"""
Delegate to the appropriate method, based on the URL.
@@ -227,14 +232,6 @@
}))
# deactived for now, create bugs with page with same slug title
- connected_fieldsets = []
- if obj:
- for mod in get_connected_models():
- for field_name, real_field_name, field in mod['fields']:
- connected_fieldsets.append(field_name)
-
- additional_fieldsets.append((_('Create a new linked ' +
- mod['model_name']), {'fields': connected_fieldsets}))
given_fieldsets = list(self.declared_fieldsets)
@@ -285,30 +282,6 @@
form.base_fields['template'].choices = template_choices
form.base_fields['template'].initial = force_unicode(template)
- # handle most of the logic of connected models
- if obj:
- for mod in get_connected_models():
- model = mod['model']
- attributes = {'page': obj.id}
- validate_field = True
-
- if request.POST:
- for field_name, real_field_name, field in
mod['fields']:
- if field_name in request.POST and
request.POST[field_name]:
- attributes[real_field_name] =
request.POST[field_name]
-
- if len(attributes) > 1:
- connected_form = mod['form'](attributes)
- if connected_form.is_valid():
- connected_form.save()
- else:
- validate_field = False
-
- for field_name, real_field_name, field in mod['fields']:
- form.base_fields[field_name] = field
- if not validate_field:
- form.base_fields[field_name].required = False
-
for placeholder in get_placeholders(template):
widget = self.get_widget(placeholder.widget)()
if placeholder.parsed:
=======================================
--- /trunk/pages/admin/forms.py Sat Jun 20 07:50:50 2009
+++ /trunk/pages/admin/forms.py Mon Aug 3 07:26:03 2009
@@ -45,6 +45,7 @@
slug = slugify(self.cleaned_data['slug'])
target = self.data.get('target', None)
position = self.data.get('position', None)
+ print self.data
if settings.PAGE_UNIQUE_SLUG_REQUIRED:
if self.instance.id:
=======================================
--- /trunk/pages/admin/utils.py Sat Jun 20 07:50:50 2009
+++ /trunk/pages/admin/utils.py Mon Aug 3 07:26:03 2009
@@ -1,26 +1,39 @@
# -*- coding: utf-8 -*-
-from django.core.urlresolvers import get_mod_func
from pages import settings
-
-def get_connected_models():
- """Return all the connected models with this CMS"""
+from django.contrib import admin
+from django.forms import ModelForm
+from django.core.urlresolvers import get_mod_func
+
+def get_connected():
if not settings.PAGE_CONNECTED_MODELS:
return []
models = []
for capp in settings.PAGE_CONNECTED_MODELS:
model = {}
- mod_name, form_name = get_mod_func(capp['form'])
- f = getattr(__import__(mod_name, {}, {}, ['']), form_name)
- model['form'] = f
mod_name, model_name = get_mod_func(capp['model'])
model['model_name'] = model_name
m = getattr(__import__(mod_name, {}, {}, ['']), model_name)
model['model'] = m
- model['fields'] = []
- for k, v in f.base_fields.iteritems():
- if k is not "page":
- model['fields'].append((model_name.lower() + '_' + k, k,
v))
- models.append(model)
+
+ options = capp.get('options', {})
+ model['options'] = options
+
+ if 'form' in capp:
+ mod_name, form_name = get_mod_func(capp['form'])
+ f = getattr(__import__(mod_name, {}, {}, ['']), form_name)
+ model['options'].update({'form': f})
+
+ models.append((m, options))
return models
+
+def make_inline_admin(model_class, options):
+ class ModelOptions(admin.StackedInline):
+ model = model_class
+ fk_name = 'page'
+ form = options.get('form', ModelForm)
+ extra = options.get('extra', 3)
+ max_num = options.get('max_num', 0)
+ return ModelOptions
+
=======================================
--- /trunk/pages/media/pages/javascript/pages_form.js Wed May 6 09:23:35
2009
+++ /trunk/pages/media/pages/javascript/pages_form.js Mon Aug 3 07:26:03
2009
@@ -41,28 +41,28 @@
});
// Select the appropriate template option
- var template = $.query.get('template');
+ // This code should go away soon
+ /*var template = $.query.get('template');
if (template) {
$('#id_template option').each(function() {
if (template == this.value) {
$(this).attr('selected', true);
return false;
- }
+ };
});
- }
+ };*/
// Confirm language and template change if page is not saved
+ // this code doesn't work with languages
$.each(['language', 'template'], function(i, label) {
var select = $('#id_'+label);
if (select.length) {
var orig_ = select.val();
select.change(function() {
- var query = $.query.set(label,
orig_).set('new_'+label,select.val()).toString();
- select.val(orig_);
- $('#page_form').attr('action',query);
- $('input[name=_continue]').click();
+ if(confirm(gettext('You will loose any changes you have
done to the page. Are you sure?')))
+ $('input[name=_continue]').click();
});
- }
+ };
});
// Disable the page content if the page is a redirection
=======================================
--- /trunk/pages/models.py Fri Jul 31 01:14:09 2009
+++ /trunk/pages/models.py Mon Aug 3 07:26:03 2009
@@ -103,6 +103,7 @@
else:
self.publication_date = None
self.last_modification_date = datetime.now()
+ print self.template
super(Page, self).save(*args, **kwargs)
def get_calculated_status(self):
=======================================
--- /trunk/pages/templates/admin/pages/page/change_form.html Sun May 10
06:58:52 2009
+++ /trunk/pages/templates/admin/pages/page/change_form.html Mon Aug 3
07:26:03 2009
@@ -19,7 +19,7 @@
{% endif %}
{% endblock %}
- <form id="page_form" action="?language={{ request.GET.language }}{%if
request.GET.target %}&target={{ request.GET.target }}{%
endif %}&{%if request.GET.target %}position={{ request.GET.position
}}{% endif %}" method="post">
+ <form id="page_form" {% if
has_file_field %}enctype="multipart/form-data" {% endif %}
action="?language={{ request.GET.language }}{%if
request.GET.target %}&target={{ request.GET.target }}{%
endif %}&{%if request.GET.target %}position={{ request.GET.position
}}{% endif %}" method="post">
<div class="sidebar">
{% for fieldset in adminform %}
{% include "admin/pages/page/includes/fieldset.html" %}
@@ -46,6 +46,10 @@
{% endif %}
{% endfor %}
</div>
+
+ {% for inline_admin_formset in inline_admin_formsets %}
+ {% include inline_admin_formset.opts.template %}
+ {% endfor %}
{% submit_row %}
</form>
=======================================
--- /trunk/pages/tests/pages_tests.py Fri Jul 31 01:06:52 2009
+++ /trunk/pages/tests/pages_tests.py Mon Aug 3 07:26:03 2009
@@ -17,7 +17,10 @@
"""Helper method for creating page datas"""
page_data = {'title':'test page %d' % self.counter,
'slug':'test-page-%d' % self.counter, 'language':'en-us',
- 'sites':[2], 'status':Page.PUBLISHED}
+ 'sites':[2], 'status':Page.PUBLISHED,
+ # used to disable an error with connected models
+ 'document_set-TOTAL_FORMS':0, 'document_set-INITIAL_FORMS':0,
+ }
self.counter = self.counter + 1
return page_data
@@ -54,9 +57,7 @@
page_data = self.get_new_page_data()
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
-
- setattr(settings, "PAGE_UNIQUE_SLUG_REQUIRED", False)
-
+ setattr(settings, "PAGE_UNIQUE_SLUG_REQUIRED", False)
response = c.post('/admin/pages/page/add/', page_data)
self.assertEqual(response.status_code, 200)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---