Exemplo n.º 1
0
def text_page(name, ns='general', comments=False):
    text = get_text(ns, name)
    return flask.render_template(
        'text.html',
        title=text['title'],
        text=text['content'] + text['more_content'],
        comments=comments,
    )
Exemplo n.º 2
0
def stats_page(name):
    text = get_text('stats', name)
    if not text['title']:
        flask.abort(404)
    return flask.render_template(
        'text.html',
        title=text['title'],
        text=text['content'] + text['more_content'],
        comments=False,
    )
Exemplo n.º 3
0
 def stats_detail(name, color):
     stats_text = get_text('stats', name)
     return {
         'background_img': flask.url_for(
             'static',
             filename='img/stats/%s.jpg' % color,
         ),
         'title': stats_text['title'],
         'content': stats_text['content'] + stats_text['more_content'],
         'url': flask.url_for('.text_page', ns='stats', name=name)
     }
Exemplo n.º 4
0
def text_content(name, fold=False, below_fold=False, ns='general'):
    text = get_text(ns, name) or BLANK_PAGE

    if fold:
        html = text['content']

    elif below_fold:
        html = text['more_content']

    else:
        html = text['content'] + text['more_content']

    return jinja2.Markup(html)
Exemplo n.º 5
0
def alegeri2016(judet=None):
    county_code = None
    candidates = defaultdict(lambda: defaultdict(list))

    counties = dal.get_county_name_map()
    counties['diaspora'] = counties.pop(None)

    if judet:
        if judet not in counties:
            flask.abort(404)

        import csv
        from pathlib import Path
        csv_path = Path(__file__).parent / 'alegeri2016_candidati.csv'
        with csv_path.open('r', encoding='utf-8') as f:
            for line in csv.DictReader(f):
                if line['judet_2016'] == judet:
                    slug = line['slug']
                    try:
                        person = dal.get_person(slug)
                    except:
                        continue
                        #raise RuntimeError("Can't find person %r" % slug)
                    chamber = {'0': 'cdep', '1': 'senat'}[line['senate']]
                    party = line['party']
                    candidates[chamber][party].append({
                        'person': person.get_main_details(),
                        'rank': int(line['rank']),
                    })
        for candidate_parties in candidates.values():
            for person_list in candidate_parties.values():
                person_list.sort(key=lambda p: p['rank'])

    return flask.render_template('alegeri2016_index.html', **{
        'breadcrumb': ['Alegeri 2016'],
        'snippet': get_text('snippet', 'alegeri2016'),
        'judet': judet,
        'candidates': candidates,
        'counties': sorted(counties.items()),
    })
Exemplo n.º 6
0
def edit():
    ns = flask.request.args['ns']
    name = flask.request.args['name']
    text = get_text(ns, name)

    if flask.request.method == 'POST':
        form = flask.request.form
        save_text(
            ns, name,
            form['title'], form['content'], form['more_content'],
        )
        flask.flash("Text saved", 'success')
        return flask.redirect(flask.url_for('.edit', ns=ns, name=name))

    return flask.render_template(
        'admin_edit.html',
        ns=ns,
        name=name,
        title=text['title'],
        content=text['content'],
        more_content=text['more_content'],
    )
Exemplo n.º 7
0
def text_title(name, ns='general'):
    text = get_text(ns, name)
    return text['title']