Permalink
Browse files

Add ability to attend/unattend for other dates

  • Loading branch information...
1 parent c1946ed commit 41e60b678966647598d0ad71277328f54e372e16 @jonasb jonasb committed Oct 24, 2011
Showing with 36 additions and 12 deletions.
  1. +15 −7 mugshots.py
  2. +4 −2 static/forsk.js
  3. +10 −0 static/style.css
  4. +7 −3 templates/index.html
View
@@ -9,7 +9,15 @@
db = flaskext.redis.init_redis(app)
-
+def get_date():
+ today = request.args.get('date', '')
+ try:
+ datetime.datetime.strptime(today, '%Y-%m-%d')
+ except:
+ if len(today) > 0:
+ flash("Format of date '%s' is incorrect, should be YYYY-mm-dd" % (today,))
+ today = datetime.datetime.now().strftime('%Y-%m-%d')
+ return today
@app.route("/setup-first")
def setup_first():
@@ -60,7 +68,7 @@ def index():
return redirect(url_for('setup_first'))
people = db.smembers('nicks')
- today = datetime.datetime.now().strftime('%Y-%m-%d')
+ today = get_date()
members = []
for person in people:
otherkey = '%s:%s' % (person, today)
@@ -72,14 +80,14 @@ def index():
junk, _, month = candidate_month.partition(":")
reports.add(month)
- return render_template('index.html', members=members, circles=circles, reports=reports)
+ return render_template('index.html', today=today, members=members, circles=circles, reports=reports)
@app.route("/attend")
def attend():
"""Ajax callback to record a person as attending a circle.
"""
- today = datetime.datetime.now().strftime('%Y-%m-%d')
- this_month = datetime.datetime.now().strftime('%Y-%m')
+ today = get_date()
+ this_month = today[0:-3]
nick = request.args.get("nick", "")
circle = request.args.get("circle", "")
if nick and circle:
@@ -99,8 +107,8 @@ def attend():
def unattend():
"""Ajax callback to cancel attendance for one person.
"""
- today = datetime.datetime.now().strftime('%Y-%m-%d')
- this_month = today[len(today)-3]
+ today = get_date()
+ this_month = today[0:-3]
nick = request.args.get("nick")
circle = request.args.get("circle")
if nick and circle:
View
@@ -1,11 +1,12 @@
$(function() {
$("ul.people li a").click(function(e) {
var $this = $(this),
+ today = $this.data('today') || '',
circle = $this.data('mnemonic') || '',
circleName = $this.data('name') || '',
nick = $this.parent().find('span').html();
e.preventDefault();
- $.get('/attend?nick=' + nick + '&circle=' + circle, function(result, status) {
+ $.get('/attend?date=' + today + '&nick=' + nick + '&circle=' + circle, function(result, status) {
if (result) {
$this.parent()
.find('span')
@@ -24,10 +25,11 @@ $(function() {
$(".unattender").live('click', function(e) {
var $this = $(this),
+ today = $this.data('today') || '',
circle = $this.data('circle') || '',
nick = $this.data('nick') || '';
e.preventDefault();
- $.get('/unattend?nick=' + nick + '&circle=' + circle, function(result, status) {
+ $.get('/unattend?date=' + today + '&nick=' + nick + '&circle=' + circle, function(result, status) {
window.location.href=window.location.href;
});
View
@@ -20,6 +20,16 @@ span {
font-size: 70%;
}
+#call-to-action h2 {
+ float: left;
+}
+#call-to-action p {
+ float: right;
+}
+.source {
+ clear: both;
+}
+
#addnick {background: #AB3229;}
#addnick input {width:280px}
View
@@ -25,18 +25,22 @@
<div id=content>
<h1 id="heading">Forskningsavdelningen: Studiecirklar</h1>
- <h2>Vad gör personen i afton?</h2>
+ <div id=call-to-action>
+ <h2>Vad gör personen i afton?</h2>
+ <p>{{today}}</p>
+ </div>
+
<div class="source">
<ul class="people">
{% for member in members %}
<li><span>{{ member['name'] }}</span>
{% if member['circle'] %}
<em>{{ member['circle'] }}</em>
- <a class=unattender data-circle="{{ member['circle'] }}" data-nick="{{ member['name'] }}" href=#>remove</a>
+ <a class=unattender data-today="{{today}}" data-circle="{{ member['circle'] }}" data-nick="{{ member['name'] }}" href=#>remove</a>
{% else %}
{% for circ in circles %}
- <a data-mnemonic="{{ circ['mnemonic'] }}" data-name="{{ circ['name'] }}" href=#>{{ circ['name'] }}</a>
+ <a data-mnemonic="{{ circ['mnemonic'] }}" data-today="{{today}}" data-name="{{ circ['name'] }}" href=#>{{ circ['name'] }}</a>
{% endfor %}
{% endif %}
</li>

0 comments on commit 41e60b6

Please sign in to comment.