Commits

edanm  committed e294241

Basic userpages working, starting to work on the blog posting page

  • Participants
  • Parent commits 5053f7c

Comments (0)

Files changed (5)

File stack2blog/stack2blogapp/static_media/style.css

  ***********************/
 #userpage_container h1 {
 	margin-top:40px;
+	color: #fe7a15;
+	font-size:30px;
 }
+
+#userpage_container h2 {
+	margin-top:20px;
+	font-size:24px;
+}
+
+#userpage_container .answers_table_header {
+	font-size:16px;
+	font-weight:bold;
+
+	border-top:1px solid black;
+	border-bottom:1px solid black;
+}
+
+#userpage_container .answer {
+	font-size:14px;
+	border-bottom:1px dotted black;
+	margin-top:10px;
+}
+
+#userpage_container .answer .votecount {
+	font-size:18px;
+}
+
+#userpage_container .answer .question_title {
+	font-size:16px;
+}
+
+#userpage_container .answer .question_body {
+
+}
+
+#userpage_container .published_answers_table_header {
+	margin-top:40px;
+
+}

File stack2blog/stack2blogapp/templates/answers.html

-<html>
-<head>
-	<title>Stack2Blog - Your answers</title>
-</head>
-<body>
-	Here is your list of {{ answers|length }} answers for user {{ userid }}
-	<h2>Published posts ({{ published_answers|length }}):</h2>
-	<table>
-		{% for answer in published_answers %}
-		<tr>
-			<td>{{ answer.id }}</td>
-			<td>{{ answer.title }}</td>
-			<td><form action="post"><input type="hidden" name="postid" value="{{ answer.id }}"/><input type="submit" value="post again"/></form></td>
-		</tr>
-		{% endfor %}
-	</table>
-	<h2>Unpublished posts ({{ unpublished_answers|length }}):</h2>
-	<table>
-		{% for answer in unpublished_answers %}
-		<tr>
-			<td>{{ answer.id }}</td>
-			<td>{{ answer.title }}</td>
-			<td><form action="post"><input type="hidden" name="postid" value="{{ answer.id }}"/><input type="submit" value="post"/></form></td>
-		</tr>
-		{% endfor %}
-	</table>
-</body>
-</html>

File stack2blog/stack2blogapp/templates/superpage.html

 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">
+
 <head>
 
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 			</div> <!-- class="wrap" -->
 		</div> <!-- id="logo" -->
 
+		<div class="clear"></div>
+
 	</div> <!-- id="header" -->
 
 	<div id="block_content">

File stack2blog/stack2blogapp/templates/userpage.html

 {% extends "superpage.html" %}
 
-{% block title %} User - Stack2Blog {% endblock %}
+{% block title %} {{so_user.display_name}}'s page - Stack2Blog {% endblock %}
 
 
 {% block head %}
 
 <div id="userpage_container" class="container_12">
 
-	<h1 class="grid_12" class="display_name"> {{so_user.display_name}} </h1>
+	<h1 class="grid_12" class="display_name"> Welcome {{so_user.display_name}} </h1>
+	<div class="clear"></div>
 
-	<h2>Published posts ({{ published_answers|length }}):</h2>
-	<table>
-		{% for answer in published_answers %}
-		<tr>
-			<td>{{ answer.id }}</td>
-			<td>{{ answer.title }}</td>
-			<td><form action="post"><input type="hidden" name="postid" value="{{ answer.id }}"/><input type="submit" value="post again"/></form></td>
-		</tr>
-		{% endfor %}
-	</table>
-	<h2>Unpublished posts ({{ unpublished_answers|length }}):</h2>
-	<table>
-		{% for answer in unpublished_answers %}
-		<tr>
-			<td>{{ answer.id }}</td>
-			<td>{{ answer.title }}</td>
-			<td><form action="post"><input type="hidden" name="postid" value="{{ answer.id }}"/><input type="submit" value="post"/></form></td>
-		</tr>
-		{% endfor %}
-	</table>
+
+	<!-- Unpublished answers -->
+	<h2 class="grid_12">Answers you haven't published yet ({{ unpublished_answers|length }}):</h2>
+	<div class="clear"></div>
+
+	<!-- The headers -->
+	<ul class="answers_table_header unpublished_answers_table_header">
+		<li class="grid_1">Votes</li>
+		<li class="grid_4">Question Title</li>
+		<li class="grid_2">Answer</li>
+		<div class="clear"></div>
+	</ul>
+
+	{% for answer in unpublished_answers %}
+		<div class="answer unposted_answer">
+			<div class="grid_1 votecount"> {{answer.score}} </div>
+			<div class="grid_4 question_title"> {{answer.title}} </div>
+			<div class="grid_4 question_body"> {{answer.body_blurb}} </div>
+
+			<div class="clear"></div>
+		</div>
+
+	{% endfor %}
+
+	<div class="clear"></div>
+
+
+	<!-- Published answers -->
+	<h2 class="grid_12">Answers you've already published ({{ published_answers|length }}):</h2>
+	<div class="clear"></div>
+
+	<!-- The headers -->
+	<ul class="answers_table_header published_answers_table_header">
+		<li class="grid_1">Votes</li>
+		<li class="grid_4">Question Title</li>
+		<li class="grid_2">Answer</li>
+		<div class="clear"></div>
+	</ul>
+
+	{% for answer in published_answers %}
+		<div class="answer unposted_answer">
+			<div class="grid_1" class="answer_votecount"> {{answer.score}} </div>
+			<div class="grid_4" class="answer_question_title"> {{answer.title}} </div>
+			<div class="grid_4" class="answer_question_body"> {{answer.body_blurb}} </div>
+
+			<div class="clear"></div>
+		</div>
+
+	{% endfor %}
+
+	<div class="clear"></div>
 
 </div>
 

File stack2blog/stack2blogapp/views.py

 from django.template import RequestContext
 from models import *
 import stackexchange
+import types
+import pdb
 
 
 # Create your views here.
 	return HttpResponseRedirect("/userpage/" + str(userid))
 
 
+def blurbifyAnswer(answer_obj):
+	'''
+	Given a StackExchange answer object, adds a method called "body_blurb" to it
+	which gives back a blurb of the answer suitable for concise display on our site.
+	'''
+	def body_blurb(self):
+		return self.body[:100]
+
+	meth = types.MethodType(body_blurb, answer_obj, stackexchange.Answer)
+	answer_obj.body_blurb = meth
+	return answer_obj
 
 def userpage(request, userid):
 	try:
 		request.session["so_userid"] = userid
 
 		site = stackexchange.Site(stackexchange.StackOverflow, app_key = "SL5xzbpFYUCSae3tqVlL7A")
+		site.be_inclusive()
 		so_user = site.user(userid)
-		# print dir(so_user)
 
 		answers = []
 		more_answers = so_user.answers.fetch()
 		# request.session["so_answers"] = answers
 
 	# Figure out what's published and unpublished.
-	published_answers = [answer for answer in answers if PublishedPost.objects.filter(postid = answer.id).count() > 0]
-	unpublished_answers = [answer for answer in answers if PublishedPost.objects.filter(postid = answer.id).count() == 0]
+	published_answers = [blurbifyAnswer(answer) for answer in answers if PublishedPost.objects.filter(postid = answer.id).count() > 0]
+	unpublished_answers = [blurbifyAnswer(answer) for answer in answers if PublishedPost.objects.filter(postid = answer.id).count() == 0]
 
 	return render_to_response('userpage.html', locals(), context_instance=RequestContext(request))