Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ indent_size = 4

[*.js]
indent_style = space
indent_size = 2
indent_size = 4

[*.css]
indent_style = space
Expand Down
2 changes: 2 additions & 0 deletions django_messages_wl/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponse
from mainpage.wl_utils import is_ajax
import json


@login_required
def get_usernames(request):
"""AJAX Callback for JS autocomplete.

Expand Down
31 changes: 19 additions & 12 deletions mainpage/templatetags/wl_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ def _make_smileys(text):

new_soup = BeautifulSoup()
words = text.split()
preceding_space = text.startswith(" ")
smileys = settings.SMILEYS

for i, word in enumerate(words):
smiley = ""
for sc, img in settings.SMILEYS:
if word == sc:
smiley = img
if smiley:
for count, word in enumerate(words):
found_smiley = False

for i, smiley in enumerate(smileys):
if word == smileys[i][0]:
found_smiley = smileys[i]

if found_smiley:
img_tag = new_soup.new_tag("img")
img_tag["src"] = "{}{}".format(settings.SMILEY_DIR, smiley)
img_tag["alt"] = smiley
img_tag["src"] = f"{settings.SMILEY_DIR}{found_smiley[1]}"
img_tag["alt"] = found_smiley[0]
new_soup.append(img_tag)
# apply a space after the smiley
new_soup.append(NavigableString(" "))
else:
if i < (len(words) - 1):
if preceding_space:
word = " " + word

if count < (len(words) - 1):
# Apply a space after each word, except the last word
word = word + " "
new_soup.append(NavigableString(word))
Expand Down Expand Up @@ -184,12 +191,11 @@ def find_smiley_strings(bs4_string):
Attention: This returns also True for ':/' in 'http://'. This get
fixed in _insert_smileys().
"""

if bs4_string.parent.name.lower() == "code":
return False

for sc in settings.SMILEYS:
if sc[0] in bs4_string:
for sc, name in settings.SMILEYS:
if sc in bs4_string:
return True
return False

Expand Down Expand Up @@ -224,6 +230,7 @@ def do_wl_markdown(value, *args, **keyw):
if len(soup.contents) == 0:
# well, empty soup. Return it
return str(soup)

if beautify:
# Insert smileys
smiley_text = soup.find_all(string=find_smiley_strings)
Expand Down
12 changes: 11 additions & 1 deletion notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Meta:


def get_notification_setting(user, notice_type, medium):
"""Return NotceSetting for a specific user. If a NoticeSetting of
"""Return NoticeSetting for a specific user. If a NoticeSetting of
given NoticeType didn't exist for given user, a NoticeSetting is created.

If a new NoticeSetting is created, the field 'default' of a NoticeType
Expand Down Expand Up @@ -233,6 +233,7 @@ def send_now(users, label, extra_context=None, on_site=True):
formats = (
"short.txt", # used for subject
"full.txt", # used for email body
"full_html.txt",
) # TODO make formats configurable

for user in users:
Expand Down Expand Up @@ -280,6 +281,14 @@ def send_now(users, label, extra_context=None, on_site=True):
},
).lstrip()

html_message = render_to_string(
"notification/email_body_html.txt",
{
"message": messages["full_html.txt"],
"notices_url": notices_url,
},
)

if should_send(user, notice_type, "1") and user.email: # Email
recipients.append(user.email)

Expand All @@ -289,6 +298,7 @@ def send_now(users, label, extra_context=None, on_site=True):
settings.DEFAULT_FROM_EMAIL,
recipients,
fail_silently=True,
html_message=html_message,
)

# reset environment to original language
Expand Down
5 changes: 5 additions & 0 deletions notification/templates/notification/email_body_html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}{% blocktrans %}
{{ message }}

<p>To change how you receive notifications, please go to <a href="{{ notices_url }}">notification settings</a>.</p>
{% endblocktrans %}
11 changes: 11 additions & 0 deletions notification/templates/notification/forum_mention/full.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% autoescape off %}
{% load i18n %}Your name was mentioned in a forum post by "{{ user }}" on topic "{{ topic }}"":

"{{ user }}" wrote:

{{ post.body }}
{% blocktrans with post.get_absolute_url as post_url and topic.get_absolute_url as topic_url %}
-------------------------
Link to post: https://{{ current_site }}{{ post_url }}
Link to topic: https://{{ current_site }}{{ topic_url }}
{% endblocktrans %}{% endautoescape %}
12 changes: 12 additions & 0 deletions notification/templates/notification/forum_mention/full_html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% autoescape off %}
{% load i18n %}
<p>Your name was mentioned in a forum post on topic <strong>{{ topic }}</strong></p>
<hr>
<p><a href="https://{{ current_site }}/profile/{{ user }}">{{ user }}</a> wrote:</p>

{{ post.body_html }}
{% blocktrans with post.get_absolute_url as post_url and topic.get_absolute_url as topic_url %}
<hr>
<p><a href="https://{{ current_site }}{{ post_url }}">Link to post</a></p>
<p><a href="https://{{ current_site }}{{ topic_url }}">Link to topic {{ topic }}</a></p>
{% endblocktrans %}{% endautoescape %}
12 changes: 12 additions & 0 deletions notification/templates/notification/forum_new_post/full_html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% autoescape off %}
{% load i18n %}
<p>A new forum post was added to the topic <strong>{{ topic }}</strong></p>
<hr>
<p><a href="https://{{ current_site }}/profile/{{ user }}">{{ user }}</a> wrote:</p>

{{ post.body_html }}
{% blocktrans with post.get_absolute_url as post_url and topic.get_absolute_url as topic_url %}
<hr>
<p><a href="https://{{ current_site }}{{ post_url }}">Link to post</a></p>
<p><a href="https://{{ current_site }}{{ topic_url }}">Link to topic {{ topic }}</a></p>
{% endblocktrans %}{% endautoescape %}
12 changes: 12 additions & 0 deletions notification/templates/notification/forum_new_topic/full_html.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% autoescape off %}
{% load i18n %}
<p>The Forum topic <strong>{{ topic }}</strong> has been created by {{ user }}</p>
<hr>
<p><a href="https://{{ current_site }}/profile/{{ user }}">{{ user }}</a> wrote:</p>

{{ post.body_html }}
{% blocktrans with post.get_absolute_url as post_url and topic.get_absolute_url as topic_url %}
<hr>
<p><a href="https://{{ current_site }}{{ post_url }}">Link to post</a></p>
<p><a href="https://{{ current_site }}{{ topic_url }}">Link to topic {{ topic }}</a></p>
{% endblocktrans %}{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% autoescape off %}
{% load i18n %}<p>A new map has been uploaded to the Website by {{ user }}:</p>
{% blocktrans %}
<p>Mapname: {{ mapname }}</p>
<p>Description: {{ uploader_comment }}</p>

<hr>
<p><a href="https://{{ current_site }}{{ url }}>Link to map {{ mapname }}</a></p>
{% endblocktrans %}{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% autoescape off %}
{% load i18n %}{% url 'wiki_changeset' article rev as diff_url %}{% url 'wiki_article' article as article_url %}{% blocktrans %}
<p>The article "{{ article }}" that you observe has been edited by {{ editor }}.</p>
<p>Comment for this revision: "{{ rev_comment }}"</p>

<hr>
<p>A diff is available <a href="https://{{ current_site }}{{ diff_url }}>here</a></p>
<p><a href="https://{{ current_site }}{{ article_url }}">Link to article</a></p>
{% endblocktrans %}{% endautoescape %}
4 changes: 3 additions & 1 deletion pybb/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class AddPostForm(forms.ModelForm):
],
)
body = forms.CharField(
widget=forms.Textarea(attrs={"cols": 80, "rows": 15}),
widget=forms.Textarea(
attrs={"cols": 80, "rows": 15, "oninput": "autoResizeTextarea()"}
),
validators=[
check_utf8mb3,
],
Expand Down
6 changes: 6 additions & 0 deletions pybb/management/pybb_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def create_notice_types(sender, **kwargs):
),
default=0,
)
notification.create_notice_type(
"forum_mention",
_("Your name was mentioned"),
_("someone has mentioned your name with '@name' in a post"),
default=2,
)

except ImportError:
print("Skipping creation of NoticeTypes as notification app not found")
119 changes: 119 additions & 0 deletions pybb/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import re

from django.contrib.auth.models import User
from django.db.models import Q

from notification import models as notification
from pybb import settings as pybb_settings

MENTION_RE = re.compile(r"@([\w.@+\-]+)")


def notify(request, topic, post):
"""Send mails for mentions, topic subscribers and users who are auto subscribers.

- topic subscribers are all users who clicked 'subscribe' to a topic and the topic author
himself
- auto subscribers are all who enabled 'auto subscriptions' and wrote a post in a topic
- mentioned are all whose name is mentioned like @username in a post
mentioning takes precedence over all. That is if a user is mentioned he will get only one
email for mentioning and no email for new topic or new post.
"""

def _get_mentions():
"""Return usernames which are mentioned in a post like @username."""

mentioned_names = []
for line in post.body.splitlines():
# Didn't found a way to exclude quoted lines with the regex :(
if not line.startswith(">"):
mentioned = MENTION_RE.findall(line)
mentioned_names.extend(mentioned)

mentioned_users = []
for username in mentioned_names:
# Make sure this is an existing user
try:
user_obj = User.objects.get(username=username)

notice_type = notification.NoticeType.objects.get(label="forum_mention")

if notification.get_notification_setting(
user_obj, notice_type, "1"
).send:
mentioned_users.append(user_obj)

except User.DoesNotExist:
pass

return mentioned_users

def _inform_mentioned(mentioned):
notification.send(
mentioned,
"forum_mention",
{"post": post, "topic": post.topic, "user": post.user},
)

if not topic:
# Inform subscribers of a new topic
if post.topic.forum.category.internal:
# Inform only users which have the permission to enter the
# internal forum and superusers. Those users have to:
# - enable 'forum_new_topic' in the notification settings, or
# - subscribed to an existing topic
subscribers = User.objects.filter(
Q(groups__permissions__codename=pybb_settings.INTERNAL_PERM)
| Q(user_permissions__codename=pybb_settings.INTERNAL_PERM)
).exclude(username=request.user.username)
superusers = User.objects.filter(is_superuser=True).exclude(
username=request.user.username
)
# Combine the query sets, excluding double entries.
subscribers = subscribers.union(superusers)
else:
# Normal users
subscribers = notification.get_observers_for(
"forum_new_topic", excl_user=request.user
)

mentions = _get_mentions()

# Remove mentioned users from subscribers
new_subscribers = set(subscribers) - set(mentions)

# Send the mails
_inform_mentioned(mentions)
notification.send(
new_subscribers,
"forum_new_topic",
{"topic": post.topic, "post": post, "user": post.topic.user},
)

# Topics author is subscriber for all new posts in his topic
post.topic.subscribers.add(request.user)

else:
# Inform users who auto subscribed to topics
notice_type = notification.NoticeType.objects.get(label="forum_auto_subscribe")
notice_setting = notification.get_notification_setting(
post.user, notice_type, "1"
)
if notice_setting.send:
post.topic.subscribers.add(request.user)

mentions = _get_mentions()

# Remove mentioned users from topic subscribers
topic_subscribers = set(
post.topic.subscribers.exclude(username=post.user)
) - set(mentions)

# Finally send the mails
_inform_mentioned(mentions)
# Send mails about a new post to topic subscribers
notification.send(
topic_subscribers,
"forum_new_post",
{"post": post, "topic": topic, "user": post.user},
)
3 changes: 3 additions & 0 deletions pybb/static/css/forum.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ div.blogEntry .post p {

.post-form #id_body {
width: 100%;
height: auto; /* Höhe automatisch anpassen */
resize: none; /* Größenänderung durch den Benutzer verhindern */
overflow: hidden; /* Scrollbalken ausblenden */
}

@media screen and (min-width: 65em) {
Expand Down
46 changes: 46 additions & 0 deletions pybb/static/css/tribute.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* See pybb/static/js/tribute/ directory for license */

.tribute-container {
position: absolute;
top: 0;
left: 0;
height: auto;
overflow: auto;
display: block;
z-index: 999999;
border: 1px solid black;
border-radius: 3px;
box-shadow: 4px 4px 4px 0px rgba(0, 0, 0, 0.7);
}

.tribute-container ul {
margin: 0;
margin-top: 2px;
padding: 0;
list-style: none;
/*background: #efefef;*/
background-image: url("../img/wood.png");
}

.tribute-container li {
padding: 5px 5px;
cursor: pointer;
border-bottom: 1px solid black;
}

.tribute-container li.highlight {
/*background: #ddd;*/
background-image: url("../img/black50.png");
}

.tribute-container li span {
font-weight: bold;
}

.tribute-container li.no-match {
cursor: default;
}

.tribute-container .menu-highlighted {
font-weight: bold;
}
Loading