Added mailing list support.
parent
9b68b5487f
commit
9cd5c83635
66
main.py
66
main.py
|
@ -1,5 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import feedparser
|
||||
from flask import Flask, render_template
|
||||
import requests
|
||||
import string
|
||||
import random
|
||||
from flask import Flask, render_template, request, flash, session, abort
|
||||
from time import mktime
|
||||
from datetime import datetime
|
||||
|
||||
|
@ -18,13 +23,68 @@ def pull_feed_entries():
|
|||
all_entries.sort(key=lambda e: e.updated_parsed, reverse=True)
|
||||
return all_entries[:app.config['MAX_ENTRIES']]
|
||||
|
||||
@app.route('/')
|
||||
def mailman_subscribe(email, mailing_list):
|
||||
r = requests.post("https://lists.hackerspace.pl/subscribe/" + mailing_list, {"email": email, "fullname": "", "pw": "", "pw-conf": "", "email-button": "Zapisz", "digest": 0})
|
||||
if r.status_code != 200:
|
||||
return False
|
||||
return True
|
||||
|
||||
@app.route('/', methods=["POST", "GET"])
|
||||
def main():
|
||||
if request.method == "POST":
|
||||
if "email" in request.form:
|
||||
email = request.form["email"].strip()
|
||||
if len(email) > 0:
|
||||
if "@" in email:
|
||||
lists = []
|
||||
if "mail-waw" in request.form:
|
||||
lists.append("waw")
|
||||
if "mail-proj" in request.form:
|
||||
lists.append("waw-proj")
|
||||
if "mail-offtopic" in request.form:
|
||||
lists.append("waw-ot")
|
||||
subscribed = []
|
||||
failed = []
|
||||
for maillist in lists:
|
||||
if mailman_subscribe(email, maillist):
|
||||
subscribed.append(maillist)
|
||||
else:
|
||||
failed.append(maillist)
|
||||
if len(subscribed) == 1:
|
||||
flash(u"Pomyślnie zasubskrybowano na listę %s@lists.hackerspace.pl.\
|
||||
W celu aktywacji subskrypcji odwiedź odnośnik wysłany mailem na adres %s." % (subscribed[0], email))
|
||||
elif len(subscribed) > 1:
|
||||
flash(u"Pomyślnie zasubskrybowano na listy %s. \
|
||||
W celu aktywacji subskrypcji odwiedź odnośniki wysłane mailem na adres %s." % \
|
||||
(", ".join(l + "@lists.hackerspace.pl" for l in subscribed), email))
|
||||
if len(failed) > 0:
|
||||
flash(u"Wystąpił problem z zapisaniem na następujące listy: %s. Ups! Napisz na bofh@hackerspace.pl, spróbujemy to naprawić." % ", ".join(failed), "error")
|
||||
else:
|
||||
flash(u"Podano nieprawidłowy adres email.", "error")
|
||||
else:
|
||||
flash(u"Nie podano adresu email.", "error")
|
||||
|
||||
|
||||
return render_template('main.html', entries=pull_feed_entries())
|
||||
|
||||
@app.route('/about')
|
||||
def about():
|
||||
return render_template('about.html')
|
||||
|
||||
@app.before_request
|
||||
def csrf_protect():
|
||||
if request.method == "POST":
|
||||
token = session.pop('_csrf_token', None)
|
||||
if not token or token != request.form.get('_csrf_token'):
|
||||
abort(403)
|
||||
generate_csrf_token()
|
||||
|
||||
def generate_csrf_token():
|
||||
if '_csrf_token' not in session:
|
||||
session['_csrf_token'] = "".join(random.choice(string.letters) for _ in range(32))
|
||||
return session['_csrf_token']
|
||||
|
||||
app.jinja_env.globals['csrf_token'] = generate_csrf_token
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run('0.0.0.0', 8080, debug=True)
|
||||
app.run('0.0.0.0', 8080, debug=True)
|
|
@ -81,7 +81,7 @@ span.author {
|
|||
|
||||
#left {
|
||||
border-right: 2px groove #fff;
|
||||
margin-right: 250px;
|
||||
margin-right: 270px;
|
||||
}
|
||||
|
||||
#right {
|
||||
|
@ -90,6 +90,8 @@ span.author {
|
|||
top: 100px;
|
||||
padding-top: 16px;
|
||||
right: 0;
|
||||
margin-right: 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.clear {
|
||||
|
@ -148,3 +150,66 @@ span.author {
|
|||
font-size: 1.2em;
|
||||
}
|
||||
}
|
||||
|
||||
#right h4 {
|
||||
margin-bottom: 0px;
|
||||
margin-left: 0px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
h1.mail {
|
||||
margin-bottom: 2px !important;
|
||||
}
|
||||
|
||||
#right .email-entry {
|
||||
width: 90%;
|
||||
border: 1px groove #777;
|
||||
padding: 2px;
|
||||
background: none repeat scroll 0% 0% rgb(250, 250, 250);
|
||||
color: rgb(34, 34, 34);
|
||||
margin: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#right .email-submit {
|
||||
padding: 4px 14px 4px 14px;
|
||||
}
|
||||
|
||||
.mailcheck {
|
||||
margin-right: 8px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
|
||||
div.mail-desc {
|
||||
font-size: 14px;
|
||||
padding-left: 26px;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
div.flashes {
|
||||
padding: 0;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 80%;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
div.flashes ul {
|
||||
list-style-type: none;
|
||||
padding: 0 0 5px 0;
|
||||
}
|
||||
|
||||
div.flashes li {
|
||||
width: 90%;
|
||||
border-radius: 4px;
|
||||
background-color: #308033;
|
||||
padding: 5px;
|
||||
margin-top: 5px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
div.flashes li.error {
|
||||
background-color: #a01023;
|
||||
}
|
|
@ -33,6 +33,17 @@
|
|||
{% block header %}
|
||||
{% include 'header.html' %}
|
||||
{% endblock %}
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="flashes">
|
||||
<ul>
|
||||
{% for category, message in messages %}
|
||||
<li class="{{ category }}">{{ message }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<div id="hs_main">
|
||||
{% block main %}
|
||||
<div id="hs_rotimage">
|
||||
|
|
|
@ -36,7 +36,21 @@
|
|||
</ul>
|
||||
</div>
|
||||
<div id="right">
|
||||
<h1 class"mail">Listy mailingowe</h1>
|
||||
<form action="/" method="post">
|
||||
<input name=_csrf_token type=hidden value="{{ csrf_token() }}">
|
||||
<h1 class="mail" style="text-align: center;">Listy mailingowe</h1>
|
||||
<h2 style="text-align: center; margin-top: -6px;">Zapisz się i porozmawiaj</h2>
|
||||
<h4><input name="mail-waw" type="checkbox" class="mailcheck" checked="true" />Warszawska</h4>
|
||||
<div class="mail-desc">Główna lista dyskusyjna hackerspaceu - organizacja i rozwiązywanie problemów.</div>
|
||||
<h4><input name="mail-proj" type="checkbox" class="mailcheck" checked="true"/>Warszawska Projektowa</h4>
|
||||
<div class="mail-desc">Informacje o postępie projektów, pomysły, ogłaszanie sukcesów i porażek.</div>
|
||||
<h4><input name="mail-offtopic" type="checkbox" class="mailcheck" />Off Topic</h4>
|
||||
<div class="mail-desc">Dyskusja o wszystkim i o niczym. Niski stosunek sygnału do szumu.</div>
|
||||
<center>
|
||||
<input type="text" name="email" class="email-entry" placeholder="twoj@email.com" />
|
||||
<input type="submit" value="Zapisz się" class="email-submit" />
|
||||
</center>
|
||||
</form>
|
||||
<h1 class="twitter">Twitter</h1>
|
||||
<script type="text/javascript">
|
||||
new TWTR.Widget({
|
||||
|
|
Loading…
Reference in New Issue