瀏覽代碼

Flask basics, style.

master
Ben Kurtovic 7 年之前
父節點
當前提交
fce7e1c4ee
共有 13 個檔案被更改,包括 246 行新增4 行删除
  1. +3
    -0
      .gitignore
  2. +1
    -1
      LICENSE
  3. +18
    -3
      README.md
  4. +24
    -0
      app.py
  5. +0
    -0
     
  6. +45
    -0
      calefaction/util.py
  7. +3
    -0
      requirements.txt
  8. +77
    -0
      static/style.css
  9. +29
    -0
      templates/_base.mako
  10. +9
    -0
      templates/_default.mako
  11. +14
    -0
      templates/_layout.mako
  12. +15
    -0
      templates/error.mako
  13. +8
    -0
      templates/landing.mako

+ 3
- 0
.gitignore 查看文件

@@ -0,0 +1,3 @@
*.pyc
__pycache__/
venv/

+ 1
- 1
LICENSE 查看文件

@@ -1,4 +1,4 @@
Copyright (C) 2015-2016 Ben Kurtovic <ben.kurtovic@gmail.com>
Copyright (C) 2016 Ben Kurtovic <ben.kurtovic@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal


+ 18
- 3
README.md 查看文件

@@ -1,10 +1,24 @@
calefaction
===========

__calefaction__ is a modular corporation manager for the video game
__calefaction__ is a corporation manager and dashboard for the video game
[EVE Online](https://www.eveonline.com/).

Installing
Guide
-----

...
### Install

git clone git@github.com:earwig/calefaction.git
cd calefaction
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt

### Setup

...

### Run

...

+ 24
- 0
app.py 查看文件

@@ -0,0 +1,24 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import Flask, g
from flask_mako import MakoTemplates, render_template

from calefaction.util import catch_errors, set_up_hash_versioning

app = Flask(__name__)

MakoTemplates(app)
set_up_hash_versioning(app)

@app.before_request
def prepare_request():
g.something = None # ...

@app.route("/")
@catch_errors(app)
def index():
return render_template("landing.mako")

if __name__ == "__main__":
app.run(debug=True, port=8080)

+ 0
- 0
查看文件


+ 45
- 0
calefaction/util.py 查看文件

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

from functools import wraps
from hashlib import md5
from os import path
from traceback import format_exc

from flask import url_for
from flask_mako import render_template, TemplateError

__all__ = ["catch_errors", "set_up_hash_versioning"]

def catch_errors(app):
def callback(func):
@wraps(func)
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except TemplateError as exc:
app.logger.error("Caught exception:\n{0}".format(exc.text))
return render_template("error.mako", traceback=exc.text)
except Exception:
app.logger.exception("Caught exception:")
return render_template("error.mako", traceback=format_exc())
return inner
return callback

def set_up_hash_versioning(app):
def callback(app, error, endpoint, values):
if endpoint == "staticv":
filename = values["filename"]
fpath = path.join(app.static_folder, filename)
mtime = path.getmtime(fpath)
cache = app._hash_cache.get(fpath)
if cache and cache[0] == mtime:
hashstr = cache[1]
else:
with open(fpath, "rb") as f:
hashstr = md5(f.read()).hexdigest()
app._hash_cache[fpath] = (mtime, hashstr)
return url_for("static", filename=filename, v=hashstr)
raise error

app._hash_cache = {}
app.url_build_error_handlers.append(lambda *args: callback(app, *args))

+ 3
- 0
requirements.txt 查看文件

@@ -0,0 +1,3 @@
Flask==0.11.1
Flask-Mako==0.4
requests==2.12.4

+ 77
- 0
static/style.css 查看文件

@@ -0,0 +1,77 @@
/* FONT... */
/* MOBILE... */

body {
display: flex;
min-height: 100vh;
flex-direction: column;
margin: 0;
font-family: sans-serif;
background-color: #173350;
color: #E6EAEF;
}

#container {
display: flex;
flex: 1;
}

#container > div {
width: 100%;
}

main, header, footer {
background-color: rgba(0, 0, 0, 0.85);
}

main, header > div, footer > div {
max-width: 1000px;
width: 80%;
}

main {
margin: 2em auto;
padding: 1em;
}

header > div {
margin: 0 auto;
padding: 1.5em;
}

header > div > div {
display: inline-block;
}

header > div > .left {
text-align: left;
width: 70%;
}

header > div > .right {
text-align: right;
width: 30%;
}

footer {
font-size: 85%;
}

footer > div {
margin: 0 auto;
padding: 1em;
}

a {
color: #78CEFF;
text-decoration: none;
}

a:hover {
color: #68BEDD;
text-decoration: underline;
}

#error pre {
white-space: pre-wrap;
}

+ 29
- 0
templates/_base.mako 查看文件

@@ -0,0 +1,29 @@
<%!
from datetime import datetime
%>\
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
<%block name="title">CORP_NAME...</%block>
</title>
<link rel="stylesheet" href="${url_for('staticv', filename='style.css')}" type="text/css" />
<!-- FAVICONS... -->
</head>
<body>
${next.body()}
<footer>
<div>
<%
copyright_year = datetime.now().year
%>
Copyright &copy; ${copyright_year} COPYRIGHT_HOLDER...
&bull;
Running <a href="https://github.com/earwig/calefaction">Calefaction</a> CALEFACTION_VERSION...
&bull;
<a href="https://eveonline.com">EVE Online</a> and all related trademarks are property of <a href="https://ccpgames.com">CCP hf</a>.
</div>
</footer>
</body>
</html>

+ 9
- 0
templates/_default.mako 查看文件

@@ -0,0 +1,9 @@
<%inherit file="_layout.mako"/>
<%block name="lefthead">
[CORP_LOGO] CORP_NAME...
<nav>Campaign: XYZ | Map | Intel | Members</nav>
</%block>
<%block name="righthead-">
PLAYER_NAME [logout]
</%block>
${next.body()}

+ 14
- 0
templates/_layout.mako 查看文件

@@ -0,0 +1,14 @@
<%inherit file="_base.mako"/>
<header>
<div>
<div class="left"><%block name="lefthead"/></div><!--
--><div class="right"><%block name="righthead"/></div>
</div>
</header>
<div id="container">
<div>
<main>
${next.body()}
</main>
</div>
</div>

+ 15
- 0
templates/error.mako 查看文件

@@ -0,0 +1,15 @@
<%inherit file="_base.mako"/>
<%block name="title">
Error &ndash; ...name...
</%block>
<div id="container">
<div>
<main>
<h1>Error!</h1>
<p>You may report the following information to the developers:</p>
<div id="error">
<pre>${traceback | trim,h}</pre>
</div>
</main>
</div>
</div>

+ 8
- 0
templates/landing.mako 查看文件

@@ -0,0 +1,8 @@
<%inherit file="_layout.mako"/>
<%block name="lefthead">
[C_LOGO] C_NAME...
</%block>
<%block name="righthead">
[login]
</%block>
<p>Hello, world!</p>

Loading…
取消
儲存