Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Natay committed May 2, 2021
1 parent 3466cef commit a3e5083
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 49 deletions.
8 changes: 6 additions & 2 deletions biostar/forum/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,16 @@ def herald_update(request, pk):
if status is None:
return ajax_error(msg="Invalid status.")

# If herald is already published, do not accept again.
if herald.published:
return ajax_error(msg=f"submission is already published.")

herald.status = status
Herald.objects.filter(pk=herald.pk).update(status=herald.status)
logmsg = f"{herald.get_status_display().lower()} herald_list {herald.url}"
logmsg = f"{herald.get_status_display().lower()} herald story {herald.url}"
auth.db_logger(user=request.user, target=herald.user, text=logmsg)

return ajax_success(msg="Changed herald_list state")
return ajax_success(msg="changed herald state")


@ajax_limited(key=RATELIMIT_KEY, rate=EDIT_RATE)
Expand Down
31 changes: 18 additions & 13 deletions biostar/forum/management/commands/herald.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
from biostar.accounts.models import User
from biostar.planet.models import BlogPost, Blog
from biostar.forum import auth
from mistune import Markdown
from django.shortcuts import reverse
from django.conf import settings

logger = logging.getLogger('engine')


def create_blogs(heralds):
def create_blog(heralds):
"""
Link a group of herald publications to a blog post.
"""
date = now()
# Create the Blog post title and content first displayed.
title = f"Biostar Herard: {date.date()} issue."
template = "herald/publication.md"
tmpl = loader.get_template(template_name=template)
context = dict(title=title, heralds=heralds)
context = dict(heralds=heralds)
content = tmpl.render(context)

# Get the Herald blog where all publications belong to.
Expand All @@ -32,40 +32,45 @@ def create_blogs(heralds):
logger.warning(f"Herald blog does not exist.")
return

# Convert template to html
html = Markdown()(text=content)

# Create a blog post
blgpost = BlogPost.objects.create(title=title, blog=hblog, content=content, insert_date=date, creation_date=date)
title = f"Biostar Herald: {date.date()} issue."
blgpost = BlogPost.objects.create(title=title, blog=hblog, content=content, insert_date=date, html=html,
creation_date=date)
# Update this blog post link to be the herald issue page.
blgpost.link = reverse('herald_issue', kwargs=dict(blog_pk=blgpost.pk))
blgpost.save()

# Link the publications to this blog post.
# Link the herald publications to this blog post.
heralds.update(blog_post=blgpost)
user = User.objects.filter(is_superuser=True).first()
auth.db_logger(user=user, text=f"created heard:{title}")
auth.db_logger(user=user, text=f"published {heralds.count()} submissions in {title}")

return


def publish(limit=20):
def herald_editor(limit=20):
"""
Publish most recently accepted herald_list submissions.
"""

# Get most recent heralds
heralds = Herald.objects.filter(status=Herald.ACCEPTED)

create_blog(heralds)

# Update the heralds
heralds.update(status=Herald.PUBLISHED)

create_blogs(heralds)
return


class Command(BaseCommand):
help = 'Create search index for the forum app.'

def add_arguments(self, parser):
parser.add_argument('--issue', action='store_true', default=False,
parser.add_argument('--publish', action='store_true', default=False,
help="Create a publication out of the most recently accepted herald_list submissions")
parser.add_argument('--limit', type=int,
help="How many submission to collate in a publication")
Expand All @@ -74,8 +79,8 @@ def handle(self, *args, **options):
# Index all un-indexed posts that have a root.
logger.debug(f"Database: {settings.DATABASE_NAME}")

issue = options['issue']
publish = options['publish']

if issue:
publish()
if publish:
herald_editor()
return
30 changes: 30 additions & 0 deletions biostar/forum/migrations/0018_herald.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2 on 2021-04-30 01:22

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('planet', '0003_blogpost_rank'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('forum', '0017_expanded_log'),
]

operations = [
migrations.CreateModel(
name='Herald',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField(max_length=10000)),
('text', models.TextField(max_length=10000)),
('html', models.TextField(max_length=10000)),
('date', models.DateTimeField()),
('status', models.IntegerField(choices=[(0, 'Submitted'), (1, 'Declined'), (3, 'Published'), (2, 'Accepted')], db_index=True, default=0)),
('blog_post', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='planet.blogpost')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
2 changes: 1 addition & 1 deletion biostar/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class Herald(models.Model):
# Gains a blog post once published, assumed none until then.
blog_post = models.ForeignKey(BlogPost, on_delete=models.SET_NULL, null=True)

#blog_post = models.ForeignKey(Post, on_delete=models.SET_NULL, null=True)
#post = models.ForeignKey(Post, on_delete=models.SET_NULL, null=True)

SUBMITTED, DECLINED, ACCEPTED, PUBLISHED = range(4)
CHOICES = [(SUBMITTED, 'Submitted'), (DECLINED, 'Declined'), (PUBLISHED, 'Published'), (ACCEPTED, 'Accepted')]
Expand Down
2 changes: 1 addition & 1 deletion biostar/forum/static/forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function herald_update(hpk, status, elem) {
data: {'status': status},
success: function (data) {
if (data.status === 'error') {
popup_message(elem, data.msg, data.status);
popup_message(elem, data.msg, data.status, 1000);
} else {
// Replace current item with the select one.
// active.text($item.text());
Expand Down
48 changes: 48 additions & 0 deletions biostar/forum/templates/herald/herald_issue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends "forum_list.html" %}
{% load forum_tags %}
{% load static %}
{% load humanize %}
{% load cache %}

{% block title %}
Biostar Herald
{% endblock %}

{% block headtitle %}
Biostar Herald
{% endblock %}

{% block body %}

<div class="ui vertical segment">
<h2 class="ui header">
<img src="{% static 'images/news-herald.png' %}">
<div class="content">
{{ blogpost.title }}
<div class="sub header">Share bioinformatics resources from across the web.</div>
</div>
</h2>
</div>

{% block inner %}
<div class="ui vertical segment">
<div class="ui relaxed divided list">

{% for herald in heralds %}

<div class="item">{{ herald.html|safe }}</div>
{% empty %}
<div class="ui blue message">No results found.</div>
{% endfor %}

</div>

</div>
{% endblock %}

{% endblock %}

{% block sidebar %}


{% endblock %}
15 changes: 6 additions & 9 deletions biostar/forum/templates/herald/herald_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
{% load cache %}

{% block title %}
Bioinformatics Answers
Biostar Herald
{% endblock %}

{% block headtitle %}
Bioinformatics Answers
Biostar Herald
{% endblock %}

{% block body %}
Expand All @@ -27,12 +27,8 @@ <h2 class="ui header">
</h2>

</div>

{% block newsubmission %}

{% endblock %}
{% block listing %}
<div class="ui vertical segment">
{% block inner %}
<div class="ui vertical segment">
<h4 class="ui header">Latest News </h4>

<div class="ui relaxed divided list">
Expand Down Expand Up @@ -80,7 +76,8 @@ <h4 class="ui header">Latest News </h4>

</div>
</div>
{% endblock %}
{% endblock %}


{% endblock %}

Expand Down
4 changes: 1 addition & 3 deletions biostar/forum/templates/herald/herald_submit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'herald/herald_list.html' %}
{% load forum_tags %}

{% block newsubmission %}
{% block inner %}

<div class="ui segment form-wrap" style="width: 61%;margin:auto;margin-top:30px;">

Expand Down Expand Up @@ -34,8 +34,6 @@
</div>


{% endblock %}
{% block listing %}
{% endblock %}

{% block sidebar %}
Expand Down
5 changes: 3 additions & 2 deletions biostar/forum/templates/herald/publication.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Here are the latest things shared amongst our user base.

{% for herald in heralds %}
- {{herald.user.profile.name}} suggest {{herald.url}}

- {{herald.user.profile.name}} shared {{herald.url}}

{% endfor %}
14 changes: 1 addition & 13 deletions biostar/forum/templates/planet/blog_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@


{% block body %}
<div class="ui vertical segment">

<h2 class="ui header">
<img src="{% static 'images/news-herald.png' %}">
<a class="content" href="{% url 'herald_list' %}">
Biostar Herald
<div class="sub header">Share bioinformatics resources from across the web</div>
</a>

</h2>

</div>

<div class="ui page-bar segment">
{% pages objs=blogposts %}
Expand All @@ -64,7 +52,7 @@ <h2 class="ui header">
{% endif %}
</div>

{{ post.content|truncatewords:200 }} <a href="{{ post.link }}">go to blog</a>
{{ post.html|safe|truncatewords_html:180 }} <a href="{{ post.link }}">go to blog</a>

<div class="content">
{% if user.profile.is_moderator %}
Expand Down
13 changes: 9 additions & 4 deletions biostar/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,20 @@ def herald_list(request):


@authenticated
def herald_issue(request, pk):
def herald_issue(request, blog_pk):
"""
Return a list publications given a
"""
links = Herald.objects.order_by('-date')

context = dict(links=links, tab='herald_list')
# Get a blog post.
blogpost = BlogPost.objects.filter(pk=blog_pk).first()

return render(request, 'herald/herald_list.html', context)
# Get herald posts belonging to this blog post issue.
heralds = blogpost.herald_set.all()

context = dict(heralds=heralds, tab='planet', blogpost=blogpost)

return render(request, 'herald/herald_issue.html', context)


@authenticated
Expand Down
4 changes: 3 additions & 1 deletion biostar/planet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class BlogPost(models.Model):

# Posts should be ranked by this.
rank = models.DateTimeField(db_index=True, null=True)

@property
def get_title(self):
return f"BLOG: {self.title}"
Expand All @@ -112,7 +113,8 @@ def save(self, *args, **kwargs):
# Set the rank
self.rank = self.rank or self.insert_date
#self.html = self.hmtl or

# SET THE HTML
#self.html = ''
self.uid = self.uid or get_uuid(10)

super(BlogPost, self).save(*args, **kwargs)
Expand Down

0 comments on commit a3e5083

Please sign in to comment.