Skip to content

Commit

Permalink
Merge pull request #694 from Natay/master
Browse files Browse the repository at this point in the history
updates in forum and recipes
  • Loading branch information
ialbert authored Feb 1, 2021
2 parents 7344d14 + c1a3fb9 commit d057830
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 131 deletions.
2 changes: 1 addition & 1 deletion biostar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
__all__ = ['celery_app']


VERSION = '2.3.3'
VERSION = '2.3.4'
4 changes: 3 additions & 1 deletion biostar/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

RATELIMIT_KEY = settings.RATELIMIT_KEY


def edit_profile(request):
if request.user.is_anonymous:
messages.error(request, "Must be logged in to edit profile")
Expand All @@ -57,7 +58,6 @@ def edit_profile(request):
username = form.cleaned_data["username"]
email = form.cleaned_data['email']
User.objects.filter(pk=user.pk).update(username=username, email=email)
# Update user information in Profile object.
Profile.objects.filter(user=user).update(name=form.cleaned_data['name'],
watched_tags=form.cleaned_data['watched_tags'],
location=form.cleaned_data['location'],
Expand All @@ -69,6 +69,8 @@ def edit_profile(request):
message_prefs=form.cleaned_data["message_prefs"],
html=markdown(form.cleaned_data["text"]),
digest_prefs=form.cleaned_data['digest_prefs'])
# Recompute watched tags
Profile.objects.filter(user=user).first().add_watched()

return redirect(reverse("user_profile", kwargs=dict(uid=user.profile.uid)))

Expand Down
11 changes: 11 additions & 0 deletions biostar/forum/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ def traffic(request):
return data


@json_response
def api_tag(request, tag):
"""
Return list of post uids that have a tag.
"""
posts = Post.objects.filter(tags__name=tag.lower()).values_list('uid', flat=True)
posts = list(posts)

return posts


@json_response
def user_email(request, email):
user = User.objects.filter(email__iexact=email.lower())
Expand Down
3 changes: 2 additions & 1 deletion biostar/forum/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ def post_tree(user, root):

# Get all posts that belong to post root.
query = Post.objects.valid_posts(u=user, root=root).exclude(pk=root.id)

# Filter quarantined and deleted comments or answers.
if user.is_anonymous or not user.profile.is_moderator:
query = query.exclude(Q(spam=Post.SUSPECT) | Q(status=Post.DELETED))
query = query.exclude(Q(spam=Post.SUSPECT) | Q(status=Post.DELETED) | Q(spam=Post.SPAM))

query = query.select_related("lastedit_user__profile", "author__profile", "root__author__profile")

Expand Down
3 changes: 3 additions & 0 deletions biostar/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def valid_posts(self, u=None, **kwargs):
if u and u.is_authenticated and u.profile.is_moderator:
return query

# Users get to see their own quarantined posts.

# Filter for open posts that are not spam.
query = query.filter(status=Post.OPEN, root__status=Post.OPEN)

query = query.filter(models.Q(spam=Post.NOT_SPAM) | models.Q(spam=Post.DEFAULT) |
models.Q(root__spam=Post.NOT_SPAM) | models.Q(root__spam=Post.DEFAULT))

Expand Down
6 changes: 4 additions & 2 deletions biostar/forum/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from whoosh.searching import Results

import html2markdown
import bleach
from whoosh.qparser import MultifieldParser, OrGroup
from whoosh.analysis import STOP_WORDS
from whoosh.index import create_in, open_dir, exists_in
Expand Down Expand Up @@ -107,8 +108,9 @@ def index_exists(dirname=settings.INDEX_DIR, indexname=settings.INDEX_NAME):


def add_index(post, writer):
# user html2markdown to clean text.
content = html2markdown.convert(post.content)

# Ensure the content is stripped of any html.
content = bleach.clean(post.content, styles=[], attributes={}, tags=[], strip=True)
writer.update_document(title=post.title, url=post.get_absolute_url(),
type_display=post.get_type_display(),
content_length=len(content),
Expand Down
4 changes: 4 additions & 0 deletions biostar/forum/static/forum.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ body > .widen.container {

}

.ui.form .form-wrap .field>.selection.dropdown {
min-width: 0 !important;
}

.voting .ui.button {
background: none;
padding: 5px;
Expand Down
15 changes: 1 addition & 14 deletions biostar/forum/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ def spam_scoring(post):
message(exc)


def tpatt(tag):
"""
Return pattern matching a tag found in comma separated string.
(?i) : case-insensitive flag
^{tag}\\s*, : matches beginning
,\\s*{tag}\\s*, : matches middle
,\\s*{tag}$ : matches end
^{tag}[^\\w+] : matches single entry ( no commas )
"""
patt = fr"(?i)(^{tag}\s*,|,\s*{tag}\s*,|,\s*{tag}$|^{tag}$)"
return patt


@task
def notify_watched_tags(post, extra_context):
"""
Expand All @@ -63,7 +50,7 @@ def notify_watched_tags(post, extra_context):
from biostar.accounts.models import User
from django.conf import settings

users = [User.objects.filter(profile__watched_tags__iregex=tpatt(tag.name)).distinct()
users = [User.objects.filter(profile__watched__name=tag.name).distinct()
for tag in post.root.tags.all()]

# Flatten nested users queryset and get email.
Expand Down
17 changes: 17 additions & 0 deletions biostar/forum/templates/accounts/edit_profile.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
{% extends "forum_base.html" %}
{% load forum_tags %}
{% load accounts_tags %}
{% load static %}

{% block headtitle %}Edit Profile{% endblock %}

{% block head %}
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link disabled rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<script async src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
{% endblock %}

{% block js %}

<script src="{% static 'semantic.min.js' %}"></script>
<script src="{% static 'prism.js' %}"></script>
<script src="{% static 'setup.js' %}{% randparam %}"></script>
<script src="{% static 'forum.js' %}{% randparam %}"></script>
{% endblock %}

{% block content %}

<div class="ui horizontal segments no-shadow">
Expand Down
1 change: 1 addition & 0 deletions biostar/forum/templates/accounts/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<script src="{% static 'forum.js' %}{% randparam %}"></script>
{% endblock %}


{% block content %}

<div class="ui stackable three column grid profile" data-value="{{ target.profile.id }}">
Expand Down
7 changes: 3 additions & 4 deletions biostar/forum/templates/banners/menu-topics.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@

{% if counts.messages.count %}

<div class="ui green large label">
<div class="ui green label">
<i class="envelope icon"></i>Messages ({{ counts.messages.count }})
</div>
{% else %}
<i class="envelope icon"></i> Messages
{% endif %}

</a>
<a class="item {% activate tab "myvotes" %}"
href="{% url 'myvotes' %}">
<a class="item {% activate tab "myvotes" %}" href="{% url 'myvotes' %}">

{% if counts.votes.count %}
<div class="ui pink label"><i class="heart icon"></i> New Votes ({{ counts.votes.count }})</div>
<div class="ui pink label"><i class="heart icon"></i> Votes ({{ counts.votes.count }})</div>
{% else %}
<i class="heart icon"></i> Votes
{% endif %}
Expand Down
29 changes: 29 additions & 0 deletions biostar/forum/templates/base_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,32 @@
<link disabled rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<script async src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
{% endblock %}

{% block css %}
<link rel="stylesheet" href="{% static 'autocomplete/tribute.css' %}" />
<link rel="stylesheet" href="{% static 'autocomplete/at.who.css' %}" />
<link href="{% static 'pagedown.css' %}" type="text/css" media="all" rel="stylesheet">
<link href="{% static 'prism.css' %}" rel="stylesheet">
<link href="{% static 'pagedown/demo/browser/demo.css' %}" type="text/css" media="all" rel="stylesheet">
{% endblock %}


{% block js %}
<script src="{% static 'autocomplete/tribute.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Converter.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/pagedown/Markdown.Converter.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Sanitizer.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Editor.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/Markdown.Extra.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown_init.js' %}{% randparam %}"></script>

<script src="{% static 'semantic.min.js' %}"></script>
<script src="{% static 'prism.js' %}"></script>
<script src="{% static 'setup.js' %}{% randparam %}"></script>

<script src="{% static 'markdown-it.js' %}"></script>
<script src="{% static 'autocomplete/at.who.js' %}"></script>
<script src="{% static 'effects.js' %}{% randparam %}"></script>
<script src="{% static 'inplace.js' %}{% randparam %}"></script>
<script src="{% static 'forum.js' %}{% randparam %}"></script>
{% endblock %}
12 changes: 7 additions & 5 deletions biostar/forum/templates/forum_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,24 @@
{#% recaptcha_init %#}

{# CSS compression. #}
{% compress css inline %}
{% compress css %}

<link href="{% static 'semantic.min.css' %}" rel="stylesheet">
{# Preload key requests #}
<link href="{% static 'prism.css' %}" rel="stylesheet">
<link href="{% static 'forum.css' %}{% randparam %}" rel="stylesheet">
{% block cssfile %}
{% endblock %}

{% endcompress %}

{# Javascript compression. #}
{% compress js inline %}
{% compress js %}

{% block jsfile %}
{% endblock %}

{% endcompress %}



{# Optional css header content. #}
{% block css %}
{% endblock %}
Expand All @@ -86,6 +84,8 @@
{% endblock %}

</head>


<body>

<div class="ui inverted container widen">
Expand Down Expand Up @@ -120,6 +120,8 @@
{% endblock %}
</div>


</body>

</html>

27 changes: 0 additions & 27 deletions biostar/forum/templates/new_post.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>

{% block css %}
<link href="{% static 'autocomplete/at.who.css' %}" rel="stylesheet">
<link rel="stylesheet" href="{% static 'autocomplete/tribute.css' %}"/>
<link href=" {% static 'pagedown.css' %}" type="text/css" media="all" rel="stylesheet">
<link href="{% static 'pagedown/demo/browser/demo.css' %}" type="text/css" media="all" rel="stylesheet">
{% endblock %}

{% block js %}
<script type="text/javascript" src="{% static 'pagedown/Markdown.Converter.js' %}"></script>
<script src="{% static 'autocomplete/tribute.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/pagedown/Markdown.Converter.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Sanitizer.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Editor.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/Markdown.Extra.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown_init.js' %}"></script>

<script src="{% static 'semantic.min.js' %}"></script>
<script src="{% static 'prism.js' %}"></script>
<script src="{% static 'setup.js' %}{% randparam %}"></script>
<script src="{% static 'forum.js' %}{% randparam %}"></script>

<script src="{% static 'markdown-it.js' %}"></script>
<script src="{% static 'autocomplete/at.who.js' %}"></script>
<script src="{% static 'autocomplete/caret.js' %}"></script>
<script src="{% static 'effects.js' %}{% randparam %}"></script>
<script src="{% static 'inplace.js' %}{% randparam %}"></script>
{% endblock %}

{% block container %}
<div class="ui bottom attached create-post segment">
Expand Down
27 changes: 0 additions & 27 deletions biostar/forum/templates/post_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,6 @@
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

{% block css %}
<link rel="stylesheet" href="{% static 'autocomplete/tribute.css' %}" />
<link rel="stylesheet" href="{% static 'autocomplete/at.who.css' %}" />
<link href="{% static 'pagedown.css' %}" type="text/css" media="all" rel="stylesheet">
<link href="{% static 'pagedown/demo/browser/demo.css' %}" type="text/css" media="all" rel="stylesheet">
{% endblock %}


{% block js %}
<script src="{% static 'autocomplete/tribute.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Converter.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/pagedown/Markdown.Converter.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Sanitizer.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown/Markdown.Editor.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown-extra/Markdown.Extra.js' %}"></script>
<script type="text/javascript" src="{% static 'pagedown_init.js' %}{% randparam %}"></script>

<script src="{% static 'semantic.min.js' %}"></script>
<script src="{% static 'prism.js' %}"></script>
<script src="{% static 'setup.js' %}{% randparam %}"></script>

<script src="{% static 'markdown-it.js' %}"></script>
<script src="{% static 'autocomplete/at.who.js' %}"></script>
<script src="{% static 'effects.js' %}{% randparam %}"></script>
<script src="{% static 'inplace.js' %}{% randparam %}"></script>
<script src="{% static 'forum.js' %}{% randparam %}"></script>
{% endblock %}

{% block body %}

Expand Down
1 change: 1 addition & 0 deletions biostar/forum/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
# Api calls
path(r'api/traffic/', api.traffic, name='api_traffic'),
path(r'api/user/<str:uid>/', api.user_details, name='api_user'),
path(r'api/tag/<str:tag>/', api.api_tag, name='api_tag'),
path(r'api/tags/list/', api.tags_list, name='api_tags_list'),
path(r'api/post/<str:uid>/', api.post_details, name='api_post'),
path(r'api/vote/<str:uid>/', api.vote_details, name='api_vote'),
Expand Down
5 changes: 4 additions & 1 deletion biostar/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def get_posts(user, topic="", tag="", order="", limit=None):
elif topic == FOLLOWING and user.is_authenticated:
query = query.filter(subs__user=user).exclude(subs__type=Subscription.NO_MESSAGES)
elif topic == MYPOSTS and user.is_authenticated:
query = query.filter(author=user)
# Show users all of there posts ( deleted, spam, or quarantined )
query = Post.objects.filter(author=user)
#query = query.filter(author=user)

elif topic == MYVOTES and user.is_authenticated:
query = query.filter(votes__post__author=user)
elif topic == MYTAGS and user.is_authenticated:
Expand Down
5 changes: 3 additions & 2 deletions biostar/recipes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ def clean(self):
if not cleaned_data.get("data_name"):
raise forms.ValidationError("Name is required with text inputs.")

total_count = Data.objects.filter(owner=self.user).count()
if total_count >= settings.MAX_DATA:
total_count = Data.objects.filter(owner=self.user, deleted=False).count()

if total_count >= settings.MAX_DATA and not self.user.profile.is_moderator:
raise forms.ValidationError(f"Exceeded maximum amount of data:{settings.MAX_DATA}.")
return cleaned_data

Expand Down
3 changes: 1 addition & 2 deletions biostar/recipes/static/engine.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ body {
}

.ui-droppable-hover {
border: #10ee0a dotted 5px !important;
height: 50% !important;
border-bottom: #10ee0a solid 5px !important;
}

.draggable {
Expand Down
14 changes: 14 additions & 0 deletions conf/scripts/server-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Load the conda commands.
source ~/miniconda3/etc/profile.d/conda.sh

export POSTGRES_HOST=/var/run/postgresql

# Activate the conda environemnt.
conda activate engine

# Set the configuration module.
export DJANGO_SETTINGS_MODULE=conf.run.site_settings

python manage.py cleanup
Loading

0 comments on commit d057830

Please sign in to comment.