Skip to content

Commit

Permalink
[frontend] New HTML/CSS theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdebsk committed Aug 25, 2017
1 parent 3f9c7ef commit 15e2eeb
Show file tree
Hide file tree
Showing 39 changed files with 1,615 additions and 1,880 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Python code dependencies:
- flask
- flask-sqlalchemy
- hawkey
- humanize
- jinja2
- koji
- librepo
Expand Down
6 changes: 6 additions & 0 deletions aux/vagrant-config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ config = {
},
},
},
"frontend": {
# Access assets throught proxy to overcome limitations of HSTS.
"fedora_assets_url": "/apps_fp_o_proxy/global",
"fedmenu_url": "/apps_fp_o_proxy/fedmenu",
"fedmenu_data_url": "/apps_fp_o_proxy/js/data.js",
},
"plugins": ["copr"],
"copr": {
"config_path": "/home/vagrant/.config/copr",
Expand Down
9 changes: 9 additions & 0 deletions aux/vagrant-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- ipython
- js-jquery
- koji
- mod_ssl
- mod_wsgi
- policycoreutils-python
- postgresql
Expand All @@ -40,6 +41,7 @@
- python-flask-sqlalchemy
- python-flask-wtf
- python-hawkey
- python-humanize
- python-jinja2
- python-librepo
- python-mock
Expand Down Expand Up @@ -135,6 +137,13 @@
- name: enable permissive selinux mode for httpd
selinux_permissive: name=httpd_t permissive=True

- name: install httpd proxy config file
copy:
content: |
SSLProxyEngine on
ProxyPass /apps_fp_o_proxy https://apps.fedoraproject.org/
dest: /etc/httpd/conf.d/koschei-vagrant.conf

- name: start and enable httpd
service: name=httpd state=started enabled=true

Expand Down
7 changes: 2 additions & 5 deletions aux/validate-html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# vagrant up
# 2. install HTML validators:
# dnf copr enable mizdebsk/html-validator
# dnf install vnu
# dnf install vnu bootlint
# 3. run the script
# ./aux/validate-html.sh

Expand Down Expand Up @@ -55,7 +55,6 @@ get list-collections.html 'collections'
get list-groups.html 'groups'
get list-packages.html 'packages?collection=epel7'
get list-rebuild-requests.html 'rebuild-request/user/vagrant'
get new-rebuild-request.html 'rebuild-request/new'
get package-detail.html 'package/nekohtml?collection=f27'
get rebuild-request-detail.html 'rebuild-request/1'
get search-results.html 'search?q=maven'
Expand All @@ -70,9 +69,7 @@ vnu "${work_dir}"/*

# bootlint - linter for Bootstrap
# https://github.com/twbs/bootlint
# Install with: npm install bootlint
# FIXME enable when we switch to using Bootstrap
#bootlint -d W001,W002,W003,W009,W012 "${work_dir}"/*
bootlint -d W001,W002,W003,W009,W012 "${work_dir}"/*
# disabled warnings - https://github.com/twbs/bootlint/wiki
# W001 - UTF-8 charset - not needed, server sends proper Content-Type
# W002 - compatibility with legacy versions of M$ IE - couldn't care less
Expand Down
5 changes: 4 additions & 1 deletion config.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ config = {
#"user_re": "http://(.+)\\.id\\.fedoraproject\\.org/",
# Kerberos
#"user_re": "(.+)@EXAMPLE\\.COM",
}
},

# Global assets for Fedora apps
"fedora_assets_url": "https://apps.fedoraproject.org/global",

# Production copies for fedmenu
#"fedmenu_url": "https://apps.fedoraproject.org/fedmenu",
Expand Down
4 changes: 4 additions & 0 deletions koschei.spec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BuildRequires: python3-flask
BuildRequires: python3-flask-sqlalchemy
BuildRequires: python3-flask-wtf
BuildRequires: python3-wtforms
BuildRequires: python3-humanize >= 0.5.1
BuildRequires: python3-jinja2
BuildRequires: python3-dogpile-cache
BuildRequires: python3-six
Expand All @@ -64,6 +65,7 @@ BuildRequires: python-psycopg2
BuildRequires: python-flask
BuildRequires: python-flask-sqlalchemy
BuildRequires: python-flask-wtf
BuildRequires: python-humanize >= 0.5.1
BuildRequires: python-jinja2
BuildRequires: python-dogpile-cache
BuildRequires: python-six
Expand Down Expand Up @@ -119,11 +121,13 @@ Requires: python3-flask
Requires: python3-flask-sqlalchemy
Requires: python3-flask-wtf
Requires: python3-wtforms
Requires: python3-humanize >= 0.5.1
Requires: python3-jinja2
%else
Requires: python-flask
Requires: python-flask-sqlalchemy
Requires: python-flask-wtf
Requires: python-humanize >= 0.5.1
Requires: python-jinja2
%endif
Requires: mod_wsgi
Expand Down
7 changes: 5 additions & 2 deletions koschei/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,13 @@ def __composite_values__(self):
def __repr__(self):
return 'EVR({}:{}-{})'.format(self.epoch or 0, self.version, self.release)

def __nonzero__(self):
return bool(self.version and self.release)

def __str__(self):
epoch, version, release = self.__composite_values__()
if not version or not release:
if not self:
return ''
epoch, version, release = self.__composite_values__()
if len(release) > 16:
release = release[:13] + '...'
if epoch:
Expand Down
39 changes: 36 additions & 3 deletions koschei/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
from __future__ import print_function, absolute_import

import logging
import humanize

from functools import wraps

from flask import Flask, abort, request, g, url_for
from flask import Flask, abort, request, g, url_for, flash
from flask_sqlalchemy import BaseQuery, Pagination
from jinja2 import Markup
from sqlalchemy.orm import scoped_session, sessionmaker

from koschei.session import KoscheiSession
from koschei.config import get_config, load_config
from koschei.config import get_config
from koschei.db import Query, get_engine

dirs = get_config('directories')
Expand All @@ -39,6 +41,23 @@
frontend_config = get_config('frontend')


def flash_ack(message):
"""Send flask flash with message about operation that was successfully
completed."""
flash(message, 'success')


def flash_nak(message):
"""Send flask flash with with message about operation that was not
completed due to an error."""
flash(message, 'danger')


def flash_info(message):
"""Send flask flash with informational message."""
flash(message, 'info')


class FrontendQuery(Query, BaseQuery):
# pylint:disable=arguments-differ
def paginate(self, items_per_page):
Expand Down Expand Up @@ -106,7 +125,21 @@ def url(self):

@staticmethod
def get_tabs():
return [t for t in tabs if t.master_endpoint]
return [t for t in tabs if t.master_endpoint and not t.requires_user]

@staticmethod
def get_user_tabs():
return [t for t in tabs if t.master_endpoint and t.requires_user]


app.jinja_env.globals['get_tabs'] = Tab.get_tabs
app.jinja_env.globals['get_user_tabs'] = Tab.get_user_tabs

app.add_template_filter(humanize.intcomma, 'intcomma')
app.add_template_filter(humanize.naturaltime, 'naturaltime')
app.add_template_filter(humanize.naturaldelta, 'naturaldelta')


@app.template_filter()
def percentage(val):
return format(val * 10000, '.4f') + Markup(' ‱')
16 changes: 8 additions & 8 deletions koschei/frontend/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import re
import functools
from flask import abort, flash, request, session, redirect, url_for, g
from flask import abort, request, session, redirect, url_for, g

from koschei.config import get_config
from koschei.frontend import app, db
from koschei.frontend import app, db, flash_ack, flash_info
import koschei.models as m

bypass_login = get_config('bypass_login', None)
Expand All @@ -45,12 +45,12 @@ def login():
user = m.User(name=user_name, admin=bool(bypass_login))
db.add(user)
db.commit()
flash('New user "{}" was registered.'.format(user_name))
flash_info('New user "{}" was registered.'.format(user_name))
session['user'] = user_name
flash('Logged in as user "{}" with identity "{}".'
.format(user_name, identity))
flash_ack('Logged in as user "{}" with identity "{}".'
.format(user_name, identity))
if user.admin:
flash('You have admin privileges.')
flash_info('You have admin privileges.')
next_url = request.values.get("next", url_for('frontpage'))
return redirect(next_url)

Expand All @@ -68,9 +68,9 @@ def lookup_current_user():
@app.route('/logout')
def logout():
if session.pop('user', None):
flash('Successfully logged out.')
flash_ack('Successfully logged out.')
else:
flash('You were not logged in.')
flash_info('You were not logged in.')
return redirect(url_for('frontpage'))


Expand Down
7 changes: 4 additions & 3 deletions koschei/frontend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import re

from flask import flash
from flask_wtf import Form

from wtforms import (
Expand All @@ -32,6 +31,8 @@

from koschei.config import get_koji_config

from koschei.frontend import flash_nak


class StrippedStringField(StringField):
def process_formdata(self, values):
Expand Down Expand Up @@ -96,8 +97,8 @@ class EmptyForm(Form):
def validate_or_flash(self):
if self.validate_on_submit():
return True
flash("Validation errors: " +
', '.join(x for i in self.errors.values() for x in i))
flash_nak("Validation errors: " +
', '.join(x for i in self.errors.values() for x in i))
return False


Expand Down
Loading

0 comments on commit 15e2eeb

Please sign in to comment.