Skip to content

Commit 2d513d7

Browse files
committed
updated and tweaked various goodies. this is a terrible commit message. i am a terrible person
1 parent 993aa5e commit 2d513d7

File tree

9 files changed

+98
-48
lines changed

9 files changed

+98
-48
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Little attention has been paid to making this particularly scalable, but it shou
2424
####TODO
2525

2626
* migrate away from app engine mail (maybe?)
27-
* Make account pages better
27+
* make email template based.

handlers/site.py

+32-13
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,39 @@ class UserHandler(framework.BaseHandler):
3232
@authorized.role('user')
3333
def get(self, email):
3434
user = self.get_user()
35+
36+
# Update enabled state if requested
37+
set_enabled = self.request.get('setenabled')
38+
if set_enabled == '1':
39+
user.enabled = True
40+
user.put()
41+
elif set_enabled == '0':
42+
user.enabled = False
43+
user.put()
44+
45+
# Update tags if sent
46+
tags = self.request.get('tags')
47+
if tags:
48+
user.tags = [s.strip() for s in tags.split(',')]
49+
user.put()
50+
51+
3552
email = urllib.unquote_plus(email)
3653
desired_user = user_from_email(email)
3754
snippets = desired_user.snippet_set
3855
snippets = sorted(snippets, key=lambda s: s.date, reverse=True)
3956
following = email in user.following
4057
tags = [(t, t in user.tags_following) for t in desired_user.tags]
4158

59+
if user.email == desired_user.email:
60+
owner = True
61+
else:
62+
owner = False
63+
4264
template_values = {
4365
'current_user': user,
4466
'user': desired_user,
67+
'owner': owner,
4568
'snippets': snippets,
4669
'following': following,
4770
'tags': tags
@@ -73,6 +96,8 @@ class UnfollowHandler(framework.BaseHandler):
7396
@authorized.role('user')
7497
def get(self):
7598
user = self.get_user()
99+
100+
76101
desired_tag = self.request.get('tag')
77102
desired_user = self.request.get('user')
78103
continue_url = self.request.get('continue')
@@ -113,20 +138,7 @@ class MainHandler(framework.BaseHandler):
113138
@authorized.role('user')
114139
def get(self):
115140
user = self.get_user()
116-
# Update enabled state if requested
117-
set_enabled = self.request.get('setenabled')
118-
if set_enabled == '1':
119-
user.enabled = True
120-
user.put()
121-
elif set_enabled == '0':
122-
user.enabled = False
123-
user.put()
124141

125-
# Update tags if sent
126-
tags = self.request.get('tags')
127-
if tags:
128-
user.tags = [s.strip() for s in tags.split(',')]
129-
user.put()
130142

131143
# Fetch user list and display
132144
raw_users = User.all().order('email').fetch(500)
@@ -137,7 +149,14 @@ def get(self):
137149
all_tags.update(u.tags)
138150
all_tags = [(t, t in user.tags_following) for t in all_tags]
139151

152+
d = date_for_retrieval()
153+
all_snippets = Snippet.all().filter("date =", d).fetch(500)
154+
logging.info(all_snippets)
155+
followed_snippets = [s for s in all_snippets if s.user.email in following]
156+
140157
template_values = {
158+
'followed_snippets':followed_snippets,
159+
'retrieval_date':d,
141160
'current_user': user,
142161
'all_users': all_users,
143162
'all_tags': all_tags

index.yaml

100755100644
File mode changed.

main.py

100755100644
File mode changed.

templates/base.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
</p>
3838
<ul class="nav">
3939
<li><a href="/user/{{ current_user.email }}">Logged in as {{ current_user.pretty_name }}</a></li>
40-
<li>{% if current_user.enabled %}<a class="light" href="?setenabled=0">click to disable</a>{% else %}<a class="light" href="?setenabled=1">click to enable</a>{% endif %}</li>
41-
4240
</ul>
4341
</div><!--/.nav-collapse -->
4442
</div>
@@ -54,6 +52,13 @@
5452
</div>
5553
{% block body %}{% endblock %}
5654
</div>
55+
56+
<div id="footer">
57+
<div class="container">
58+
<hr>
59+
<p class="muted credit">Send your snippets to <a target="_blank" href="mailto:{{site_email}}">{{site_email}}</a> by monday afternoon! <a href="https://github.com/lunarcorp/snippets">fix bugs</a>.</p>
60+
</div>
61+
</div>
5762
</body>
5863
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
5964
</html>

templates/index.html

+22-14
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44
{% block body %}
55
<div class="row">
66
<div class="span12">
7-
<h2><a href="/user/{{ current_user.email }}">{{ current_user.pretty_name }}</a></h2>
7+
<h1>Welcome back, <a href="/user/{{ current_user.email }}">{{ current_user.pretty_name }}</a></h1>
88

9-
currently
10-
{% if current_user.enabled %}
11-
enabled (<a class="light" href="?setenabled=0">disable</a>)
12-
{% else %}
13-
disabled (<a class="light" href="?setenabled=1">enable</a>)
14-
{% endif %}
15-
<form action="/" method="get">
169

17-
my tags <input name="tags" type="text" value="{{ current_user.tags|join:"," }}"/></form>
1810

19-
</td></tr></table>
20-
<br/>
11+
Send your snippets to <a target="_blank" href="mailto:{{site_email}}">{{site_email}}</a> by monday afternoon!
12+
<br/><br/>
13+
</div>
14+
</div>
2115

22-
send your snippets to <a target="_blank" href="mailto:{{site_email}}">{{site_email}}</a> by monday afternoon!
23-
<br/><br/>
16+
{% if followed_snippets %}
17+
<div class="row">
18+
<div class="span12">
19+
<h2>Snippets for this week <small>({{retrieval_date}})</small></h2>
20+
{% for snippet in followed_snippets %}
21+
<b><a href="/user/{{ snippet.user.email }}">{{ snippet.user.pretty_name }}</a></b><br/>
22+
<pre>{{ snippet.text|urlize }}</pre>
23+
<br/>
24+
{% endfor %}
25+
</div>
26+
</div>
27+
{% else %}
28+
<h2>No followed snippets for this week <small>({{retrieval_date}})</small></h2>
29+
<p>Follow some people or tags or wait until next week.</p>
30+
{% endif %}
31+
<hr />
32+
<div class="row">
2433
<div class="span4">
2534

2635
<table class="table table-condensed table-striped table-hover table-bordered">
@@ -74,7 +83,6 @@ <h2><a href="/user/{{ current_user.email }}">{{ current_user.pretty_name }}</a><
7483
</div>
7584

7685
</div>
77-
</div>
7886

7987

8088
{% endblock %}

templates/tag.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<div class="row">
66
<div class="span12">
77

8-
<h1>{{ tag }}
8+
<h1>Snippets tagged '{{ tag }}'
99
<small>
1010

1111
{% if following %}
1212
<a class="light" href="/unfollow?tag={{ tag }}&continue=/tag/{{ tag }}">unfollow</a>
1313
{% else %}
1414
<a class="light" href="/follow?tag={{ tag }}&continue=/tag/{{ tag }}">follow</a>
1515
{% endif %}
16-
<small>
16+
</small>
1717
</h1>
1818

1919
</div>
@@ -23,9 +23,9 @@ <h1>{{ tag }}
2323
<div class="span12">
2424

2525
{% for snippet in snippets %}
26-
<b>{{ snippet.user.pretty_name }}</b><br/>
26+
<b><a href="/user/{{ snippet.user.email }}">{{ snippet.user.pretty_name }}</a></b><br/>
2727
<pre>{{ snippet.text|urlize }}</pre>
28-
<br/></br>
28+
<br/>
2929
{% endfor %}
3030
</div>
3131
</div>

templates/user.html

+31-13
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,49 @@
44
<div class="row">
55
<div class="span12">
66

7-
<h1>{{ user.email }} <small>{% if following %}
7+
<h2>Snippets for {{ user.email }} <small>{% if following %}
88
<a class="light" href="/unfollow?user={{ user.email }}&continue=/user/{{ user.email }}">unfollow</a>
99
{% else %}
1010
<a class="light" href="/follow?user={{ user.email }}&continue=/user/{{ user.email }}">follow</a>
11-
{% endif %}</small></h1>
11+
{% endif %}</small></h2>
1212

1313

1414
</div>
1515
</div>
16+
17+
{%if owner %}
1618
<div class="row">
17-
<div class="span2 pull-right well">
19+
<div class="span12">
20+
<b>This is you!</b> Currently
21+
{% if current_user.enabled %}
22+
enabled (<a class="light" href="?setenabled=0">disable</a>)
23+
{% else %}
24+
disabled (<a class="light" href="?setenabled=1">enable</a>)
25+
{% endif %}
26+
</div>
27+
</div>
28+
{% endif %}
29+
30+
<div class="row">
31+
<div class="span3 pull-right well">
1832
<b>Tags</b><br/>
19-
{% for tag in tags %}
20-
{{ tag.0 }}
21-
{% if tag.1 %}
22-
<a class="light" href="/unfollow?tag={{ tag.0 }}&continue=/user/{{ user.email }}">unfollow</a>
23-
{% else %}
24-
<a class="light" href="/follow?tag={{ tag.0 }}&continue=/user/{{ user.email }}">follow</a>
25-
{% endif %}
26-
<br/>
27-
{% endfor %}
33+
{%if not owner %}
34+
{% for tag in tags %}
35+
{{ tag.0 }}
36+
{% if tag.1 %}
37+
<a class="light" href="/unfollow?tag={{ tag.0 }}&continue=/user/{{ user.email }}">unfollow</a>
38+
{% else %}
39+
<a class="light" href="/follow?tag={{ tag.0 }}&continue=/user/{{ user.email }}">follow</a>
40+
{% endif %}
41+
<br/>
42+
{% endfor %}
43+
{% else %}
44+
<form method="get"><input name="tags" class="span2" type="text" placeholder="tag1, tag2" value="{{ current_user.tags|join:"," }}"/></form>
45+
{% endif %}
2846

2947
</div>
3048

31-
<div class="span10">
49+
<div class="span8">
3250
{% for snippet in snippets %}
3351
<b>{{ snippet.date }}</b><br/>
3452
<pre>{{ snippet.text|urlize }}</pre>

utilities/authorized.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def check_login(self, *args, **kwargs):
6262
self.error(403)
6363
else:
6464
logging.debug("User not logged in -- force login")
65-
return self.redirect(users.create_login_url(self.request.uri))
65+
return self.redirect(users.create_login_url())
6666
elif role == "user" or (role == "admin" and
6767
users.is_current_user_admin()):
6868
logging.debug("Role is %s so will allow handler", role)

0 commit comments

Comments
 (0)