1 # Copyright 2012 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
35 from datetime import datetime
37 from django.db import models
38 from django.conf import settings
39 from django.contrib.auth.models import User
40 from django.utils.translation import ugettext_lazy as _, ugettext, ungettext
41 from django.template.loader import render_to_string
42 from django.core import urlresolvers
44 from feincms import translations
45 from feincms.models import Base
46 from feincms.module.page.models import Page
47 from feincms.content.application.models import reverse
48 from feincms.content.richtext.models import RichTextContent
49 from feincms.content.section.models import SectionContent
50 from feincms.module.medialibrary.fields import MediaFileForeignKey
51 from feincms.module.medialibrary.models import MediaFile
52 from feincms.module.page.extensions.navigation import NavigationExtension
53 from feincms.module.page.extensions.navigation import PagePretender
54 from feincms.content.application.models import ApplicationContent
55 from feincms.models import Base, create_base_model
57 from cloudcms.cms_utils import get_app_page
59 class UserGuideEntryManager(models.Manager):
62 return self.filter(is_active=True)
64 def latest(self, limit=3):
65 return self.filter()[:limit]
70 Returns Page model that has been associated with userguide application
72 return get_app_page(Page, "cloudcmsguide")
77 from mptt.models import MPTTModel
79 Base = create_base_model(MPTTModel)
84 class UserGuideEntry(Base):
88 is_active = models.BooleanField(_('is active'), default=True)
89 is_featured = models.BooleanField(_('is featured'), default=False)
91 title = models.CharField(_('title'), max_length=100)
92 slug = models.SlugField(_('slug'), max_length=100, unique_for_date='published_on')
93 author = models.ForeignKey(User, related_name='guide_pages', verbose_name=_('author'))
94 language = models.CharField(max_length=255, choices=settings.LANGUAGES)
96 published_on = models.DateTimeField(_('published on'), blank=True, null=False, default=datetime.now,
97 help_text=_('Will be filled in automatically when entry gets published.'))
98 last_changed = models.DateTimeField(_('last change'), auto_now=True, editable=False)
100 service = models.ForeignKey('cloudcms.Service', verbose_name=_('service'),
101 related_name='userguideentries', null=True, blank=False)
103 parent = models.ForeignKey('self', verbose_name=_('Parent'), blank=True, null=True, related_name='children')
105 objects = UserGuideEntryManager()
108 get_latest_by = 'published_on'
109 ordering = ['service', 'published_on']
110 verbose_name = _('User guide entry')
111 verbose_name_plural = _('User guide entries')
113 def __unicode__(self):
117 return self.get_next_by_published_on(service=self.service)
119 def get_previous(self):
120 return self.get_previous_by_published_on(service=self.service)
122 def get_absolute_url(self):
124 r = reverse('cloudcmsguide_entry_detail', 'cloudcmsguide.urls', (),
126 'service': self.service.translation.slug,
133 # ugly hack to fix proper application reverse url
136 GUIDE_URL = get_guide_page().get_navigation_url()
140 if r.startswith(GUIDE_URL):
143 return GUIDE_URL + r.lstrip('/')
146 return get_guide_page().get_navigation_url()
148 if mptt_register: # MPTT 0.3 legacy support
151 UserGuideEntry.register_extensions(