from copy import deepcopy
from mezzanine.core.admin import *
from mezzanine.pages.admin import PageAdmin
-#from orderable.admin import OrderableTabularInline #OrderableAdmin,
-from organization.magazine.models import Article, Brief, Topic, ArticleImage, ArticlePersonListBlockInline
-from organization.magazine.forms import BriefForm, ArticlePersonListForm
+from organization.magazine.models import *
+from organization.magazine.forms import *
class ArticleImageInline(TabularDynamicInlineAdmin):
form = ArticlePersonListForm
+class DynamicContentArticleInline(TabularDynamicInlineAdmin):
+
+ model = DynamicContentArticle
+ form = DynamicContentArticleForm
+
+ class Media:
+ js = (
+ static("mezzanine/js/admin/dynamic_inline.js"),
+ )
+
+
class ArticleAdminDisplayable(DisplayableAdmin):
fieldsets = deepcopy(ArticleAdmin.fieldsets)
exclude = ('related_posts',)
filter_horizontal = ['categories', 'related_articles', ]
- inlines = [ArticleImageInline, ArticlePersonAutocompleteInlineAdmin]
+ inlines = [ArticleImageInline,
+ ArticlePersonAutocompleteInlineAdmin,
+ DynamicContentArticleInline]
class BriefAdmin(admin.ModelAdmin): #OrderableTabularInline
import dal_queryset_sequence
import dal_select2_queryset_sequence
from django import forms
-from organization.magazine.models import Article, Topic, Brief, ArticlePersonListBlockInline
+from organization.magazine.models import *
from organization.pages.models import CustomPage
from organization.network.models import PersonListBlock
from mezzanine_agenda.models import Event
class Meta:
model = ArticlePersonListBlockInline
fields = ('person_list_block',)
+
+
+class DynamicContentArticleForm(autocomplete.FutureModelForm):
+
+ content_object = dal_queryset_sequence.fields.QuerySetSequenceModelField(
+ queryset=autocomplete.QuerySetSequence(
+ Article.objects.all(),
+ Event.objects.all()
+ ),
+ required=False,
+ widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-article'),
+ )
+
+ class Meta:
+ model = DynamicContentArticle
+ fields = ('content_object',)
--- /dev/null
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-23 16:03
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('contenttypes', '0002_remove_content_type_name'),
+ ('organization-magazine', '0003_articlepersonlistblockinline'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='DynamicContentArticle',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('_order', mezzanine.core.fields.OrderField(null=True, verbose_name='Order')),
+ ('object_id', models.PositiveIntegerField(editable=False, null=True, verbose_name='related object')),
+ ('article', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='organization-magazine.Article', verbose_name='article')),
+ ('content_type', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType', verbose_name='content type')),
+ ],
+ options={
+ 'verbose_name': 'Dynamic Content Article',
+ 'ordering': ('_order',),
+ },
+ ),
+ ]
--- /dev/null
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-23 16:21
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('organization-magazine', '0004_dynamiccontentarticle'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='dynamiccontentarticle',
+ name='article',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dynamic_content_articles', to='organization-magazine.Article', verbose_name='article'),
+ ),
+ ]
def __str__(self):
return self.title
+
+
+class DynamicContentArticle(DynamicContent, Orderable):
+
+ article = models.ForeignKey(Article, verbose_name=_('article'), related_name='dynamic_content_articles', blank=True, null=True, on_delete=models.SET_NULL)
+
+ class Meta:
+ verbose_name = 'Dynamic Content Article'
from mezzanine.core.translation import (TranslatedSlugged,
TranslatedDisplayable,
TranslatedRichText)
-from organization.magazine.models import (Article,
- Topic,
- Brief,
- ArticleImage,
- ArticlePersonListBlockInline)
+from organization.magazine.models import *
+
@register(Article)
class ArticleTranslationOptions(TranslationOptions):
class ArticlePersonListBlockInlineTranslationOptions(TranslationOptions):
pass
+
+
+@register(DynamicContentArticle)
+class DynamicContentArticleTranslationOptions(TranslationOptions):
+
+ pass
url("^article/detail/(?P<slug>.*)%s$" % _slash, ArticleDetailView.as_view(), name="magazine-article-detail"),
url("^topic/detail/(?P<slug>.*)%s$" % _slash, TopicDetailView.as_view(), name='topic-detail'),
url("^object-autocomplete/$", ObjectAutocomplete.as_view(), name='object-autocomplete'),
+ url("^dynamic-content-article/$", DynamicContentArticleView.as_view(), name='dynamic-content-article'),
]
qs = self.mixup_querysets(qs)
return qs
+
+
+class DynamicContentArticleView(Select2QuerySetSequenceView):
+ def get_queryset(self):
+
+ articles = Article.objects.all()
+ events = Event.objects.all()
+
+ if self.q:
+ articles = articles.filter(title__icontains=self.q)
+ events = events.filter(title__icontains=self.q)
+
+ qs = autocomplete.QuerySetSequence(articles, events )
+
+ if self.q:
+ # This would apply the filter on all the querysets
+ qs = qs.filter(title__icontains=self.q)
+
+ # This will limit each queryset so that they show an equal number
+ # of results.
+ qs = self.mixup_querysets(qs)
+
+ return qs
--- /dev/null
+{% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
+
+<a class="article-box" href="{{ content.content_object.get_absolute_url }}" title="{{ content.content_object.title }}">
+ <div class="article-box__header">
+ <figure class="article-box__image">
+ {% with content.content_object.images.all|get_type:'card' as image %}
+ {% if image %}
+ <img src="{{ MEDIA_URL }}{% thumbnail image.first.file 427 286 %}" data-src="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 %}" class="lazyload" alt="" />
+ {% endif %}
+ {% endwith %}
+ </figure>
+ {% if content.content_type.model == 'article' %}
+ <div class="article-box__tags">
+ <div class="tag tag--small tag--category">
+ {% trans 'News' %}
+ </div>
+ {% if content.content_object.department %}
+ <div class="tag tag--small dashed dashed--gray">
+ {{ content.content_object.department.name }}
+ </div>
+ {% endif %}
+ </div>
+ {% elif content.content_type.model == 'event' %}
+ <div class="article-box__tags">
+ {% if content.content_object.departments.first %}
+ {% with content.content_object.departments.first as department %}
+ <div class="tag tag--small dashed">
+ {{ department.department.name }}
+ </div>
+ {% endwith %}
+ {% endif %}
+ {% if content.content_object.category %}
+ <div class="tag tag--small tag--category">
+ {{ content.content_object.category }}
+ </div>
+ {% endif %}
+ </div>
+ {% endif %}
+ </div>
+
+ <div class="article-box__content tal">
+ <h3 class="article-box__title">{{ content.content_object.title }}</h3>
+ <div class="article-box__subtitle">
+ {% if content.content_type.model == 'article' %}
+ {{ content.content_object.publish_date|date:"DATE_FORMAT" }}
+ {% for category in content.content_object.categories.all %}
+ {% if forloop.first %} | {% endif %}
+ {% if not forloop.first %}, {% endif %}
+ <strong>{{ category }}</strong>
+ {% endfor %}
+ {% elif content.content_type.model == 'event' %}
+ {% if content.content_object.start %}
+ {% if content.content_object.end %}
+ {% trans "From" %}
+ {% endif %}
+ {{ content.content_object.start|date:"DATE_FORMAT" }}
+ {% if content.content_object.end %}
+ {% trans "to" %} {{ content.content_object.end|date:"DATE_FORMAT" }}
+ {% endif %}
+ {% endif %}
+ {% if content.content_object.location %}
+ <br /><strong>{{ content.content_object.location }}</strong>
+ {% endif %}
+ {% endif %}
+ </div>
+ <div class="article-box__desc">
+ {{ content.content_object.description|richtext_filters|safe|truncatechars_html:200 }}
+ </div>
+ </div>
+</a>
<div class="container">
<div class="row">
- {% for body in home.dynamiccontenthomebody_set.all %}
+ {% for content in home.dynamiccontenthomebody_set.all %}
<div class="col-xs-4">
- {% if body.content_type.model == "brief" %}
- {% include "home/inc/brief_card.html" %}
+ {% if content.content_type.model == "brief" %}
+ {% include "magazine/brief/inc/brief_card.html" %}
{% else %}
- {% include "home/inc/generic_card.html" %}
+ {% include "core/inc/generic_card.html" %}
{% endif %}
</div>
{% endfor %}
+++ /dev/null
-{% load i18n %}
-
-<div class="brief-box">
-
- <div class="brief-box__head">
- {% trans 'Brief !' %}
- </div>
-
- <h3 class="brief-box__title">{{ body.content_object.title }}</h3>
- <div class="brief-box__desc">
- {{ body.content_object.description|slice:":500" }}
- </div>
- {% if body.content_object.external_content %}
- <a class="brief-box__button" href="{{ body.content_object.external_content }}" title="{{ body.content_object.text_button }}">{{ body.content_object.text_button }}</a>
- {% elif body.content_object.content_object %}
- <a class="brief-box__button" href="{{ body.content_object.content_object.get_absolute_url }}" title="{{ body.content_object.text_button }}">{{ body.content_object.text_button }}</a>
- {% else %}
- <a class="brief-box__button" href="{{ body.content_object.get_absolute_url }}" title="{{ body.content_object.title }}">{{ body.content_object.title }}</a>
- {% endif %}
-
-</div>
+++ /dev/null
-{% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
-
-<a class="article-box" href="{{ body.content_object.get_absolute_url }}" title="{{ body.content_object.title }}">
- <div class="article-box__header">
- <figure class="article-box__image">
- {% with body.content_object.images.all|get_type:'card' as image %}
- {% if image %}
- <img src="{{ MEDIA_URL }}{% thumbnail image.first.file 427 286 %}" data-src="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 %}" class="lazyload" alt="" />
- {% endif %}
- {% endwith %}
- </figure>
- {% if body.content_type.model == 'article' %}
- <div class="article-box__tags">
- <div class="tag tag--small tag--category">
- {% trans 'News' %}
- </div>
- {% if body.content_object.department %}
- <div class="tag tag--small dashed dashed--gray">
- {{ body.content_object.department.name }}
- </div>
- {% endif %}
- </div>
- {% elif body.content_type.model == 'event' %}
- <div class="article-box__tags">
- {% if body.content_object.departments.first %}
- {% with body.content_object.departments.first as department %}
- <div class="tag tag--small dashed">
- {{ department.department.name }}
- </div>
- {% endwith %}
- {% endif %}
- {% if body.content_object.category %}
- <div class="tag tag--small tag--category">
- {{ body.content_object.category }}
- </div>
- {% endif %}
- </div>
- {% endif %}
- </div>
-
- <div class="article-box__content tal">
- <h3 class="article-box__title">{{ body.content_object.title }}</h3>
- <div class="article-box__subtitle">
- {% if body.content_type.model == 'article' %}
- {{ body.content_object.publish_date|date:"DATE_FORMAT" }}
- {% for category in body.content_object.categories.all %}
- {% if forloop.first %} | {% endif %}
- {% if not forloop.first %}, {% endif %}
- <strong>{{ category }}</strong>
- {% endfor %}
- {% elif body.content_type.model == 'event' %}
- {% if body.content_object.start %}
- {% if body.content_object.end %}
- {% trans "From" %}
- {% endif %}
- {{ body.content_object.start|date:"DATE_FORMAT" }}
- {% if body.content_object.end %}
- {% trans "to" %} {{ body.content_object.end|date:"DATE_FORMAT" }}
- {% endif %}
- {% endif %}
- {% if body.content_object.location %}
- <br /><strong>{{ body.content_object.location }}</strong>
- {% endif %}
- {% endif %}
- </div>
- <div class="article-box__desc">
- {{ body.content_object.description|richtext_filters|safe|truncatechars_html:200 }}
- </div>
- </div>
-</a>
{% endfor %}
{% endblock %}
-
{% block page_related_content %}
-
- {% if article.related_articles.all %}
-
+ {% if article.dynamic_content_articles.all %}
<hr class="mt0 mb0" />
<div class="white-bg pb2">
<div class="container">
</div>
</div>
<div class="row tac">
- {% for article in article.related_articles.all %}
+ {% for content in article.dynamic_content_articles.all %}
+ {% if content.content_model == "article" %}
+ <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
+ {% include 'magazine/article/includes/article_card.html' %}
+ </div>
+ {% else %}
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
- {% include 'magazine/article/includes/article_card.html' %}
+ {% include "core/inc/generic_card.html" %}
</div>
+ {%endif%}
{% endfor %}
</div>
</div>
</div>
-
{% endif %}
-
{% endblock %}
{% block page_sidebar %}
--- /dev/null
+{% load i18n %}
+
+<div class="brief-box">
+
+ <div class="brief-box__head">
+ {% trans 'Brief !' %}
+ </div>
+
+ <h3 class="brief-box__title">{{content.content_object.title }}</h3>
+ <div class="brief-box__desc">
+ {{content.content_object.description|slice:":500" }}
+ </div>
+ {% if content.content_object.external_content %}
+ <a class="brief-box__button" href="{{ content.content_object.external_content }}" title="{{ content.content_object.text_button }}">{{ content.content_object.text_button }}</a>
+ {% elif content.content_object.content_object %}
+ <a class="brief-box__button" href="{{ content.content_object.content_object.get_absolute_url }}" title="{{ content.content_object.text_button }}">{{ content.content_object.text_button }}</a>
+ {% else %}
+ <a class="brief-box__button" href="{{ content.content_object.get_absolute_url }}" title="{{ content.content_object.title }}">{{ content.content_object.title }}</a>
+ {% endif %}
+
+</div>
</div>
{% pagination_for articles %}
-
+
{% endblock %}