def get_absolute_url(self, language=None, fallback=True): if self.is_home(): return reverse("pages-root") if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) return urlutils.urljoin(reverse("pages-root"), path) # else path = self.get_path(language, fallback) return urlutils.urljoin(reverse("pages-root"), path)
def get_absolute_url(self, language=None, fallback=True): if self.is_home(): return reverse('pages-root') if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) return urlutils.urljoin(reverse('pages-root'), path) # else path = self.get_path(language, fallback) return urlutils.urljoin(reverse('pages-root'), path)
def get_absolute_url(self, language=None, fallback=True): try: if self.is_home(): return reverse('pages-root') except NoHomeFound: pass if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) else: path = self.get_path(language, fallback) if hasattr(self, "home_cut_cache") and self.home_cut_cache: if not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: path = "/".join(path.split("/")[1:]) else: home_pk = None try: home_pk = self.home_pk_cache except NoHomeFound: pass ancestors = self.get_cached_ancestors(ascending=True) if self.parent_id and ancestors[-1].pk == home_pk and not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: path = "/".join(path.split("/")[1:]) if settings.CMS_DBGETTEXT and settings.CMS_DBGETTEXT_SLUGS: path = '/'.join([ugettext(p) for p in path.split('/')]) return urljoin(reverse('pages-root'), path)
def send_mail(subject, txt_template, to, context=None, html_template=None, fail_silently=True): """ Multipart message helper with template rendering. """ site = Site.objects.get_current() context = context or {} context.update({ 'login_url': "http://%s" % urljoin(site.domain, admin_reverse('index')), 'title': subject, }) txt_body = render_to_string(txt_template, context) message = EmailMultiAlternatives(subject=subject, body=txt_body, to=to) if html_template: body = render_to_string(html_template, context) message.attach_alternative(body, 'text/html') message.send(fail_silently=fail_silently)
def get_absolute_url(self, language=None, fallback=True): try: if self.is_home(): return reverse('pages-root') except NoHomeFound: pass if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) else: path = self.get_path(language, fallback) if hasattr(self, "home_cut_cache") and self.home_cut_cache: if not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: path = "/".join(path.split("/")[1:]) else: home_pk = None try: home_pk = self.home_pk_cache except NoHomeFound: pass """ this is pain slow! the code fetches all ancestors for all pages and then checks if the root node is a home_pk, if yes, it cuts off the first path part. """ ancestors = self.get_cached_ancestors(ascending=True) # sometimes there are no ancestors if len(ancestors) != 0: if self.parent_id and ancestors[-1].pk == home_pk and not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path: path = "/".join(path.split("/")[1:]) return urlutils.urljoin(reverse('pages-root'), path)
def get_absolute_url(self, language=None, fallback=True): try: if self.is_home(): return reverse("pages-root") except NoHomeFound: pass if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) else: path = self.get_path(language, fallback) home_pk = None try: home_pk = self.home_pk_cache except NoHomeFound: pass ancestors = self.get_cached_ancestors() if ( self.parent_id and ancestors[-1].pk == home_pk and not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path ): path = "/".join(path.split("/")[1:]) return urljoin(reverse("pages-root"), path)
def get_absolute_url(self, language=None, fallback=True): #if self.is_home(): # return "/" if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) else: path = self.get_path(language, fallback) return urljoin(reverse('pages-root'), path)
def language_changer(self, language): url = self.get_absolute_url(language) if url: return url # There is no entry in the given language, we return blog's root blog_prefix = '' try: title = Title.objects.get(application_urls='BlogApphook', language=language) blog_prefix = urljoin(reverse('pages-root'), title.overwrite_url or title.slug) except Title.DoesNotExist: # Blog app hook not defined anywhere? pass return blog_prefix or reverse('pages-root')
def send_mail(subject, txt_template, to, context=None, html_template=None, fail_silently=True): """Multipart message helper with template rendering. """ site = Site.objects.get_current() context = context or {} context.update({ 'login_url': "http://%s" % urljoin(site.domain, admin.site.root_path), 'title': subject, }) txt_body = render_to_string(txt_template, context) message = EmailMultiAlternatives(subject=subject, body=txt_body, to=to) if html_template: body = render_to_string(html_template, context) message.attach_alternative(body, 'text/html') message.send(fail_silently=fail_silently)
def mail_approvement_request(page, user=None): """Sends approvement request over email to all users which should approve this page if they have an email entered. Don't send it to current user - he should now about it, because he made the change. """ if not settings.CMS_MODERATOR or not page.requires_approvement(): return recipient_list = [] for moderator in page.get_moderator_queryset(): email = moderator.user.email if email and not email in recipient_list: recipient_list.append(email) if user and user.email in recipient_list: recipient_list.remove(user.email) if not recipient_list: return from django.contrib import admin from django.contrib.sites.models import Site from cms.utils.urlutils import urljoin from cms.utils.mail import send_mail site = Site.objects.get_current() subject = _('CMS - Page %s requires approvement.') % unicode(page) context = { 'page': page, 'admin_url': "http://%s" % urljoin(site.domain, admin.site.root_path, 'cms/page', page.id), } send_mail(subject, 'admin/cms/mail/approvement_required.txt', recipient_list, context, 'admin/cms/mail/approvement_required.html')
def get_absolute_url(self, language=None, fallback=True): try: if self.is_home(): return reverse('pages-root') except NoHomeFound: pass if settings.CMS_FLAT_URLS: path = self.get_slug(language, fallback) else: path = self.get_path(language, fallback) home_pk = None try: home_pk = self.home_pk_cache except NoHomeFound: pass ancestors = self.get_cached_ancestors() if self.parent_id and ancestors[ -1].pk == home_pk and not self.get_title_obj_attribute( "has_url_overwrite", language, fallback) and path: path = "/".join(path.split("/")[1:]) return urljoin(reverse('pages-root'), path)
def mail_approvement_request(page, user=None): """Sends approvement request over email to all users which should approve this page if they have an email entered. Don't send it to current user - he should know about it, because he made the change. """ if not settings.CMS_MODERATOR or not page.requires_approvement(): return recipient_list = [] for moderator in page.get_moderator_queryset(): email = moderator.user.email if email and not email in recipient_list: recipient_list.append(email) if user and user.email in recipient_list: recipient_list.remove(user.email) if not recipient_list: return from django.contrib import admin from django.contrib.sites.models import Site from cms.utils.urlutils import urljoin from cms.utils.mail import send_mail site = Site.objects.get_current() subject = _('CMS - Page %s requires approvement.') % unicode(page) context = { 'page': page, 'admin_url': "http://%s" % urljoin(site.domain, admin.site.root_path, 'cms/page', page.id), } send_mail(subject, 'admin/cms/mail/approvement_required.txt', recipient_list, context, 'admin/cms/mail/approvement_required.html')
def test_02_urljoin(self): self.assertEqual('a/b/c/', urlutils.urljoin('a', 'b', 'c')) self.assertEqual('a/b/c/', urlutils.urljoin('a', '//b//', 'c')) self.assertEqual('a/', urlutils.urljoin('a', ''))