Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 31 Mar 2019 14:05:31 UTC Commit: 673822f0b41476032a21f52cd27b1de2f564d27b https://github.com/geany/www.geany.org/commit/673822f0b41476032a21f52cd27b1d...
Log Message: ----------- Update and fix a few issues in the news app
Modified Paths: -------------- news/admin.py news/feeds.py news/models.py news/sitemaps.py news/templates/news/detail.html news/templates/news/list.html news/templates/news/list_embedded.html news/templatetags/news_tags.py news/urls.py
Modified: news/admin.py 69 lines changed, 13 insertions(+), 56 deletions(-) =================================================================== @@ -12,22 +12,21 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from django.conf.urls import patterns, url from django.contrib import admin -from django.core.urlresolvers import reverse -from django.http import HttpResponseRedirect -from django.templatetags.static import static from mezzanine.core.models import CONTENT_STATUS_DRAFT, CONTENT_STATUS_PUBLISHED + from news.models import NewsPost
######################################################################## class NewsPostAdmin(admin.ModelAdmin): - list_display = ('title', 'user', '_is_published_switch', 'publish_date') - date_hierarchy = 'publish_date' + list_display = ('title', 'user', 'status', 'publish_date') + list_editable = ("status",) list_filter = ('publish_date', 'status') + date_hierarchy = 'publish_date' exclude = ('slug', 'user', 'entry_date') actions = ['_toggle_many_published'] + radio_fields = {"status": admin.HORIZONTAL}
#---------------------------------------------------------------------- def save_model(self, request, obj, form, change): @@ -36,54 +35,6 @@ def save_model(self, request, obj, form, change): obj.user = request.user obj.save()
- #---------------------------------------------------------------------- - def get_urls(self): - urls = admin.ModelAdmin.get_urls(self) - my_urls = patterns( - '', - url( - r'^toggle_published/([0-9]+)/$', - self.admin_site.admin_view(self._toggle_published), - name='news_post_toggle_published'),) - return my_urls + urls - - #---------------------------------------------------------------------- - def _is_published_switch(self, obj): - toggle_published_url = reverse('admin:news_post_toggle_published', args=(obj.id,)) - yes_no = 'yes' if obj.status == CONTENT_STATUS_PUBLISHED else 'no' - static_path = static('admin/img/icon-{}.gif'.format(yes_no)) - value = obj.status - return '<a href="{}"><img src="{}" alt="{}"/></a>'.format( - toggle_published_url, - static_path, - value) - - #---------------------------------------------------------------------- - def _toggle_published(self, request, newspost_id): - newspost = NewsPost.objects.get(pk=newspost_id) - self._toggle_newspost_published_status(newspost) - self.message_user( - request, - u'News post public status have been changed.', - fail_silently=True) - # redirect back to the changelist page - changelist_url = self._admin_url('changelist') - return HttpResponseRedirect(changelist_url) - - #---------------------------------------------------------------------- - def _toggle_newspost_published_status(self, newspost): - if newspost.status == CONTENT_STATUS_PUBLISHED: - newspost.status = CONTENT_STATUS_DRAFT - else: - newspost.status = CONTENT_STATUS_PUBLISHED - newspost.save() - - #---------------------------------------------------------------------- - def _admin_url(self, target_url): - opts = self.model._meta - url_ = "admin:%s_%s_%s" % (opts.app_label, opts.object_name.lower(), target_url) - return reverse(url_) - #---------------------------------------------------------------------- def _toggle_many_published(self, request, queryset): # this is not really as efficient as it could be as the query is performed, but I don't know @@ -94,8 +45,14 @@ def _toggle_many_published(self, request, queryset): rows_updated += 1 self.message_user(request, "{} News posts were successfully changed.".format(rows_updated))
- _is_published_switch.allow_tags = True - _is_published_switch.short_description = 'Is published' + #---------------------------------------------------------------------- + def _toggle_newspost_published_status(self, newspost): + if newspost.status == CONTENT_STATUS_PUBLISHED: + newspost.status = CONTENT_STATUS_DRAFT + else: + newspost.status = CONTENT_STATUS_PUBLISHED + newspost.save() + _toggle_many_published.short_description = "Toggle the published status of selected News posts"
Modified: news/feeds.py 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -13,7 +13,7 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
from django.contrib.syndication.views import Feed -from django.core.urlresolvers import reverse +from django.urls import reverse from mezzanine.core.templatetags.mezzanine_tags import richtext_filters from mezzanine.utils.html import absolute_urls from mezzanine.conf import settings @@ -32,7 +32,7 @@ def link(self):
#---------------------------------------------------------------------- def items(self): - return NewsPost.objects.recently_published(count=20) + return NewsPost.objects.recently_published(count=200)
#---------------------------------------------------------------------- def item_title(self, item):
Modified: news/models.py 5 lines changed, 3 insertions(+), 2 deletions(-) =================================================================== @@ -12,8 +12,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from django.core.urlresolvers import reverse from django.db import models +from django.urls import reverse from django.utils import timezone from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ @@ -59,7 +59,8 @@ class NewsPost(models.Model): user = models.ForeignKey( get_user_model_name(), verbose_name=_('Author'), - related_name='%(class)ss') + related_name='%(class)ss', + on_delete=models.PROTECT) status = models.IntegerField( _('Status'), choices=CONTENT_STATUS_CHOICES,
Modified: news/sitemaps.py 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -22,4 +22,4 @@ class NewsPostSitemap(StaticSitemap):
#---------------------------------------------------------------------- def get_dynamic_items(self): - return list(NewsPost.objects.recently_published(count=10)) + return list(NewsPost.objects.recently_published(count=30))
Modified: news/templates/news/detail.html 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -26,6 +26,6 @@ <h2>{{ newspost.title }}</h2> <div class="clearfix"></div> </div>
-{{ newspost.content|richtext_filter|safe }} +{{ newspost.content|richtext_filters|safe }}
{% endblock %}
Modified: news/templates/news/list.html 73 lines changed, 57 insertions(+), 16 deletions(-) =================================================================== @@ -6,6 +6,10 @@ <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/newspost.css"> {% endblock %}
+{% block extra_head %} +{{ block.super }} +<link rel="alternate" type="application/rss+xml" title="RSS" href="{% url "news_feed" %}"> +{% endblock %}
{% block meta_title %}{% if page %}{{ page.richtextpage.meta_title }}{% else %}{% trans "News" %}{% endif %}{% endblock %}
@@ -17,27 +21,64 @@ {% block richtext_content %}
<h2>News</h2> +{% regroup object_list|dictsortreversed:"publish_date" by publish_date.year as newsposts_by_year %} +<div id="accordion" class="panel-group"> +{% for by_year in newsposts_by_year %} + <div class="panel panel-default"> + <div class="panel-heading"> + <h4 class="panel-title"> + <a data-toggle="collapse" data-parent="#accordion" href="#collapse{{ forloop.counter }}"> + <span class="glyphicon glyphicon-plus"></span> + {{ by_year.grouper }} + </a> + </h4> + </div> + <div id="collapse{{ forloop.counter }}" class="panel-collapse collapse{% if forloop.counter0 == 0 %} in{% endif %}"> + <div class="panel-body list-group">
-<div class="list-group"> -{% for newspost in object_list %} - <div class="list-group-item"> - <div class="list-group-item-heading"> - <div class="pull-left"> - <h4> - <a href="{{ newspost.get_absolute_url }}">{{ newspost.title }}</a> - </h4> - </div> - <div class="pull-right"> - {{ newspost.publish_date|date:"F dS, Y" }} + {% for newspost in by_year.list %} + <div class="list-group-item"> + <div class="list-group-item-heading"> + <div class="pull-left"> + <h4> + <a href="{{ newspost.get_absolute_url }}">{{ newspost.title }}</a> + </h4> + </div> + <div class="pull-right"> + {{ newspost.publish_date|date:"F dS, Y" }} + </div> + <div class="clearfix"></div> + </div> + <div class="list-group-item-text"> + {{ newspost.content|striptags|truncatechars:75 }} + <a href="{{ newspost.get_absolute_url }}" class="small">more</a> + </div> + </div> + {% endfor %} </div> - <div class="clearfix"></div> - </div> - <div class="list-group-item-text"> - {{ newspost.content|striptags|truncatechars:75 }} - <a href="{{ newspost.get_absolute_url }}" class="small">more</a> </div> </div> {% endfor %} </div>
+ +{% endblock %} + + +{% block footer_js %} +<script type="text/javascript"> + $(document).ready(function(){ + // Add minus icon for collapse element which is open by default + $(".collapse.in").each(function(){ + $(this).siblings(".panel-heading").find(".glyphicon").addClass("glyphicon-minus").removeClass("glyphicon-plus"); + }); + + // Toggle plus minus icon on show hide of collapse element + $(".collapse").on('show.bs.collapse', function(){ + $(this).parent().find(".glyphicon").removeClass("glyphicon-plus").addClass("glyphicon-minus"); + }).on('hide.bs.collapse', function(){ + $(this).parent().find(".glyphicon").removeClass("glyphicon-minus").addClass("glyphicon-plus"); + }); + }); +</script> {% endblock %}
Modified: news/templates/news/list_embedded.html 13 lines changed, 3 insertions(+), 10 deletions(-) =================================================================== @@ -10,19 +10,12 @@ <span class="small">- {{ newspost.publish_date|date:"F Y" }}</span> </li> {% endfor %} -</ul> - -{% comment %} -<ul class="list-group"> -{% for newspost in recent_news_posts %} <li class="list-group-item"> - <a href="#" data-toggle="modal" data-target="#news-modal" id="news-post-{{ newspost.slug }}"> - {{ newspost.title }} - </a> + <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span> + <a href="{% url 'news_list' %}">Older news</a> </li> -{% endfor %} </ul> -{% endcomment %} +
<!-- Modal --> <div class="modal fade" id="news-modal" tabindex="-1" role="dialog" aria-labelledby="news-modal-label">
Modified: news/templatetags/news_tags.py 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -22,5 +22,5 @@ @register.inclusion_tag("news/list_embedded.html", takes_context=True) def get_recent_news(context): user = context.request.user - context["recent_news_posts"] = NewsPost.objects.recently_published(for_user=user) + context["recent_news_posts"] = NewsPost.objects.recently_published(count=4, for_user=user) return context
Modified: news/urls.py 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -22,7 +22,7 @@ urlpatterns = ( url(r'^$', NewsListView.as_view(), name='news_list'), url(r'^feed/$', LatestNewsPostsFeed(), name='news_feed'), - url(r'^(?P<newspost_slug>.+)$', NewsDetailView.as_view(), name='news_detail'), + url(r'^(?P<newspost_slug>.+)/$', NewsDetailView.as_view(), name='news_detail'), )
# register our urlpatterns to the global sitemap generator
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).