Closed rhaskara closed 7 years ago
It seems this is a regression, see 3e93cdb92a0d4988a4f3d39768a905dd691e0b30. @DylannCordel, what do you think?
@lampslave : we now have tests which use those templates / templatetags. It seems ok for me. I just re-run all tests from master. pybb_may_admin_post
is for exemple called in TestTemplateTags.test_post_actions_staff_with_perms
to check admin link is generated when user can admin a post. pybb_get_time
is used in TestTemplateTags.test_pybb_get_time
for exemple.
@rhaskara : Do you use a recent version of pybb ? There was a regression in #255 (merged on 22 jan) fixed in #262 (merged on 10 Feb).
If you use the up to date master, do you load the pybb tags with {% load pybb_tags %}
in your templates ?
@DylannCordel I do have a recent version of pybb, and I do the loading of pybb tags with
{% load pybb_tags i18n %}
@rhaskara could you:
PermissionHandler
(setting PYBB_PERMISSION_HANDLER
) ? If yes, could you copy past it here please ?templatetags/pybb_tags.py
file ?Thanks
django version 1.10 python version 2.7.13 -- Switched from python 3 pybbm version: 0.18.4 I installed the package via pip for python 2.7 about a week ago. Should have the latest package running.
Both templates that I have on is the exact copy from this repository with minor edits.
{% load pybb_tags i18n %}
{% block title %}
{% pybb_get_profile target_user as target_profile %}
{{ target_profile.get_display_name }}
{% endblock %}
{% block content %}
<div class="panel panel-default panel-warc">
<div class="panel-body">
{% pybb_get_profile target_user as target_profile %}
<h1>{{ target_profile.get_display_name }}</h1>
<div class="userinfo">
{% include 'pybb/avatar.html' with user=target_user %}
<div class="info">
<div class="label">{% trans 'Statistics' %}</div>
<div>
<a href="{% url 'pybb:user_topics' target_user.get_username %}">
{% blocktrans with count=topic_count %}Number of topics: {{ count }}{% endblocktrans %}
</a>
</div>
<div>
<a href="{% url 'pybb:user_posts' target_user.get_username %}">
{% blocktrans with count=target_profile.post_count %}Number of posts: {{ count }}{% endblocktrans %}
</a>
</div>
<div>
{% pybb_get_time target_user.date_joined as date_joined %}
{% blocktrans %}Date of registration: {{ date_joined }} {% endblocktrans %}
</div>
</div>
<div class="clear"></div>
</div>
<div class="controls">
{% if request.user|pybb_may_manage_moderators %}
<a href="{% url 'pybb:edit_privileges' target_user.get_username %}" class="btn">{% trans 'Moderator' %}</a>
{% endif %}
{% if perms.pybb.block_users %}
{% if target_user.is_active %}
<form action="{% url 'pybb:block_user' target_user.get_username %}" method="post">{% csrf_token %}
<button type="submit">{% trans 'Block' %}</button>
<button type="submit" name="block_and_delete_messages">{% trans 'Block and delete all messages' %}</button>
</form>
{% else %}
<form action="{% url 'pybb:unblock_user' target_user.get_username %}" method="post">{% csrf_token %}
<button type="submit">{% trans 'Unblock' %}</button>
</form>
{% endif %}
{% endif %}
{% if target_user.id == user.id %}
<a href="{% url 'pybb:edit_profile' %}">{% trans 'Edit' %}</a>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% load i18n pybb_tags staticfiles %}
{% pybb_get_profile user=post.user as post_user_profile %}
{% pybb_get_profile user=user as user_profile %}
<a name="post-{{ post.id }}"></a> {# may be remove this string? #}
<table class="table table-bordered post {% if post.on_moderation %}on-moderation{% endif %}" id="post-{{ post.id }}">
<thead class="post-header">
<tr>
<th colspan="2">
<a class="permalink" href="{{ post.get_absolute_url }}">#</a>
<span class="updated">{% pybb_time post.created %}</span>
</th>
</tr>
</thead>
<tbody>
<tr class="post-row">
<td class="post-info">
{% include "pybb/avatar.html" with user=post.user %}
<div class="post-author">
<a href="{{ post_user_profile.get_absolute_url }}">
<span class="post-username">{{ post_user_profile.get_display_name }}</span>
</a>
</div>
{% if post_user_profile.rank %}
<div class="rank">
{% blocktrans with rank=post_user_profile.rank %}Rank: {{ rank }}{% endblocktrans %}
{% if user.is_authenticated and user != post.user %}
<a href="#" class="vote" rel="{{ post_user_profile.get_vote_up_url }}">+</a>
<a href="#" class="vote" rel="{{ post_user_profile.get_vote_down_url }}">-</a>
{% endif %}
</div>
{% endif %}
{% if user.is_superuser %}
<div class="post-extra-info">{{ post.user_ip }}</div>
{% endif %}
<div class="post-controls">
{% if user|pybb_may_edit_post:post %}
<a href="{% url 'pybb:edit_post' pk=post.id %}">{% trans 'Edit' %}</a>
{% endif %}
{% if user|pybb_may_delete_post:post %}
<a onclick="pybb_delete_post('{% url 'pybb:delete_post' post.id %}',
'post-{{ post.id }}', '{% trans 'Delete post?' as txt %}{{ txt|escapejs }}'); return false;"
href="{% url 'pybb:delete_post' post.id %}">{% trans 'Delete' %}</a>
{% endif %}
{% if post.on_moderation and user.is_moderator %}
<a href="{% url 'pybb:moderate_post' pk=post.id %}">{% trans 'Approve post' %}</a>
{% endif %}
{% if user.is_moderator %}
<a href="{% url 'pybb:move_post' pk=post.id %}">{% if post.is_topic_head %}{% trans 'Move' %}{% else %}{% trans "Split" %}{% endif %}</a>
{% endif %}
{% if user|pybb_may_admin_post:post %}
<a href="{% url 'admin:pybb_post_change' post.id %}">{% trans 'Admin' %}</a>
{% endif %}
</div>
</td>
<td class="post-content">
{{ post.body_html|safe }}
{% if not user.is_authenticated or user_profile.show_signatures %}
{% if post_user_profile.signature %}
<div class="post-signature">
{{ post_user_profile.signature_html|safe }}
</div>
{% endif %}
{% endif %}
{% if post.updated %}
<div class="updated-message">{% trans 'Edited' %} {% pybb_time post.updated %}</div>
{% endif %}
{% comment %}
{% if post.attachment_cache %}
{% for attach in post.attachment_cache %}
<br/>
{% trans 'Attachment' %}{% trans ':' %} <a href="{{ attach.get_absolute_url }}">{{ attach.name }}</a> ({{ attach.size_display }})
{% endfor %}
{% endif %}
{% endcomment %}
<div class="post-related">
{% if user|pybb_may_create_post:post.topic %}
<a href="{% url 'pybb:add_post' topic.id %}?quote_id={{ post.id }}" class="quote-link">{% trans 'quote' %}</a>
<div style="color: transparent;" class="quote-selected-link">{% trans 'quote selected' %}</div>
{% endif %}
<div class="attachments">
{% for attachment in post.attachments.all %}
<a href="{{ attachment.file.url }}"><img src="{% static 'pybb/img/attachment.png' %}"> {{ attachment.size_display }}</a>
{% endfor %}
</div>
</div>
</td>
</tr>
</tbody>
</table>
Thanks @rhaskara
I think you copied templates from the master version, not from the 0.18.4 you are using :wink:
pybb_get_time
and pybb_may_admin_post
don't yet exist in 0.18.4.
The master branch of this repo is the future 0.19.0.
To get files from 0.18.4 via github, you can use the dropdown at the top left of code view to select v0.18.4.
Oh alright.. didn't realize that. Thanks.
@DylannCordel I still can't find pybb_may_admin_post
in pybb_tags.
[2017.03.15 14:14] lampslave@vector180 192.168.1.172 172.17.0.1
[~/hovel/pybbm]$ git checkout origin/master
HEAD is now at 3d859ac... Merge pull request #266 from webu/fixes/permissions
[2017.03.15 14:14] lampslave@vector180 192.168.1.172 172.17.0.1
[~/hovel/pybbm]$ grep -r pybb_may_admin_post
pybb/templates/pybb/post_template.html: {% if user|pybb_may_admin_post:post %}
[2017.03.15 14:14] lampslave@vector180 192.168.1.172 172.17.0.1
[~/hovel/pybbm]$
@lampslave yeah it's normal : permissions tags are dynamically created from PermissionHandler:
# pybb/pybb_tags.py
def load_perms_filters():
def partial(func_name, perms_obj):
def newfunc(user, obj_or_qs):
return getattr(perms_obj, func_name)(user, obj_or_qs)
return newfunc
def partial_no_param(func_name, perms_obj):
def newfunc(user):
return getattr(perms_obj, func_name)(user)
return newfunc
for method_name, method in inspect.getmembers(perms):
if not inspect.ismethod(method):
continue # pragma: no cover - only methods are used to dynamically build templatetags
if not method_name.startswith('may') and not method_name.startswith('filter'):
continue # pragma: no cover - only (may|filter)* methods are used to dynamically build templatetags
method_args = inspect.getargspec(method).args
args_count = len(method_args)
if args_count not in (2, 3):
continue # pragma: no cover - only methods with 2 or 3 params
if method_args[0] != 'self' or method_args[1] != 'user':
continue # pragma: no cover - only methods with self and user as first args
if len(inspect.getargspec(method).args) == 3:
register.filter('%s%s' % ('pybb_', method_name), partial(method_name, perms))
elif len(inspect.getargspec(method).args) == 2:
register.filter('%s%s' % ('pybb_', method_name), partial_no_param(method_name, perms))
load_perms_filters()
Oh, ok then, thanks for explanation.
Been getting this message when trying to open a post.
and also this when trying to open pybbm user's profile.
Both error happened while I'm trying to override the default template. Forum runs fine when both blocks removed from their respective html files.