summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazański <q3k@q3k.org>2013-02-13 20:53:08 +0100
committerSergiusz Bazański <q3k@q3k.org>2013-02-13 20:53:08 +0100
commit9cd5c8363505980d27d16fa46635d5778872fd46 (patch)
tree3dd90c3bbf3a9e265e9ef87a028ff97e6d97df23
parent9b68b5487f9f6f684fd5e5785860815ab1eb0ab7 (diff)
downloadwww-main-9cd5c8363505980d27d16fa46635d5778872fd46.tar.gz
www-main-9cd5c8363505980d27d16fa46635d5778872fd46.tar.bz2
www-main-9cd5c8363505980d27d16fa46635d5778872fd46.tar.xz
www-main-9cd5c8363505980d27d16fa46635d5778872fd46.zip
Added mailing list support.
-rw-r--r--main.py66
-rw-r--r--static/main.css67
-rw-r--r--templates/basic.html11
-rw-r--r--templates/main.html16
4 files changed, 155 insertions, 5 deletions
diff --git a/main.py b/main.py
index 684a583..2270f1f 100644
--- a/main.py
+++ b/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) \ No newline at end of file
diff --git a/static/main.css b/static/main.css
index d85cbef..9450021 100644
--- a/static/main.css
+++ b/static/main.css
@@ -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;
+} \ No newline at end of file
diff --git a/templates/basic.html b/templates/basic.html
index 21582cc..6a0d4d8 100644
--- a/templates/basic.html
+++ b/templates/basic.html
@@ -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">
diff --git a/templates/main.html b/templates/main.html
index bf8d38b..99a6d3c 100644
--- a/templates/main.html
+++ b/templates/main.html
@@ -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({