Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 64139b0697134c8ce5f063d937d3f33fbdc3cdfe Author: Valentin Gologuzov vgologuz@redhat.com Date: Fri Feb 20 14:40:12 2015 +0100
[frontend] [rhbz:#1185959] RFE: Present statistics about project popularity: less logic in jinja template
frontend/coprs_frontend/coprs/config.py | 3 +- frontend/coprs_frontend/coprs/log.py | 2 +- frontend/coprs_frontend/coprs/models.py | 8 ++ .../coprs/templates/coprs/detail/overview.html | 75 +++++++------------- .../coprs/views/coprs_ns/coprs_general.py | 32 ++++++-- .../coprs/views/stats_ns/stats_receiver.py | 2 +- 6 files changed, 62 insertions(+), 60 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/config.py b/frontend/coprs_frontend/coprs/config.py index b8bb37a..15f3c08 100644 --- a/frontend/coprs_frontend/coprs/config.py +++ b/frontend/coprs_frontend/coprs/config.py @@ -42,8 +42,9 @@ class Config(object):
# primary log file LOG_FILENAME = "/var/log/copr/frontend.log" - INTRANET_IPS = ["127.0.0.1"]
+ INTRANET_IPS = ["127.0.0.1"] + DEBUG = True
class ProductionConfig(Config): DEBUG = False diff --git a/frontend/coprs_frontend/coprs/log.py b/frontend/coprs_frontend/coprs/log.py index 90d2022..8fd6d55 100644 --- a/frontend/coprs_frontend/coprs/log.py +++ b/frontend/coprs_frontend/coprs/log.py @@ -45,4 +45,4 @@ def setup_log(): handler.setLevel(log_level) app.logger.addHandler(handler)
- app.logger.info("logging configuration finished") + app.logger.info("logging configuration finished, config: {}".format(app.config)) diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index d6cfe5d..1e011c3 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -429,6 +429,14 @@ class MockChroot(db.Model, helpers.Serializer): """ return "{}-{}".format(self.os_release, self.os_version)
+ + @property + def name_release_human(self): + """ + Textual representation of name of this or release + """ + return "{} {}".format(self.os_release, self.os_version) + @property def os(self): """ diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html index 6063a33..5c9629a 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html +++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/overview.html @@ -18,66 +18,42 @@ </div> <div class="dnf-enable-field"> # <input onClick="this.select();"type="text" value="dnf copr enable {{copr.owner.name}}/{{ copr.name}}" readonly="readonly"> More info about <a target="_blank" href="https://fedorahosted.org/copr/wiki/HowToEnableRepo">how to enable a repo on the wiki page.</a></div> + <table class="releases"> <tr> <th class="leftmost">Release</th> <th>Architecture</th> - - <th class="rightmost">Yum Repo <small>[Downloads]</small></th> + <th>#Downloads</th> + <th class="rightmost">Yum Repo </th> </tr> - <!-- TODO: remove complex logic from html, group by os-release in the python view --> - {% for mock_chroot in copr.active_chroots %} - {% if loop.index < copr.active_chroots|length %} - {% if mock_chroot.os_release != copr.active_chroots[loop.index].os_release or - mock_chroot.os_version != copr.active_chroots[loop.index].os_version %} - {# next release is different => release-end #} - <tr class="release-end"> - {% else %} - <tr> - {% endif %} - {% else %}{# last line => release-end for sure #} - <tr class="release-end"> - {% endif %} - {% if mock_chroot.os_release != copr.active_chroots[loop.index0 - 1].os_release or - mock_chroot.os_version != copr.active_chroots[loop.index0 - 1].os_version or - loop.index0 == 0 %} - {# previous os_release-os_version were different or this is the first one #} - <td>{{ mock_chroot.os_release|capitalize }} {{ mock_chroot.os_version }}</td> - {% else %} - <td></td> - {% endif %} + {% for repo in repos_info_list %} + <tr class="release-end"> + <td class="leftmost"> + {{ repo.name_release_human|capitalize }} + </td> <td> - {{ mock_chroot.arch }} - {% if copr.buildroot_pkgs(mock_chroot): %} - <a id="modified-chroot-{{mock_chroot.name}}">[modified]</a> - {% endif %} + {{ repo.arch_list|join(", ") }} </td> <td> - {% if mock_chroot.os_release != copr.active_chroots[loop.index0 - 1].os_release or - mock_chroot.os_version != copr.active_chroots[loop.index0 - 1].os_version or - loop.index0 == 0 %} - {# previous os_release-os_version were different or this is the first one #} - - <a href="{{ - url_for( - 'coprs_ns.generate_repo_file', - username=copr.owner.name, - coprname=copr.name, - chroot=mock_chroot.os_release+"-"+mock_chroot.os_version, - repofile=copr.owner.name+'-'+copr.name+'-'+mock_chroot.os_release+"-"+mock_chroot.os_version+'.repo', - _external=True - )|fix_url_https_frontend}}"> - {{ copr.owner.name }}-{{ copr.name }}-{{mock_chroot.os_release+"-"+mock_chroot.os_version}}.repo - </a> - <small>[ {{ repo_dl_stat[mock_chroot.name_release] }} ]</small> - {% endif %} + <center> {{ repo.dl_stat }} </center> </td> - - </tr> - {% else %} - <tr colspan="2"><td>No active releases</td></tr> + <td class="rightmost"> + <a href="{{ + url_for( + 'coprs_ns.generate_repo_file', + username=copr.owner.name, + coprname=copr.name, + name_release=repo.name_release, + repofile=repo.repo_file, + _external=True + )|fix_url_https_frontend}}"> + {{ repo.repo_file }} + </a> + </td> + </tr> {% endfor %} </table> + {% if copr.repos_list %} <h2>Repository List</h2> <ul class=repos-list> @@ -87,6 +63,7 @@ </ul> {% endif %}
+ {% if g.user and g.user.can_edit(copr) and copr and copr.owner and not copr.auto_createrepo %} <dt> <!--<h2>Release options</h2>--> 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 75ade2f..de05b68 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py @@ -184,12 +184,28 @@ def copr_detail(username, coprname): except sqlalchemy.orm.exc.NoResultFound: return page_not_found( "Copr with name {0} does not exist.".format(coprname)) - from collections import defaultdict + repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr) + + repos_info = {} + for chroot in copr.active_chroots: + if chroot.name_release not in repos_info: + repos_info[chroot.name_release] = { + "name_release": chroot.name_release, + "name_release_human": chroot.name_release_human, + "arch_list": [chroot.arch], + "repo_file": "{}-{}-{}.repo".format(copr.owner.name, copr.name, chroot.name_release), + "dl_stat": repo_dl_stat[chroot.name_release] + } + else: + repos_info[chroot.name_release]["arch_list"].append(chroot.arch) + repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"]) + return flask.render_template("coprs/detail/overview.html", copr=copr, form=form, - repo_dl_stat=repo_dl_stat + repo_dl_stat=repo_dl_stat, + repos_info_list=repos_info_list, )
@@ -509,9 +525,9 @@ def copr_legal_flag(username, coprname): coprname=coprname))
-@coprs_ns.route("/<username>/<coprname>/repo/<chroot>/", defaults={"repofile": None}) -@coprs_ns.route("/<username>/<coprname>/repo/<chroot>/<repofile>") -def generate_repo_file(username, coprname, chroot, repofile): +@coprs_ns.route("/<username>/<coprname>/repo/<name_release>/", defaults={"repofile": None}) +@coprs_ns.route("/<username>/<coprname>/repo/<name_release>/<repofile>") +def generate_repo_file(username, coprname, name_release, repofile): """ Generate repo file for a given repo name. Reponame = username-coprname """ # This solution is used because flask splits off the last part after a @@ -520,7 +536,7 @@ def generate_repo_file(username, coprname, chroot, repofile):
reponame = "{0}-{1}".format(username, coprname)
- if repofile is not None and repofile != username + '-' + coprname + '-' + chroot + '.repo': + if repofile is not None and repofile != username + '-' + coprname + '-' + name_release + '.repo': return page_not_found( "Repository filename does not match expected: {0}" .format(repofile)) @@ -534,9 +550,9 @@ def generate_repo_file(username, coprname, chroot, repofile): return page_not_found( "Project {0}/{1} does not exist".format(username, coprname))
- mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(chroot, noarch=True).first() + mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(name_release, noarch=True).first() if not mock_chroot: - return page_not_found("Chroot {0} does not exist".format(chroot)) + return page_not_found("Chroot {0} does not exist".format(name_release))
url = "" for build in copr.builds: diff --git a/frontend/coprs_frontend/coprs/views/stats_ns/stats_receiver.py b/frontend/coprs_frontend/coprs/views/stats_ns/stats_receiver.py index caf3039..3f811ba 100644 --- a/frontend/coprs_frontend/coprs/views/stats_ns/stats_receiver.py +++ b/frontend/coprs_frontend/coprs/views/stats_ns/stats_receiver.py @@ -23,7 +23,7 @@ def increment(counter_type, name): return "", 201
@stats_rcv_ns.route("/from_logstash", methods=['POST']) -#@intranet_required +@intranet_required # ? def logstash_handler(): # import ipdb; ipdb.set_trace() json = flask.request.json