Skip to content

Commit

Permalink
Merge pull request #693 from Natay/master
Browse files Browse the repository at this point in the history
page speed increased
  • Loading branch information
ialbert authored Jan 25, 2021
2 parents c8f860e + 1ff91d7 commit 7344d14
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 123 deletions.
5 changes: 3 additions & 2 deletions biostar/forum/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def tags_list(request):

# How many months prior to look back
months = request.POST.get('months', '6')

try:
months = int(months) if months.isalmun() else float(months)
except Exception as exc:
Expand All @@ -319,8 +320,8 @@ def tags_list(request):
continue

posts = query.filter(tags__name=tag)
answer_count = posts.filter(type=Post.ANSWER).count()
comment_count = posts.filter(type=Post.COMMENT).count()
answer_count = Post.objects.filter(root__in=posts, type=Post.ANSWER).count()
comment_count = Post.objects.filter(root__in=posts, type=Post.COMMENT).count()
total = posts.count()

val = dict(total=total, answer_count=answer_count, comment_count=comment_count)
Expand Down
64 changes: 0 additions & 64 deletions biostar/forum/static/forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,58 +105,6 @@ function highlight(text) {
}


function mark_spam(post) {
var uid = post.data("value");
$.ajax('/ajax/report/spam/' + uid + "/",
{
type: 'GET',
dataType: 'json',
ContentType: 'application/json',
data: {},
success: function (data) {

if (data.status === 'error') {
popup_message(post, data.msg, data.status);

} else {
popup_message(post, data.msg, data.status);
post.removeClass('open').removeClass('quarantine').addClass('spam');
}

},
error: function (xhr, status, text) {
error_message(post, xhr, status, text)
}
});
}


function release_suspect(post) {

var uid = post.data("value");
$.ajax('/release/' + uid + "/",
{
type: 'GET',
dataType: 'json',
ContentType: 'application/json',
data: {},
success: function (data) {

if (data.status === 'error') {
popup_message(post, data.msg, data.status);
} else {
popup_message(post, data.msg, data.status);
post.removeClass('quarantine').addClass('open');
}

},
error: function (xhr, status, text) {
error_message(post, xhr, status, text)
}
});
}


function moderate(uid, container, url) {

//event.preventDefault();
Expand Down Expand Up @@ -307,18 +255,6 @@ function highligh_preview(form, text) {

$(document).ready(function () {

$('.spam').dropdown({on: 'hover'});
$('.spam .mark.item').click(function (event) {
var post = $(this).closest('.post');
mark_spam(post);
});

$('.spam .release.item').click(function (event) {
var post = $(this).closest('.post');
release_suspect(post);

});

$('#similar-feed').each(function () {
var elem = $(this);
similar_posts(elem);
Expand Down
18 changes: 18 additions & 0 deletions biostar/forum/templates/accounts/user_profile.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{% extends "forum_base.html" %}
{% load static %}
{% load accounts_tags %}
{% load forum_tags %}
{% block headtitle %}{{ target.profile.name }}{% 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 stackable three column grid profile" data-value="{{ target.profile.id }}">
Expand Down
11 changes: 11 additions & 0 deletions biostar/forum/templates/base_view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'forum_list.html' %}
{% load static %}
{% load forum_tags %}

{% 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 %}
41 changes: 9 additions & 32 deletions biostar/forum/templates/forum_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
{% block favicon %}
<link rel="icon" href="{% static 'forum_favicon.ico' %}" type="image/x-icon"/>
{% endblock %}
{# Load JQuery. #}

<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script defer 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 defer src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
{# Optional block header content. #}
{% block head %}
{% endblock %}

{# Google tracker injected if it exists in the context. Set in the django settings. #}
{% if google_tracker %}
Expand All @@ -43,6 +39,7 @@
</script>

{% endif %}
{# <script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script"></script>#}

<script>
MathJax = {
Expand All @@ -54,50 +51,30 @@
}
};
</script>
{% comment %}
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script"></script>
{% endcomment %}

{# Load recaptcha #}
{% recaptcha_init %}
{#% recaptcha_init %#}

{# CSS compression. #}
{% compress css %}
{% compress css inline %}
<link href="{% static 'semantic.min.css' %}" rel="stylesheet">
{# Preload key requests #}
<link rel="preload" as="font" type="font/woff" href="{% static 'themes/default/assets/fonts/icons.woff' %}"
crossorigin="anonymous">
<link rel="preload" as="font" type="font/woff" href="{% static 'themes/default/assets/fonts/icons.woff2' %}"
crossorigin="anonymous">
<link rel="preload" as="font" type="font/woff"
href="{% static 'themes/default/assets/fonts/outline-icons.woff2' %}"
crossorigin="anonymous">
<link rel="preload" as="font" type="font/woff"
href="{% static 'themes/default/assets/fonts/outline-icons.woff' %}"
crossorigin="anonymous">

<link href="{% static 'prism.css' %}" rel="stylesheet" media="print">
<link href="{% static 'prism.css' %}" rel="stylesheet">
<link href="{% static 'forum.css' %}{% randparam %}" rel="stylesheet">
{% block cssfile %}
{% endblock %}

{% endcompress %}

{# Javascript compression. #}
{% compress js %}
<script src="{% static 'semantic.min.js' %}"></script>
<script defer src="{% static 'prism.js' %}"></script>
<script src="{% static 'forum.js' %}{% randparam %}"></script>
<script src="{% static 'setup.js' %}{% randparam %}"></script>
{% compress js inline %}

{% block jsfile %}
{% endblock %}

{% endcompress %}

{# Optional block header content. #}
{% block head %}

{% endblock %}

{# Optional css header content. #}
{% block css %}
Expand Down
10 changes: 8 additions & 2 deletions biostar/forum/templates/new_post.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "forum_base.html" %}
{% extends "base_view.html" %}
{% load forum_tags %}
{% load static %}

Expand All @@ -7,9 +7,10 @@
{% endblock %}

<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 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 %}
Expand All @@ -23,6 +24,11 @@
<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>
Expand Down
5 changes: 4 additions & 1 deletion biostar/forum/templates/post_view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "forum_list.html" %}
{% extends "base_view.html" %}
{% load forum_tags %}
{% load static %}

Expand Down Expand Up @@ -27,6 +27,9 @@
<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>
Expand Down
4 changes: 2 additions & 2 deletions biostar/forum/templates/widgets/post_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<div class="ui simple dropdown spam">
<i class="bug orange icon"></i>
<div class="menu">
<div class="mark item">Mark as Spam</div>
<a href="{% url 'mark_spam' post.uid %}" class="mark item">Mark as Spam</a>

{% if post.suspect_spam %}
<div class="release item">Release</div>
<a href="{% url 'release_quar' post.uid %}" class="release item">Release</a>
{% endif %}

</div>
Expand Down
3 changes: 3 additions & 0 deletions biostar/forum/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@

path('moderate/<str:uid>/', views.post_moderate, name="post_moderate"),

path(r'mark/spam/<str:uid>/', views.mark_spam, name='mark_spam'),
path(r'mark/spam/<str:uid>/', views.release_quar, name='release_quar'),

# Community urls
path('community/', views.community_list, name='community_list'),
path('ajax/handle/search/', ajax.handle_search, name='handle_search'),
Expand Down
37 changes: 36 additions & 1 deletion biostar/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from biostar.forum import forms, auth, tasks, util, search
from biostar.forum.const import *
from biostar.forum.models import Post, Vote, Badge, Subscription

from biostar.utils.decorators import is_moderator

User = get_user_model()

Expand Down Expand Up @@ -194,6 +194,41 @@ def pages(request, fname):
return render(request, 'pages.html', context=context)


@is_moderator
def mark_spam(request, uid):
"""
Mark post as a
"""
post = Post.objects.filter(uid=uid).first()
if not post:
messages.error(request, "Post does noe exist.")
return redirect('/')

auth.Moderate(post=post, action=REPORT_SPAM, user=request.user)

return redirect('/')


@is_moderator
def release_quar(request, uid):
"""
Release quarantined post to the public.
"""
post = Post.objects.filter(uid=uid).first()
if not post:
messages.error(request, "Post does noe exist.")
return redirect('/')

# Bump the score by one is the user does not get quarantined again.
# Tells the system user has gained antibodies!
if post.author.profile.low_rep:
post.author.profile.bump_over_threshold()

Post.objects.filter(uid=uid).update(spam=Post.NOT_SPAM)

return redirect('/')


@ensure_csrf_cookie
def post_list(request, topic=None, cache_key='', extra_context=dict()):
"""
Expand Down
7 changes: 5 additions & 2 deletions biostar/recipes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def encode_recipe(recipe, show_image=False, user=None):

if user and user.is_admin:
store['owner_email'] = recipe.owner.email
store['owner_first_name'] = project.owner.first_name
store['owner_text'] = project.owner.profile.text

return store

Expand All @@ -134,11 +136,12 @@ def json_list(qs=None, show_image=False, user=None):
def api_list(request):
# Get the token and user
token = auth.get_token(request=request)
show_all = bool(request.GET.get('show', 0))

user = User.objects.filter(profile__token=token).first()

# Admins get all projects
if user.is_admin:
# Admins can get all projects
if user.is_admin and show_all:
projects = Project.objects.filter(deleted=False).all()
else:
# Get the project list corresponding to this user returns public projects if user is None.
Expand Down
3 changes: 0 additions & 3 deletions biostar/recipes/templates/base_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<div id="clipboard">{% clipboard project.uid %}</div>
<div class="ui large secondary pointing menu">


<a class="{% activate 'info' active %} item" href="{% url 'project_view' project.uid %}">
<i class="info circle icon"></i><span class="phone">Project</span>
</a>
Expand All @@ -37,8 +36,6 @@
</div>
{% endif %}



</div>

{% csrf_token %}
Expand Down
Loading

0 comments on commit 7344d14

Please sign in to comment.