From bfb99d14e7af3fd8bf43338d6cdbf40eb1a10ba6 Mon Sep 17 00:00:00 2001 From: Daniel Washburn Date: Fri, 4 Nov 2016 19:01:02 -0400 Subject: Very basic functionality --- aliases/__init__.py | 1 + aliases/aliases.py | 40 ++++++++++++++++++++++++++++++ aliases/models.py | 35 ++++++++++++++++++++++++++ aliases/templates/index.html | 59 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 aliases/aliases.py create mode 100644 aliases/models.py create mode 100644 aliases/templates/index.html diff --git a/aliases/__init__.py b/aliases/__init__.py index ef96ccd..487ebee 100644 --- a/aliases/__init__.py +++ b/aliases/__init__.py @@ -1 +1,2 @@ from aliases import app +from models import * diff --git a/aliases/aliases.py b/aliases/aliases.py new file mode 100644 index 0000000..8aef861 --- /dev/null +++ b/aliases/aliases.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +""" + # Aliases + + A minimal web app to manage email aliases. + + :copyright: (c) 2016 by Daniel Washburn + :license: Common Development and Distribution License (CDDL-1.0). See LICENSE + +""" + +from flask import Flask, Response, request, session, url_for, redirect, \ + render_template, abort, g, flash, _app_ctx_stack +from flask_debugtoolbar import DebugToolbarExtension + +app = Flask(__name__) +app.config.from_object('config') + +toolbar = DebugToolbarExtension(app) + +from models import Alias + + +@app.route('/') +def index(): + entries = Alias.query + + return render_template('index.html', entries=entries) + + +@app.route('/login', methods=['GET', 'POST']) +def login(): + # stub + return redirect(url_for('index')) + + +@app.route('/logout') +def logout(): + # stub + return redirect(request.referrer or url_for('login')) diff --git a/aliases/models.py b/aliases/models.py new file mode 100644 index 0000000..a1b4287 --- /dev/null +++ b/aliases/models.py @@ -0,0 +1,35 @@ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.dialects.postgresql import ARRAY +from aliases import app + +db = SQLAlchemy(app) + +class User(db.Model): + __tablename__ = 'admins' + + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String, unique=True) + domains = db.Column(ARRAY(db.String)) + + def __init__(self, username, domains): + self.username = username + self.domains = domains + +class Alias(db.Model): + __tablename__ = 'aliases' + + id = db.Column(db.Integer, primary_key=True) + local_part = db.Column(db.String) + domain = db.Column(db.String) + action = db.Column(db.String) + destination = db.Column(db.String) + count = db.Column(db.Integer) + last_date = db.Column(db.DateTime) + + def __init__(self, local_part, domain, action, destination, count, last_date): + self.local_part = local_part + self.domain = domain + self.action = action + self.destination = destination + self.count = count + self.last_date = last_date diff --git a/aliases/templates/index.html b/aliases/templates/index.html new file mode 100644 index 0000000..7cf1ce8 --- /dev/null +++ b/aliases/templates/index.html @@ -0,0 +1,59 @@ + + + +Aliases + + + + +
+

Aliases

+
+ {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} +
+ {% block body %} + + + + + + + + + + + + + + {% for entry in entries %} + + + + + + + + + {% endfor %} + + + + + +
Local PartDomainActionDestinationCountLast Delivery
{{ entry.local_part }}{{ entry.domain }}{{ entry.action }}{{ entry.destination }}{{ entry.count }}{{ entry.last_date }}
+ + {% endblock %} +
+ + -- cgit v1.2.2