Esempio n. 1
0
def view_all_articles(request):
    """all article"""

    articles_admin_url = newsletters_admin_url = add_article_url = add_newsletter_url = None

    if request.user.is_staff:
        article_class = get_article_class()

        view_name = 'admin:{0}_{1}_changelist'.format(get_model_app(article_class), get_model_name(article_class))
        articles_admin_url = reverse(view_name)

        newsletters_admin_url = reverse('admin:coop_cms_newsletter_changelist')

        add_newsletter_url = reverse('admin:coop_cms_newsletter_add')

    article_class = get_article_class()
    content_type = ContentType.objects.get_for_model(article_class)
    perm = '{0}.add_{1}'.format(content_type.app_label, content_type.model)
    if request.user.has_perm(perm):
        add_article_url = reverse('coop_cms_new_article')

    return render(
        request,
        'coop_cms/view_all_articles.html',
        {
            'articles': article_class.objects.filter(sites__id=settings.SITE_ID).order_by('-id')[:10],
            'newsletters': models.Newsletter.objects.all().order_by('-id')[:10],
            'editable': True,
            'articles_list_url': articles_admin_url,
            'newsletters_list_url': newsletters_admin_url,
            'add_article_url': add_article_url,
            'add_newsletter_url': add_newsletter_url,
        }
    )
Esempio n. 2
0
def new_link(request):
    """new link"""
    content_type = ContentType.objects.get_for_model(models.Link)
    perm = '{0}.add_{1}'.format(content_type.app_label, content_type.model)

    if not request.user.has_perm(perm):
        raise PermissionDenied

    if request.method == "POST":
        form = NewLinkForm(request.POST)
        if form.is_valid():
            form.save()
            form.save_m2m()
            homepage_url = reverse('coop_cms_homepage')
            next_url = request.META.get('HTTP_REFERER', homepage_url)
            success_message(request, _('The link has been created properly'))
            return HttpResponseRedirect(next_url)
    else:
        form = NewLinkForm()

    context = {
        'form': form,
    }

    return render(
        request,
        'coop_cms/popup_new_link.html',
        context
    )
Esempio n. 3
0
def set_homepage(request, article_id):
    """use the article as homepage"""
    article = get_object_or_404(get_article_class(), id=article_id)

    if not request.user.has_perm('can_edit_article', article):
        raise PermissionDenied

    if request.method == "POST":
        site_settings = models.SiteSettings.objects.get_or_create(
            site=Site.objects.get_current())[0]

        if homepage_no_redirection():
            site_settings.homepage_url = ''
            site_settings.homepage_article = article.slug
        else:
            site_settings.homepage_url = article.get_absolute_url()
            site_settings.homepage_article = ''
        site_settings.save()

        return HttpResponseRedirect(reverse('coop_cms_homepage'))

    context_dict = {
        'article': article,
        'title': _("Do you want to use this article as homepage?"),
    }

    return render(request, 'coop_cms/popup_set_homepage.html', context_dict)
Esempio n. 4
0
 def set_logo_size(self, logo_size=None, logo_crop=None):
     """change logo size"""
     if 'logo' in self.fields:
         thumbnail_src = self.logo_thumbnail(logo_size, logo_crop)
         update_url = reverse('coop_cms_update_logo',
                              args=[self.article.id])
         self.fields['logo'].widget = ImageEdit(
             update_url,
             thumbnail_src.url if thumbnail_src else '',
             attrs={"class": "resizable"})
Esempio n. 5
0
 def __init__(self, instance, attrs=None):
     super(GenericFieldRawIdWidget, self).__init__(attrs)
     nav_types = NavType.objects.all()
     self.base_nav_urls = []
     self.instance = instance
     for nav_type in nav_types:
         self.base_nav_urls.append(
             (
                 nav_type.content_type.id,
                 reverse(
                     'admin:{0}_{1}_changelist'.format(
                         nav_type.content_type.app_label,
                         nav_type.content_type.model
                     )
                 )
             )
         )
Esempio n. 6
0
def view_navnode(request, tree):
    """show info about the node when selected"""
    try:
        response = {}

        node_id = request.POST['node_id']
        node = models.NavNode.objects.get(tree=tree, id=node_id)
        model_name = object_label = ""

        # get the admin url
        if node.content_type:
            app, mod = node.content_type.app_label, node.content_type.model
            admin_url = reverse("admin:{0}_{1}_change".format(app, mod),
                                args=(node.object_id, ))

            # load and render template for the object
            # try to load the corresponding template and if not found use the default one
            model_name = "{0}".format(node.content_type)
            object_label = "{0}".format(node.content_object)
            template = select_template([
                "coop_cms/navtree_content/{0}.html".format(
                    node.content_type.name),
                "coop_cms/navtree_content/default.html"
            ])
        else:
            admin_url = ""
            template = select_template(
                ["coop_cms/navtree_content/default.html"])

        context_dict = {
            "node": node,
            "admin_url": admin_url,
            "model_name": model_name,
            "object_label": object_label,
        }

        html = template.render(make_context(request, context_dict))

        # return data has dictionary
        response['html'] = html
        response['message'] = "Node content loaded."

        return response
    except Exception:
        logger.exception("view_navnode")
        raise
def set_homepage(apps, schema_editor):
    # Move from homepage_for_site to SiteSettings
    site_class = apps.get_model("sites", "Site")
    for site in site_class.objects.all():
        try:
            homepage_article = site.homepage_article.all()[0]
        except (models.ObjectDoesNotExist, IndexError, AttributeError):
            homepage_article = None

        if homepage_article:
            site_settings_class = apps.get_model("coop_cms", "SiteSettings")
            site_settings = site_settings_class.objects.get_or_create(
                site=site)[0]
            if not site_settings.homepage_url:
                homepage_url = reverse('coop_cms_view_article',
                                       args=[homepage_article.slug])
                site_settings.homepage_url = homepage_url
                site_settings.save()
Esempio n. 8
0
def homepage(request):
    """view homepage"""
    if cms_no_homepage():
        raise Http404

    if homepage_no_redirection():
        article_slug = get_homepage_article()

        if article_slug:
            article_views = get_article_views()
            article_view = article_views['article_view']
            return article_view.as_view(as_homepage=True)(request,
                                                          slug=article_slug)

    else:
        homepage_url = get_homepage_url()
        if homepage_url:
            return HttpResponseRedirect(homepage_url)

    return HttpResponseRedirect(reverse('coop_cms_view_all_articles'))
Esempio n. 9
0
def _get_photologue_media(request):
    """get photologue media"""
    # Only if django-photologue is installed
    if "photologue" in settings.INSTALLED_APPS:
        from photologue.models import Photo, Gallery
        media_url = reverse('coop_cms_media_photologue')
        gallery_filter = request.GET.get('gallery_filter', 0)
        queryset = Photo.objects.all().order_by("-date_added")
        if gallery_filter:
            queryset = queryset.filter(galleries__id=gallery_filter)
            media_url += "?gallery_filter={0}".format(gallery_filter)

        context = {
            'media_url': media_url,
            'media_slide_template': 'coop_cms/medialib/slide_photologue_content.html',
            'gallery_filter': int(gallery_filter),
            'galleries': Gallery.objects.all(),
        }
        return queryset, context
    else:
        raise Http404
Esempio n. 10
0
 def get_success_url(self):
     """url to go after edition success"""
     return self.success_url or reverse(
         self.success_view_name) if self.success_view_name else ''
Esempio n. 11
0
def show_media(request, media_type):
    """show media library"""
    try:
        if not request.user.is_staff:
            raise PermissionDenied

        try:
            page = int(request.GET.get('page', 0) or 0)
        except ValueError:
            page = 1
        is_ajax = page > 0
        media_filter = request.GET.get('media_filter', 0)
        skip_media_filter = False

        if request.session.get("coop_cms_media_doc", False):
            # force the doc
            media_type = 'document'
            del request.session["coop_cms_media_doc"]

        if media_type == 'image':
            queryset = models.Image.objects.all().order_by("ordering", "-created")
            context = {
                'media_url': reverse('coop_cms_media_images'),
                'media_slide_template': 'coop_cms/medialib/slide_images_content.html',
            }

        elif media_type == 'photologue':
            queryset, context = _get_photologue_media(request)
            skip_media_filter = True

        else:
            media_type = "document"
            queryset = models.Document.objects.all().order_by("ordering", "-created")
            context = {
                'media_url': reverse('coop_cms_media_documents'),
                'media_slide_template': 'coop_cms/medialib/slide_docs_content.html',
            }

        context['is_ajax'] = is_ajax
        context['media_type'] = media_type

        if not skip_media_filter:
            # list of lists of media_filters
            media_filters = [media.filters.all() for media in queryset.all()]
            # flat list of media_filters
            media_filters = itertools.chain(*media_filters)
            # flat list of unique media filters sorted by alphabetical order (ignore case)
            context['media_filters'] = sorted(
                list(set(media_filters)), key=lambda mf: mf.name.upper()
            )

            if int(media_filter):
                queryset = queryset.filter(filters__id=media_filter)
                context['media_filter'] = int(media_filter)

        page_obj = paginate(request, queryset, 12)

        context[media_type+'s'] = list(page_obj)
        context['page_obj'] = page_obj

        context["allow_photologue"] = "photologue" in settings.INSTALLED_APPS

        if int(media_filter):
            context["media_url"] += '?media_filter={0}'.format(media_filter)

        template = get_template('coop_cms/medialib/slide_base.html')
        html = template.render(make_context(request, context))

        if is_ajax:
            data = {
                'html': html,
                'media_type': media_type,
                'media_url': context["media_url"],
            }
            return HttpResponse(json.dumps(data), content_type="application/json")
        else:
            return HttpResponse(html)
    except Exception:
        logger.exception("show_media")
        raise
Esempio n. 12
0
 def get_absolute_url(self):
     """get url"""
     return reverse(self.view_name)
Esempio n. 13
0
def get_login_url():
    """returns the URL of the login page"""
    try:
        return reverse("auth_login")
    except NoReverseMatch:
        return reverse("login")
Esempio n. 14
0
 def get_edit_url(self):
     """for unit-testing"""
     return reverse('coop_cms_testapp_edit', args=[self.id])
Esempio n. 15
0
 def get_absolute_url(self):
     """for unit-testing"""
     return reverse('coop_cms_testapp_detail', args=[self.id])
Esempio n. 16
0
 def get_list_url(self):
     """for unit-testing"""
     return reverse('coop_cms_testapp_list')