Permalink
Browse files

coping works again

  • Loading branch information...
1 parent 8a5aec4 commit ae171a7448e6592af4c83649a1d9d8abe32f3129 @digi604 digi604 committed Jun 19, 2009
View
@@ -229,11 +229,10 @@ class PageAdmin(admin.ModelAdmin):
form = PageForm
exclude = ['author', 'lft', 'rght', 'tree_id', 'level']
- mandatory_placeholders = ('title', 'slug', 'parent', 'meta_description', 'meta_keywords', 'page_title', 'menu_title')
- filter_horizontal = ['sites']
+ mandatory_placeholders = ('title', 'slug', 'parent', 'site', 'meta_description', 'meta_keywords', 'page_title', 'menu_title')
top_fields = ['language']
- general_fields = ['title', 'slug', 'parent', 'published']
- advanced_fields = ['sites', 'in_navigation', 'reverse_id', 'overwrite_url']
+ general_fields = ['title', ('slug', 'parent', 'site'), 'published']
+ advanced_fields = ['in_navigation', 'reverse_id', 'overwrite_url']
template_fields = ['template']
change_list_template = "admin/cms/page/change_list.html"
@@ -266,8 +265,6 @@ class PageAdmin(admin.ModelAdmin):
if settings.CMS_SHOW_META_TAGS:
advanced_fields.append('meta_description')
advanced_fields.append('meta_keywords')
-
- list_filter += ['sites']
if settings.CMS_SEO_FIELDS:
seo_fields = ('page_title', 'meta_description', 'meta_keywords')
@@ -533,10 +530,6 @@ def get_form(self, request, obj=None, **kwargs):
form = super(PageAdmin, self).get_form(request, obj, **kwargs)
language = get_language_from_request(request, obj)
form.base_fields['language'].initial = force_unicode(language)
- if 'site' in request.GET.keys():
- form.base_fields['sites'].initial = [int(request.GET['site'])]
- else:
- form.base_fields['sites'].initial = Site.objects.all().values_list('id', flat=True)
if obj:
try:
title_obj = obj.get_title_obj(language=language, fallback=False, version_id=version_id, force_reload=True)
@@ -558,7 +551,12 @@ def get_form(self, request, obj=None, **kwargs):
for name in ['slug','title','application_urls','overwrite_url','meta_description','meta_keywords']:
form.base_fields[name].initial = u''
form.base_fields['parent'].initial = request.GET.get('target', None)
+ print request.session.keys()
+ print request.session
+ print dir(request.session)
+ form.base_fields['site'].initial = request.session.get('cms_admin_site', None)
form.base_fields['parent'].widget = HiddenInput()
+ form.base_fields['site'].widget = HiddenInput()
template = get_template_from_request(request, obj)
if settings.CMS_TEMPLATES:
template_choices = list(settings.CMS_TEMPLATES)
@@ -846,7 +844,6 @@ def copy_page(self, request, page_id, extra_context=None):
'copy_permissions': request.REQUEST.get('copy_permissions', False),
'copy_moderation': request.REQUEST.get('copy_moderation', False)
}
-
page.copy_page(target, site, position, **kwargs)
return HttpResponse("ok")
#return self.list_pages(request,
View
@@ -5,7 +5,7 @@
from cms.utils import get_language_from_request, find_children
from django.contrib.sites.models import Site
-SITE_VAR = "sites__id__exact"
+SITE_VAR = "site__exact"
COPY_VAR = "copy"
class CMSChangeList(ChangeList):
@@ -26,18 +26,29 @@ def __init__(self, *args, **kwargs):
except:
self._current_site = Site.objects.get_current()
else:
- self._current_site = Site.objects.get_current()
+ site_pk = request.session.get('cms_admin_site', None)
+ if site_pk:
+ self._current_site = Site.objects.get(pk=site_pk)
+ else:
+ self._current_site = Site.objects.get_current()
+
+ request.session['cms_admin_site'] = self._current_site.pk
+ request.session.save()
def get_query_set(self, request=None):
if COPY_VAR in self.params:
- del self.params[COPY_VAR]
+ del self.params[COPY_VAR]
+
+
qs = super(CMSChangeList, self).get_query_set()
if request:
permissions = Page.permissions.get_change_list_id_list(request.user)
if permissions != Page.permissions.GRANT_ALL:
qs = qs.filter(pk__in=permissions)
self.root_query_set = self.root_query_set.filter(pk__in=permissions)
self.real_queryset = True
+ if not SITE_VAR in self.params:
+ qs = qs.filter(site=request.session.get('cms_admin_site', None))
qs = qs.order_by('tree_id', 'parent', 'lft')
return qs
View
@@ -82,16 +82,6 @@ def clean_overwrite_url(self):
if not any_path_re.match(url):
raise forms.ValidationError(ugettext_lazy('Invalid url, use /my/url format.'))
return url
-
- def clean_sites(self):
- sites = self.cleaned_data['sites']
- if self.cleaned_data['parent'] != None:
- parent_sites = self.cleaned_data['parent'].sites.all().values_list('id', flat=True)
- for site in sites:
- if not site.pk in parent_sites:
- raise forms.ValidationError(ugettext_lazy('The parent of this page is not on the site %(site)s') % {'site':site } )
- return sites
-
class PagePermissionInlineAdminForm(forms.ModelForm):
"""Page permission inline admin form used in inline admin. Required, because
View
@@ -13,6 +13,7 @@ Example:
It also adds this prefix automatically to every href and form tag.
+put 'cms.middleware.multilingual.MultilingualURLMiddleware' into your settings.MIDDLEWARE_CLASSES to enable it.
Language Chooser
----------------
@@ -49,7 +50,7 @@ same url as the current and only will change the language prefix.
For the language chooser to work the MultilingualURLMiddleware must be installed.
-page_language_url
+page\_language\_url
-----------------
This template_tag returns the url of the current page in an other language.
View
@@ -28,7 +28,7 @@ add the following middlewares:
MIDDLEWARE_CLASSES = (
...
'cms.middleware.CurrentPageMiddleware',
- 'cms.middleware.MultilingualURLMiddleware',
+ 'cms.middleware.multilingual.MultilingualURLMiddleware',
...
)
View
@@ -207,7 +207,7 @@ Softroot
Softroots are pages that start a new navigation.
If you are in a child of a softroot node you can only see the path to the softroot.
-This feature is useful if you have big navigation trees with a lot of sites and don't want to overwhelm the user
+This feature is useful if you have big navigation trees with a lot of pages and don't want to overwhelm the user
To enable it put the following to your settings.py
@@ -322,7 +322,7 @@ $(document).ready(function() {
}else{
url = remove_from_url(url, "copy");
}
- url = insert_into_url(url, "sites__id__exact", id)
+ url = insert_into_url(url, "site__exact", id)
window.location = url;
});
var copy_splits = window.location.href.split("copy=")
@@ -18,9 +18,8 @@ def forwards(self, orm):
db.rename_table('cms_title', 'cms_publictitle')
db.add_column('cms_publictitle', 'mark_delete',())
- db.rename_table('cms_page_sites', 'cms_publicpage_sites')
- db.rename_column('cms_publicpage_sites', 'page', 'publicpage')
- # Adding ManyToManyField 'PublicPage.sites'
+ db.delete_table('cms_page_sites')
+ # TODO: create pages for every site
# Adding model 'PublicPage'
db.create_table('cms_page', (
@@ -47,13 +46,6 @@ def forwards(self, orm):
))
db.send_create_signal('cms', ['Page'])
-
- db.create_table('cms_page_sites', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('page', models.ForeignKey(orm.Page, null=False)),
- ('site', models.ForeignKey(orm['sites.Site'], null=False))
- ))
-
# Adding model 'PublicCMSPlugin'
db.create_table('cms_cmsplugin', (
('id', models.AutoField(primary_key=True)),
View
@@ -88,7 +88,7 @@ class Page(Publisher, Mptt):
published = models.BooleanField(_("is published"), blank=True)
template = models.CharField(_("template"), max_length=100, choices=settings.CMS_TEMPLATES, help_text=_('The template used to render the content.'))
- sites = models.ManyToManyField(Site, help_text=_('The site(s) the page is accessible at.'), verbose_name=_("sites"))
+ site = models.ForeignKey(Site, help_text=_('The site the page is accessible at.'), verbose_name=_("site"))
moderator_state = models.SmallIntegerField(_('moderator state'), choices=moderator_state_choices, default=MODERATOR_NEED_APPROVEMENT, blank=True)
@@ -136,7 +136,10 @@ def copy_page(self, target, site, position='first-child', copy_permissions=True,
"""
from cms.utils.moderator import update_moderation_message
- descendants = [self] + list(self.get_descendants().filter(sites__pk=site.pk).order_by('-rght'))
+ descendants = [self] + list(self.get_descendants().order_by('-rght'))
+ print "copy"
+ print target, site, position
+ print descendants
tree = [target]
level_dif = self.level - target.level - 1
first = True
@@ -181,7 +184,8 @@ def copy_page(self, target, site, position='first-child', copy_permissions=True,
if first:
first = False
page.move_to(target, position)
- page.sites = [site]
+ page.site = site
+ page.save()
for title in titles:
title.pk = None
title.public_id = None
@@ -1036,7 +1040,7 @@ class PublicPage(models.Model):
published = models.BooleanField(_("is published"), blank=True)
template = models.CharField(_("template"), max_length=100, choices=settings.CMS_TEMPLATES, help_text=_('The template used to render the content.'))
- sites = models.ManyToManyField(Site, help_text=_('The site(s) the page is accessible at.'), verbose_name=_("sites"))
+ site = models.ForeignKeyField(Site, help_text=_('The site the page is accessible at.'), verbose_name=_("site"))
moderator_state = models.SmallIntegerField(_('moderator state'), choices=moderator_state_choices, default=MODERATOR_NEED_APPROVEMENT, blank=True)
View
@@ -11,7 +11,7 @@
class PageManager(models.Manager):
def on_site(self):
site = Site.objects.get_current()
- return self.filter(sites=site)
+ return self.filter(site=site)
def root(self):
"""
@@ -119,7 +119,7 @@ def get_page_slug(self, slug, site=None, latest_by='creation_date'):
try:
titles = self.filter(
slug=slug,
- page__sites__domain=site.domain,
+ page__site=site,
).select_related()#'page')
except self.model.DoesNotExist:
return None
View
@@ -68,8 +68,8 @@
CMS_APPLICATIONS_URLS = getattr(settings, 'CMS_APPLICATIONS_URLS', ())
# Whether a slug should be unique ... must be unique in all languages.
-i18n_installed = not 'cms.middleware.MultilingualURLMiddleware' in settings.MIDDLEWARE_CLASSES
-CMS_UNIQUE_SLUGS = getattr(settings, 'CMS_UNIQUE_SLUGS', i18n_installed)
+i18n_not_installed = not 'cms.middleware.multilingual.MultilingualURLMiddleware' in settings.MIDDLEWARE_CLASSES
+CMS_UNIQUE_SLUGS = getattr(settings, 'CMS_UNIQUE_SLUGS', i18n_not_installed)
#Should the tree of the pages be also be displayed in the urls? or should a falt slug strucutre be used?
CMS_FLAT_URLS = getattr(settings, 'CMS_FLAT_URLS', False)
@@ -3,7 +3,6 @@
from django.utils.safestring import mark_safe
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _
-from django.contrib.sites.models import Site
from cms import settings as cms_settings
from cms.models import MASK_PAGE, MASK_CHILDREN, MASK_DESCENDANTS
from cms.utils.admin import get_admin_menu_item_context
@@ -35,7 +35,7 @@ def show_menu(context, from_level=0, to_level=100, extra_inactive=0, extra_activ
else:# maybe the active node is in an extender?
alist = []
extenders = PageModel.objects.published().filter(in_navigation=True,
- sites__domain=site.domain,
+ site=site,
level__lte=to_level)
extenders = extenders.exclude(navigation_extenders__isnull=True).exclude( navigation_extenders__exact="")
for ext in extenders:
@@ -47,7 +47,7 @@ def show_menu(context, from_level=0, to_level=100, extra_inactive=0, extra_activ
alist = [(ext.pk, ext.soft_root)] + alist
break
filters = {'in_navigation' : True,
- 'sites__domain' : site.domain,
+ 'site' : site,
'level__lte' : to_level}
#check the ancestors for softroots
@@ -141,7 +141,7 @@ def show_sub_menu(context, levels=100, template="cms/sub_menu.html"):
'rght__lt':page.rght,
'tree_id':page.tree_id,
'level__lte':page.level+levels,
- 'sites__domain':site.domain}
+ 'site':site}
if settings.CMS_HIDE_UNTRANSLATED:
filters['title_set__language'] = lang
pages = PageModel.objects.published().filter(**filters)
@@ -164,8 +164,7 @@ def show_sub_menu(context, levels=100, template="cms/sub_menu.html"):
to_level = page.level+levels
extra_active = extra_inactive = levels
else:
- extenders = PageModel.objects.published().filter(in_navigation=True,
- sites__domain=site.domain)
+ extenders = PageModel.objects.published().filter(in_navigation=True, site=site)
extenders = extenders.exclude(navigation_extenders__isnull=True).exclude(navigation_extenders__exact="")
children = []
from_level = 0
@@ -218,8 +217,7 @@ def show_breadcrumb(context, start_level=0, template="cms/breadcrumb.html"):
else:
site = Site.objects.get_current()
ancestors = []
- extenders = PageModel.objects.published().filter(in_navigation=True,
- sites__domain=site.domain)
+ extenders = PageModel.objects.published().filter(in_navigation=True, site=site)
extenders = extenders.exclude(navigation_extenders__isnull=True).exclude(navigation_extenders__exact="")
for ext in extenders:
ext.childrens = []
View
@@ -24,7 +24,7 @@ def setUp(self):
def get_new_page_data(self):
page_data = {'title':'test page %d' % self.counter,
'slug':'test-page-%d' % self.counter, 'language':'en',
- 'sites':[1], 'published':True, 'template':'index.html'}
+ 'site':1, 'published':True, 'template':'index.html'}
# required only if user haves can_change_permission
page_data['pagepermission_set-TOTAL_FORMS'] = 0
View
@@ -8,12 +8,13 @@ def is_valid_page_slug(page, parent, lang, slug):
from cms.models import Title
if cms_settings.CMS_UNIQUE_SLUGS:
+ print "unique slugs"
titles = Title.objects.filter(slug=slug)
else:
titles = Title.objects.filter(slug=slug, language=lang)
if not cms_settings.CMS_FLAT_URLS:
titles = titles.filter(page__parent=parent)
-
+ titles = titles.filter(page__site=page.site_id)
if page.pk:
titles = titles.exclude(language=lang, page=page)
if titles.count():
View
@@ -81,10 +81,11 @@
'django.middleware.doc.XViewMiddleware',
#'django.contrib.csrf.middleware.CsrfMiddleware',
+ 'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
- 'cms.middleware.user.CurrentUserMiddleware',
+
)
ROOT_URLCONF = 'example.urls'
@@ -146,7 +147,6 @@
CMS_NAVIGATION_EXTENDERS = (('example.categories.navigation.get_nodes', 'Categories'),)
CMS_SOFTROOT = True
-CMS_FLAT_URLS = True
CMS_MODERATOR = True
CMS_REDIRECTS = True

0 comments on commit ae171a7

Please sign in to comment.