widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #16319
Re: [Merge] lp:~widelands-dev/widelands-website/more_latest_posts into lp:widelands-website
Added some nits for strings and comments.
The grouping doesn't work properly. In
http://alpha.widelands.org/forum/latest_posts/?days=400&sort_by=forum
I see the "Germany" forum twice and the topic "Na dann gucken wir mal wie das hier ist" 3 times.
In http://alpha.widelands.org/forum/latest_posts/?days=400&sort_by=topic, I see the same topic listed multiple times as well.
Diff comments:
>
> === modified file 'pybb/forms.py'
> --- pybb/forms.py 2018-12-21 11:26:08 +0000
> +++ pybb/forms.py 2019-03-18 21:30:36 +0000
> @@ -87,3 +87,17 @@
> post.updated = datetime.now()
> post.save(*args, **kwargs)
> return post
> +
> +
> +class LastPostsDayForm(forms.Form):
> + days = forms.IntegerField(
> + max_value = 1000,
> + min_value = 5,
> + label = 'Show posts created these days before today:'
Show posts created up to <form> days ago
> + )
> +
> + sort_by = forms.ChoiceField(
> + #widget = forms.RadioSelect,
> + choices = [('forum','Forum'),('topic', 'Topic'),],
> + label = 'Sort by:',
> + )
>
> === added file 'pybb/templates/pybb/all_last_posts.html'
> --- pybb/templates/pybb/all_last_posts.html 1970-01-01 00:00:00 +0000
> +++ pybb/templates/pybb/all_last_posts.html 2019-03-18 21:30:36 +0000
> @@ -0,0 +1,74 @@
> +{% extends 'pybb/base.html' %}
> +
> +{% block title %}
> + Latest posts - {{ block.super }}
> +{% endblock title %}
> +
> +{% block content_header %}
> + <h1>Latest Posts</h1>
> +{% endblock %}
> +
> +{% block content_main %}
> +<div class="blogEntry">
> +
> + <form action="." method="post" novalidate>
> + {% csrf_token %}
> + <span class="errormessage">{{ form.days.errors }}</span>
> + {{ form.days.label_tag }} {{ form.days }}
> + <span class="errormessage">{{ form.sort_by.errors }}</span>
> + {{ form.sort_by.label_tag }} {{ form.sort_by }}
> + <input type="submit" value="Submit" />
> + {% if form.errors %}
> + <p class="errormessage">
> + An error occured, some default values are used.
> + Please correct the erros above to get valuable results.
erros -> errors
> + </p>
> + {% else %}
> + <p>
> + Found {{ posts|length }} posts. The list is always sorted by the most recent post first.
> + </p>
> + {% endif %}
> + </form>
> +
> + <hr>
> +
> + {% if sort_by == 'topic' %}
> + {% regroup posts by topic as topic_list %}
> + {% for topic, posts in topic_list %}
> + <h2>{{ topic }}</h2>
> + <p>At Forum:
> + <a href="{% url 'pybb_forum' posts.0.topic.forum.id %}">{{ posts.0.topic.forum }}</a>
> + </p>
> + {% include 'pybb/inlines/latest_posts_table.html'%}
> + {% endfor %}
> + {% else %} {# sort by forum #}
> + {% regroup posts by topic.forum as forum_list %}
> + {% for forum, posts in forum_list %}
> + <h2>{{ forum }}</h2>
> + {% regroup posts by topic as topic_list %}
> + <table class='forum'>
> + <thead>
> + <tr>
> + <th style="text-align: left; width: 30%;">Topic{{ topic_list|length|pluralize }}</th>
> + <th style="text-align: left;">Post{{ posts|length|pluralize }}</th>
> + </tr>
> + </thead>
> + <tbody>
> + {% for topic, posts in topic_list %}
> + <tr class={% cycle 'odd' 'even' %}>
> + <td class='post'>
> + <a href="{% url 'pybb_topic' posts.0.topic.id %}">{{ posts.0.topic }}</a>
> + </td>
> + <td>
> + {% include 'pybb/inlines/latest_posts_table.html'%}
> + </td>
> + </tr>
> + {% endfor %}
> + </tbody>
> + </table>
> + {% empty %}
> + <p>Sorry, no posts found...</p>
> + {% endfor %}
> + {% endif %}
> +</div>
> +{% endblock %}
>
> === modified file 'pybb/templatetags/pybb_extras.py'
> --- pybb/templatetags/pybb_extras.py 2019-02-27 17:20:01 +0000
> +++ pybb/templatetags/pybb_extras.py 2019-03-18 21:30:36 +0000
> @@ -20,15 +20,18 @@
>
> @register.inclusion_tag('pybb/last_posts.html', takes_context=True)
> def pybb_last_posts(context, number=8):
> +
> + # Create a Queryset
> + last_posts = Post.objects.all().order_by(
> + '-created')
> +
> + # Permission depended Queryset filtering
depended -> dependent
> if pybb.views.allowed_for(context.request.user):
> - last_posts = Post.objects.filter(
> - hidden=False).order_by(
> - '-created')[:45]
> + last_posts = last_posts.filter(
> + hidden=False)[:100]
> else:
> - last_posts = Post.objects.filter(
> - hidden=False, topic__forum__category__internal=False).order_by(
> - '-created')[:45]
> -
> + last_posts = last_posts.filter(
> + hidden=False, topic__forum__category__internal=False)[:100]
>
> check = []
> answer = []
>
> === modified file 'pybb/views.py'
> --- pybb/views.py 2019-03-04 17:47:12 +0000
> +++ pybb/views.py 2019-03-18 21:30:36 +0000
> @@ -387,3 +389,71 @@
> first_post.save()
>
> return redirect(topic)
> +
> +
> +def all_latest_posts(request):
> + """Provide a view to show more latest posts."""
> +
> + # default values
> + sort_by_default = 'topic'
> + days_default = pybb_settings.LAST_POSTS_DAYS
> +
> + if request.method == 'POST':
> + # Executed if the form get submitted
Executed when the form is submitted
> + form = LastPostsDayForm(request.POST)
> + if form.is_valid():
> + days = form.cleaned_data['days']
> + sort_by = form.cleaned_data['sort_by']
> + url = '{}?days={days}&sort_by={sort_by}'.format(
> + reverse('all_latest_posts'),
> + days=days, sort_by=sort_by
> + )
> +
> + return HttpResponseRedirect(url)
> +
> + else: # request GET
> + # Initialize if no values are given or if the
> + # values are given in the url
> + days = request.GET.get('days', days_default)
> + sort_by = request.GET.get('sort_by', sort_by_default)
> +
> + # Create a bound form, so error messages are shown if
> + # the given values don't validate against the form
> + form = LastPostsDayForm(
> + {
> + 'days': days,
> + 'sort_by': sort_by,
> + }
> + )
> +
> + if not form.is_valid():
> + # I we are here, the user has likely modified the url with invalid
I -> If
> + # values and we apply defaults for the database query
> + days = days_default
> + sort_by = sort_by_default
> +
> + # Executed on every request (POST and GET)
> + search_date = date.today() - timedelta(int(days))
> +
> + last_posts = Post.objects.exclude(
> + topic__forum__category__internal=True).filter(
> + created__gte=search_date, hidden=False)
> +
> + if sort_by == 'topic':
> + last_posts = last_posts.order_by('-created', 'topic')
> + elif sort_by == 'forum':
> + last_posts = last_posts.order_by('-created', 'topic__forum')
> + else:
> + last_posts = []
> +
> + # exclude hidden topics
> + last_posts = [p for p in last_posts if not p.topic.is_hidden]
> +
> + return {
> + 'posts': last_posts,
> + 'form': form,
> + 'sort_by': sort_by
> + }
> +
> +
> +all_latest = render_to('pybb/all_last_posts.html')(all_latest_posts)
--
https://code.launchpad.net/~widelands-dev/widelands-website/more_latest_posts/+merge/364706
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/more_latest_posts into lp:widelands-website.
References