From 8d7f5b30e2ac3cd16eb1d02fc33987a8783ca8a1 Mon Sep 17 00:00:00 2001 From: Jakub Kadlčík Date: Nov 28 2017 16:37:22 +0000 Subject: Merge #174 `Show most recent post from our blog` --- diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py b/frontend/coprs_frontend/coprs/logic/builds_logic.py index 6f65de6..3a4430f 100644 --- a/frontend/coprs_frontend/coprs/logic/builds_logic.py +++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py @@ -70,7 +70,7 @@ class BuildsLogic(object): # Workaround - otherwise it could take less records than `limit`even though there are more of them. query = query.limit(limit if limit > 100 else 100) - return list(query.all()[:5]) + return list(query.all()[:4]) @classmethod def get_build_importing_queue(cls): diff --git a/frontend/coprs_frontend/coprs/static/js/blog.js b/frontend/coprs_frontend/coprs/static/js/blog.js new file mode 100644 index 0000000..5113c64 --- /dev/null +++ b/frontend/coprs_frontend/coprs/static/js/blog.js @@ -0,0 +1,28 @@ +// https://stackoverflow.com/a/10943610/3285282 + +$(document).ready(function(){ + $.get("https://fedora-copr.github.io/feed.xml", function (data) { + + // https://stackoverflow.com/a/10996297/3285282 + Date.prototype.getMonthName = function() { + var monthNames = [ + "Jan", "Feb", "Mar", "Apr", "May", "June", + "July", "Aug", "Sept", "Oct", "Nov", "Dec" + ]; + return monthNames[this.getMonth()]; + } + + $(data).find("item").each(function () { // or "item" or whatever suits your feed + var el = $(this); + var published = new Date(el.find("pubDate").text()); + var f_published = published.getDate() + " " + published.getMonthName() + " " + published.getFullYear() + + $("#blog-title").text(el.find("title").text()) + $("#blog-author").text(el.find("author").text()) + $("#blog-date").text(f_published) + $("#blog-link").attr("href", el.find("link").text()) + $("#blog-link").removeClass("hidden") + return false + }); + }); +}); diff --git a/frontend/coprs_frontend/coprs/templates/_helpers.html b/frontend/coprs_frontend/coprs/templates/_helpers.html index 49007fb..ae42750 100644 --- a/frontend/coprs_frontend/coprs/templates/_helpers.html +++ b/frontend/coprs_frontend/coprs/templates/_helpers.html @@ -313,6 +313,36 @@ {% endmacro %} +{% macro recent_blog_panel() %} +
+
+

News - Read All

+
+ +
+{% endmacro %} + + {% macro render_crumb(href, title, active=False) %}
  • diff --git a/frontend/coprs_frontend/coprs/templates/coprs/show.html b/frontend/coprs_frontend/coprs/templates/coprs/show.html index 7af98c6..efface3 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/show.html +++ b/frontend/coprs_frontend/coprs/templates/coprs/show.html @@ -2,7 +2,7 @@ {% block title %}Project List{% endblock %} {% block header %}Project List{% endblock %} {% from "_helpers.html" import render_pagination, copr_details_href, copr_name, user_projects_panel %} -{% from "_helpers.html" import recent_builds_panel, task_queue_panel %} +{% from "_helpers.html" import recent_builds_panel, task_queue_panel, recent_blog_panel %} {%block main_menu_projects %}active{% endblock %} {% block body %}
    @@ -46,6 +46,7 @@ {{ user_projects_panel(g.user) }} {% endif %} + {{ recent_blog_panel() }} {{ task_queue_panel(tasks_info) }} {{ recent_builds_panel(users_builds) }} diff --git a/frontend/coprs_frontend/coprs/templates/layout.html b/frontend/coprs_frontend/coprs/templates/layout.html index 1475cc7..63ec5e9 100644 --- a/frontend/coprs_frontend/coprs/templates/layout.html +++ b/frontend/coprs_frontend/coprs/templates/layout.html @@ -165,5 +165,9 @@ }); {% endif %} + + + + diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py index 8261a1a..59c4e9a 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py @@ -74,7 +74,7 @@ def coprs_show(page=1): # flask.g.user is none when no user is logged - showing builds from everyone # TODO: builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 5) takes too much time, optimize sql # users_builds = builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 5) - users_builds = builds_logic.BuildsLogic.get_recent_tasks(None, 5) + users_builds = builds_logic.BuildsLogic.get_recent_tasks(None, 4) return flask.render_template("coprs/show/all.html", coprs=coprs, @@ -100,7 +100,7 @@ def coprs_by_user(username=None, page=1): coprs = paginator.sliced_query # flask.g.user is none when no user is logged - showing builds from everyone - users_builds = builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 5) + users_builds = builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 4) return flask.render_template("coprs/show/user.html", user=user,