#524 Added rss feed from all copr's projects to /rss/ Closes #559
Merged 5 years ago by msuchy. Opened 5 years ago by hojang.
copr/ hojang/copr rss  into  master

@@ -85,7 +85,8 @@ 

  from coprs.views.user_ns import user_general

  from coprs.views.webhooks_ns import webhooks_ns

  from coprs.views.webhooks_ns import webhooks_general

- 

+ from coprs.views.rss_ns import rss_ns

+ from coprs.views.rss_ns import rss_general

  

  from coprs.exceptions import ObjectNotFound, AccessRestricted, BadRequest, CoprHttpException

  from .context_processors import include_banner, inject_fedmenu, counter_processor
@@ -105,6 +106,7 @@ 

  app.register_blueprint(groups_ns)

  app.register_blueprint(user_ns)

  app.register_blueprint(webhooks_ns)

+ app.register_blueprint(rss_ns)

  

  app.add_url_rule("/", "coprs_ns.coprs_show", coprs_general.coprs_show)

  

@@ -0,0 +1,16 @@ 

+ <?xml version="1.0" encoding="UTF-8" ?>

+ {% from "_helpers.html" import copr_url %}

+ <rss version="2.0">

+ <channel>

+   <title>Copr Home Page</title>

+   <link>https://copr.fedorainfracloud.org/coprs/</link>

+   <description>Copr is an easy-to-use automatic build system providing a package repository as its output</description>

+   {% for copr in coprs %}

+   <item>

+ 	  <title>{{copr.full_name}}</title>

+ 	  <link>{{copr_url('coprs_ns.copr_detail', copr, _external=True)}}</link>

+ 	  <description>{{copr.description}}</description>

+   </item>

+  {% endfor %}

+ </channel>

+ </rss>

@@ -0,0 +1,3 @@ 

+ import flask

+ 

+ rss_ns = flask.Blueprint("rss_ns", __name__, url_prefix="/rss")

@@ -0,0 +1,25 @@ 

+ # coding: utf-8

+ 

+ from coprs.views.rss_ns import rss_ns

+ from coprs import app

+ from coprs.helpers import fix_protocol_for_frontend

+ from coprs.logic.coprs_logic import CoprsLogic

+ from flask import render_template, Response

+ from coprs import models

+ 

+ 

+ @rss_ns.route("/", defaults={"limit": 200})

+ @rss_ns.route("/<int:limit>/")

+ def rss(limit=200):

+     """

+     Simple route that returns all projects

+     name, description, link to selected project

+     as rss feed

+ 

+     """

+ 

+     coprs = CoprsLogic.get_all().order_by(models.Copr.id.desc()).limit(limit)

+ 

+     answer = render_template("rss/rss.xml", coprs=coprs)

+ 

+     return Response(answer, mimetype="text/xml")

rebased onto 09f195feccb927b0b8dd0d3a8658878fae13470f

5 years ago

Hello @hojang,
thank you for this nice feature.

I really like the idea of creating rss_general.py instead of putting the code into coprs_general.py or somewhere else. This way we have a possibility to simply add more feeds in the future if we want to.

The code is well written and works fine, good job! :-)

Though, I have several suggestions to simplify it even more. In the rss_general.py we don't have to go through all coprs and create a (name, url, description) tuples for them. We can simply pass a list of all coprs to the template and let it deal with it. Then the template will iterate through copr in items or copr in coprs depends on which name you will use and it will print variables like this <title>{{ copr.full_name }}</title>. Here comes the tricky part, how to print the link, which we don't construct anymore. You can use the copr_url macro from _helpers.html. Be aware, that you have to import it below <?xml line, otherwise it complains, that this has to be the first line of the file. Also, you need to use the copr_url macro with _external=True parameter in order to print a full URL (with hostname and everything).

rebased onto bdb5dc5bf06e8e828d838a40c36a52584aac0c5c

5 years ago

rebased onto da6c0320cc3daf7d5011c36a5b3797e97cc8a5e6

5 years ago

OK done, but I still use this two lines:

url = 'https://' + app.config["PUBLIC_COPR_HOSTNAME"]
url = fix_protocol_for_frontend(url)

for getting part of url that represents computer running copr.
If you know some solution how to get this part in template I would be appreciative.

OK done, but I still use this two lines:

url = 'https://' + app.config["PUBLIC_COPR_HOSTNAME"]
url = fix_protocol_for_frontend(url)

for getting part of url that represents computer running copr.
If you know some solution how to get this part in template I would be appreciative.

That's exactly what _external=True parameter is for :-)

Also, you need to use the copr_url macro with _external=True parameter in order to print a full URL (with hostname and everything).

rebased onto 465c946099fe20a4aa636bc5641ad68f60f379ed

5 years ago

rebased onto db3ef6bb32f85c2becfd4166650ab02b2e4e0c09

5 years ago

4 new commits added

  • updated limit
  • Updated rss feed
  • Added image to rss feed.
  • Added rss feed from all copr's projects to /rss/
5 years ago

rebased onto a2b0eb2

5 years ago

Pull-Request has been merged by msuchy

5 years ago