Найти - Пользователи
Полная версия: django-cms
Начало » Django » django-cms
1
romankrv
Привет всем.
Кто работал с django-cms, может объяснить почему происходит следующая ситуация:
при попытке сохранения нового экземпляра например через сигнал или через python-shell со всеми необходимыми параметрами и после создания контекста я пытаюсь доступится по тому url что указал ранее. Но получаю 404. Хотя сравнивая содержания таблиц (это cms_page и cms_pagecontent) вижу что записи, созданные через интерфейс django-cms и через python-shell одинаковые. Для записей что созданы через интерфейс 404 не возникает.

пример кода в shell которым создаю экземпляр:
  
from cms.models import PageContent, Page
In [59]: Page(
title='test',
slug='test',
position=1,
created = datetime.datetime.now(),
start_publish_date = datetime.datetime.now(),
override_url = True,
overridden_url = 'non',
parent_id=8
).save()
Спасибо.


ps
также привожу код класса
class Page(models.Model):
title = models.CharField(_('title'), max_length=200, help_text=_('The title of the page.'))
slug = models.SlugField(_('slug'), help_text=_('The name of the page that appears in the URL. A slug can contain letters, numbers, underscores or hyphens.'))

created = models.DateTimeField(null=True, blank=True)
modified = models.DateTimeField(null=True, blank=True)

template = models.CharField(max_length=200, null=True, blank=True)
context = models.CharField(max_length=200, null=True, blank=True, help_text=_('Optional. Dotted path to a python function that receives two arguments (request, context) and can update the context.'))

is_published = models.BooleanField(_('is published'), default=True, help_text=_('Whether or not the page is accessible from the web.'))
start_publish_date = models.DateTimeField(_('start publishing'), null=True, blank=True)
end_publish_date = models.DateTimeField(_('finish publishing'), null=True, blank=True)

# Navigation
parent = models.ForeignKey('self', verbose_name=_('Navigation'), null=True, blank=True, help_text=_('The page will be appended inside the chosen category.'))
position = models.IntegerField()
in_navigation = models.BooleanField(_('display in navigation'), default=True)
toc = models.BooleanField(_('Table of contents'), default=False, help_text=_('If checked, will render a toc based on the anchor elements.'))

# Access
requires_login = models.BooleanField(_('requires login'), help_text=_('If checked, only logged-in users can view the page.'))
#(not implemented yet)
#change_access_level = models.ManyToManyField(Group, verbose_name=_('change access level'), related_name='change_page_set', filter_interface=models.VERTICAL, null=True, blank=True)
#view_access_level = models.ManyToManyField(Group, verbose_name=_('view access level'), related_name='view_page_set', filter_interface=models.VERTICAL, null=True, blank=True)

# Override the page URL or redirect the page to another page.
override_url = models.BooleanField(default=False)
overridden_url = models.CharField(max_length=200, null=True, blank=True)#, choices=choices)
redirect_to = models.ForeignKey('self', null=True, blank=True, related_name='redirected_pages')

is_editable = models.BooleanField(default=True)

objects = PageManager()

class Meta:
ordering = ('position', 'title',)
verbose_name = _('page')
verbose_name_plural = _('pages')
verbose_name = _(u'Editable page')
verbose_name_plural = _(u'== Editable pages ==')

def __unicode__(self):
return self.title

def save(self, force_insert=False, force_update=False):
if not self.id:
self.created = datetime.datetime.now()
self.modified = datetime.datetime.now()
if self.overridden_url is not None:
self.overridden_url = self.overridden_url.strip('/ ')
super(Page, self).save(force_insert=False, force_update=False)

def get_content(self, language=None, all=False, position=''):
if not language:
language = translation.get_language()
published_page_contents = self.pagecontent_set.filter(is_published=True, position=position)

page_content = None

# Determine the PageContent we want to render
page_contents = published_page_contents.filter(language=language)
if page_contents:
if all:
page_content = page_contents
else:
page_content = page_contents[0]
else:
# Use a PageContent in an alternative language
for alt_language in language_list():
if alt_language == language:
continue
page_contents = published_page_contents.filter(language=alt_language)
if page_contents:
if all:
page_content = page_contents
else:
page_content = page_contents[0]
break


if not page_content:
# TODO: What's better?
# return None
page_content = PageContent(page=self)
if all:
page_content = [PageContent(page=self)]

if all and page_content:
for c in page_content:
c.prepare()
return page_content
return page_content.prepare()

def get_path(self):
class PathList(list):
def __unicode__(self):
return u' > '.join([smart_unicode(page) for page in self])

path = [self]
parent = self.parent
while parent:
path.append(parent)
parent = parent.parent
return PathList(reversed(path))

def on_path(self, super):
return super in self.get_path()

def get_absolute_url(self, language=None):
if self.redirect_to:
return self.redirect_to.get_absolute_url()

url = u'/'
if self.override_url:
# Check whether it is an absolute URL
if PROTOCOL_RE.match(self.overridden_url):
return self.overridden_url

# The overridden URL is assumed to not have a leading or trailing slash.
if self.overridden_url:
return u'%s%s/' % (url, self.overridden_url.strip('/ '))
else:
return url

if LANGUAGE_REDIRECT:
if not language:
language = translation.get_language()
url += u'%s/' % language

url += u'/'.join([page.smart_slug(language=language) for page in self.get_path() if page.parent])
if not url.endswith('/'):
url += '/'
return url
absolute_url = get_absolute_url

def get_next_position(self):
children = Page.objects.filter(parent=self).order_by('-position')
return children and (children[0].position+1) or 1

def get_level(self):
parent = self.parent
level = 0
while parent:
level += 1
parent = parent.parent
return level

def smart_title(self):
return self.get_content().title
smart_title = property(smart_title)

def smart_slug(self, language=None):
return self.get_content(language=language).slug

def published(self, user):
return self in Page.objects.published(user)
published.boolean = True

def get_meta_tags(self, language=None):
if not language:
language = translation.get_language()
pagecontent_set = self.pagecontent_set.filter(is_published=True, language=language)
tags = []
tags += [MetaTag(page_content.keywords, 'keywords', lang=page_content.language)
for page_content in pagecontent_set.filter(is_published=True) if page_content.keywords]
tags += [MetaTag(page_content.description, 'description', lang=page_content.language)
for page_content in pagecontent_set if page_content.description]
tags += [MetaTag(page_content.page_topic, 'page_topic', lang=page_content.language)
for page_content in pagecontent_set if page_content.page_topic]
return tags
Doberman26rus
Есть ли в django-cms 2.0 table of content? То есть, если страница пустая, то автоматически выводить дочерние каталоги?
romankrv
Посмотри в модели models.py там можешь узнать какое это поле
Вообще оно должно быть иначе где же хранить контент набраный юзером

Удачи
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB