1 4 12 16 25 27 28 31 34 35 36 39 40 41 43 46 47 49 51 52 57 65 66 67 68 69 70 71 72 73 74 77 78 79 80 81 83 84 85 86 87 88 89 92 93 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 112 114 116 118 119 120 121 122 123 124 125 126 127 128 129 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 164 165 166 167 169 175 177 178 179 180 181 182 184 186 188 189 190 191 192 193 194 195 197 198 199 201 205 206 207 208 209 210 216 219 223 224 227 229 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 258 260 261 262 264 266 267 269 270 272 273 275 277 278 280 282 284 285 286 288 290 292 294 295 297 299 301 303 304 305 307 309 310 311 312 313 314 315 318 319 320 321 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 347 352 357 358 359 366 370 375 |
# -*- coding: utf-8 -*-
"""Page Admin class."""
# these mandatory fields are not versioned
# TODO: find solution to do this dynamically #if getattr(settings, 'PAGE_USE_SITE_ID'):
# Strange django behavior. If not provided, django will try to find # 'page' foreign key in all registered models
# Add support for future dating and expiration based on settings. general_fields.insert(insert_point, 'publication_end_date') general_fields.insert(insert_point, 'publication_date')
(_('General'), { 'fields': general_fields, 'classes': ('module-general',), }), (_('Options'), { 'fields': normal_fields, 'classes': ('module-options',), }), )
'all': [join(settings.PAGES_MEDIA_URL, path) for path in ( 'css/rte.css', 'css/pages.css' )] } 'javascript/jquery.js', 'javascript/jquery.rte.js', 'javascript/jquery.query.js', 'javascript/pages.js', 'javascript/pages_form.js', )]
# Admin-site-wide views. url(r'^$', self.list_pages, name='page-index'), url(r'^(?P<page_id>[0-9]+)/traduction/(?P<language_id>[-\w]+)/$', traduction, name='page-traduction'), url(r'^(?P<page_id>[0-9]+)/get-content/(?P<content_id>[-\w]+)/$', get_content, name='page-traduction'), url(r'^(?P<page_id>[0-9]+)/modify-content/(?P<content_id>[-\w]+)/(?P<language_id>[-\w]+)/$', modify_content, name='page-traduction'), url(r'^(?P<page_id>[0-9]+)/delete-content/(?P<language_id>[-\w]+)/$', delete_content, name='page-delete_content'), url(r'^(?P<page_id>[0-9]+)/sub-menu/$', sub_menu, name='page-sub-menu'), url(r'^(?P<page_id>[0-9]+)/move-page/$', self.move_page, name='page-traduction'), url(r'^(?P<page_id>[0-9]+)/change-status/$', change_status, name='page-change-status'), )
"""Displays the i18n JavaScript that the Django admin requires.
This takes into account the ``USE_I18N`` setting. If it's set to False, the generated JavaScript will be leaner and faster. """ if global_settings.USE_I18N: from django.views.i18n import javascript_catalog else: from django.views.i18n import null_javascript_catalog as javascript_catalog return javascript_catalog(request, packages='pages')
"""Move the page in the tree if necessary and save every placeholder :class:`Content <pages.models.Content>`. """
language = form.cleaned_data['language'] target = form.data.get('target', None) position = form.data.get('position', None) page.save()
# if True, we need to move the page if target and position: try: target = self.model.objects.get(pk=target) except self.model.DoesNotExist: pass else: target.invalidate() page.move_to(target, position)
for name in self.mandatory_placeholders: data = form.cleaned_data[name] placeholder = PlaceholderNode(name) placeholder.save(page, language, data, change)
for placeholder in get_placeholders(page.get_template()): if(placeholder.name in form.cleaned_data and placeholder.name not in self.mandatory_placeholders): data = form.cleaned_data[placeholder.name] placeholder.save(page, language, data, change)
page.invalidate()
""" Add fieldsets of placeholders to the list of already existing fieldsets. """
'fields': placeholder_fieldsets, 'classes': ('module-content',), }))
# deactived for now, create bugs with page with same slug title
"""Given a ModelForm return an unsaved instance. ``change`` is True if the object is being changed, and False if it's being added.""" instance = super(PageAdmin, self).save_form(request, form, change) instance.template = form.cleaned_data['template'] if not change: instance.author = request.user return instance
"""Get a :class:`Page <pages.admin.forms.PageForm>` for the :class:`Page <pages.models.Page>` and modify its fields depending on the request."""
initial_slug = obj.slug(language=language, fallback=False) initial_title = obj.title(language=language, fallback=False) form.base_fields['slug'].initial = initial_slug form.base_fields['title'].initial = initial_title form.base_fields['slug'].label = _('Slug')
_('Default template')))
initial = Content.objects.get_content(obj, language, name) else:
"""The ``change`` admin view for the :class:`Page <pages.models.Page>`.""" language = get_language_from_request(request) extra_context = { 'language': language, # don't see where it's used #'lang': current_lang, 'page_languages': settings.PAGE_LANGUAGES, } try: obj = self.model.objects.get(pk=object_id) except self.model.DoesNotExist: # Don't raise Http404 just yet, because we haven't checked # permissions yet. We don't want an unauthenticated user to be able # to determine whether a given object exists. obj = None else: template = get_template_from_request(request, obj) extra_context['placeholders'] = get_placeholders(template) extra_context['traduction_languages'] = [l for l in settings.PAGE_LANGUAGES if Content.objects.get_content(obj, l[0], "title") and l[0] != language] extra_context['page'] = obj return super(PageAdmin, self).change_view(request, object_id, extra_context)
"""The ``add`` admin view for the :class:`Page <pages.models.Page>`.""" 'language': get_language_from_request(request), 'page_languages': settings.PAGE_LANGUAGES, } #extra_context['placeholders'] = get_placeholders(template) extra_context)
"""Return ``True`` if the current user has permission to add a new page.""" return super(PageAdmin, self).has_add_permission(request) else:
"""Return ``True`` if the current user has permission on the page. Return the string ``All`` if the user has all rights.""" return obj.has_page_permission(request)
"""Return ``True`` if the current user has permission on the page. Return the string ``All`` if the user has all rights. """ return obj.has_page_permission(request)
"""List root pages""" return admin.site.login(request) # HACK: overrides the changelist template and later resets it to None self.change_list_template = template_name
page_ids = list(set([c.page.pk for c in Content.objects.filter(body__icontains=q)])) pages = Page.objects.filter(pk__in=page_ids) else:
'language': language, 'name': _("page"), 'pages': pages, 'opts': self.model._meta, 'q': q }
self.change_list_template = None return change_list
"""Move the page to the requested target, at the given position""" page = Page.objects.get(pk=page_id)
target = request.POST.get('target', None) position = request.POST.get('position', None) if target is not None and position is not None: try: target = self.model.objects.get(pk=target) except self.model.DoesNotExist: pass # TODO: should use the django message system # to display this message # _('Page could not been moved.') else: page.invalidate() target.invalidate() page.move_to(target, position) return self.list_pages(request, template_name='admin/pages/page/change_list_table.html') return HttpResponseRedirect('../../')
#admin.site.register(Content, ContentAdmin)
|