summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <fitoria@fitoria-laptop.(none)>2009-10-13 10:54:45 -0600
committerAdolfo Fitoria <fitoria@fitoria-laptop.(none)>2009-10-13 11:04:05 -0600
commit3f42d059adaa0ae6813dc32a10e32b8ddd99d31e (patch)
treed614b7b5c951073ce69236de6e8319aa119bad13
parentd0702a245f2dba0fc3ea37047a19498f52b6c93d (diff)
parent6214863f362fd0702af79abaade0de6736d12e96 (diff)
downloadaskbot-3f42d059adaa0ae6813dc32a10e32b8ddd99d31e.tar.gz
askbot-3f42d059adaa0ae6813dc32a10e32b8ddd99d31e.tar.bz2
askbot-3f42d059adaa0ae6813dc32a10e32b8ddd99d31e.zip
Merge branch 'master' of git://github.com/cnprog/CNPROG into chinito/master
Conflicts: forum/models.py forum/views.py settings.py settings_local.py.dist
-rw-r--r--.gitignore1
-rw-r--r--LICENSE28
-rw-r--r--TODO4
-rw-r--r--cnprog.wsgi8
-rw-r--r--drop-all-tables.sh4
-rw-r--r--forum/managers.py17
-rw-r--r--forum/models.py19
-rw-r--r--forum/views.py1713
-rw-r--r--rmpyc1
-rw-r--r--settings.py7
-rw-r--r--settings_local.py.dist27
-rw-r--r--sql_scripts/update_2009_01_25_001.sql2
-rw-r--r--sql_scripts/update_2009_02_26_001.sql36
-rw-r--r--sql_scripts/update_2009_04_10_001.sql4
-rw-r--r--templates/content/js/compress.bat10
-rw-r--r--templates/content/js/flot-build.bat4
-rw-r--r--templates/content/style/style.css1
17 files changed, 953 insertions, 933 deletions
diff --git a/.gitignore b/.gitignore
index b217d5cc..b929b531 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
*.log
settings_local.py
nbproject
+settings_local.py
diff --git a/LICENSE b/LICENSE
index cb24f678..803781c5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,14 +1,14 @@
-Copyright (C) 2009. Chen Gang
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
+Copyright (C) 2009. Chen Gang
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/TODO b/TODO
deleted file mode 100644
index 3769fa08..00000000
--- a/TODO
+++ /dev/null
@@ -1,4 +0,0 @@
-*check change email function - there is a strange 'password' field in form
-*make reusable question-block template for index questions unanswered - get rid of copy-paste
-*unused votes count in user profile not working - left that commented out in templates/user_info.html
-*badge award notification messages need to be set fixed at place where badges are awarded
diff --git a/cnprog.wsgi b/cnprog.wsgi
deleted file mode 100644
index a1bd8039..00000000
--- a/cnprog.wsgi
+++ /dev/null
@@ -1,8 +0,0 @@
-import os
-import sys
-
-sys.path.append('/var/www/vhosts')
-os.environ['DJANGO_SETTINGS_MODULE'] = 'cnprog.settings'
-
-import django.core.handlers.wsgi
-application = django.core.handlers.wsgi.WSGIHandler()
diff --git a/drop-all-tables.sh b/drop-all-tables.sh
deleted file mode 100644
index 87783b77..00000000
--- a/drop-all-tables.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-mysql_username='cnprog'
-mysql_database='cnprog'
-mysqldump -u $mysql_username -p --add-drop-table --no-data $mysql_database | grep ^DROP
-#| mysql -u[USERNAME] -p[PASSWORD] [DATABASE]
diff --git a/forum/managers.py b/forum/managers.py
index 6e536af9..e05aed53 100644
--- a/forum/managers.py
+++ b/forum/managers.py
@@ -169,17 +169,22 @@ class TagManager(models.Manager):
class AnswerManager(models.Manager):
GET_ANSWERS_FROM_USER_QUESTIONS = u'SELECT answer.* FROM answer INNER JOIN question ON answer.question_id = question.id WHERE question.author_id =%s AND answer.author_id <> %s'
- def get_answers_from_question(self, question, user=None):
+ def get_answers_from_question(self, question, user=None, other_orderby = None):
"""
Retrieves visibile answers for the given question. Delete answers
are only visibile to the person who deleted them.
- """
-
+ """
if user is None or not user.is_authenticated():
- return self.filter(question=question, deleted=False)
+ q = self.filter(question=question, deleted=False)
+ else:
+ q = self.filter(Q(question=question),
+ Q(deleted=False) | Q(deleted_by=user))
+ if other_orderby is None:
+ q = q.order_by("-accepted")
else:
- return self.filter(Q(question=question),
- Q(deleted=False) | Q(deleted_by=user))
+ q = q.order_by("-accepted", other_orderby)
+
+ return q
def get_answers_from_questions(self, user_id):
"""
diff --git a/forum/models.py b/forum/models.py
index e8b4a77d..f07d2879 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -3,6 +3,7 @@ import datetime
import hashlib
from urllib import quote_plus, urlencode
from django.db import models
+from django.utils.http import urlquote as django_urlquote
from django.utils.html import strip_tags
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
@@ -193,7 +194,7 @@ class Question(models.Model):
return u','.join([unicode(tag) for tag in self.tagname_list()])
def get_absolute_url(self):
- return '%s%s' % (reverse('question', args=[self.id]), slugify(self.title))
+ return '%s%s' % (reverse('question', args=[self.id]), django_urlquote(self.title.replace(' ', '-')))
def has_favorite_by_user(self, user):
if not user.is_authenticated():
@@ -221,7 +222,17 @@ class Question(models.Model):
def get_latest_revision(self):
return self.revisions.all()[0]
-
+
+ def get_user_votes_in_answers(self, user):
+ content_type = ContentType.objects.get_for_model(Answer)
+ query_set = Vote.objects.extra(
+ tables = ['question', 'answer'],
+ where = ['question.id = answer.question_id AND question.id = %s AND vote.object_id = answer.id AND vote.content_type_id = %s AND vote.user_id = %s'],
+ params = [self.id, content_type.id, user.id]
+ )
+
+ return query_set
+
def get_update_summary(self,last_reported_at=None,recipient_email=''):
edited = False
if self.last_edited_at and self.last_edited_at > last_reported_at:
@@ -407,7 +418,7 @@ class Answer(models.Model):
return self.question.title
def get_absolute_url(self):
- return '%s%s#%s' % (reverse('question', args=[self.question.id]), self.question.title, self.id)
+ return '%s%s#%s' % (reverse('question', args=[self.question.id]), django_urlquote(self.question.title), self.id)
class Meta:
db_table = u'answer'
@@ -548,7 +559,7 @@ class Book(models.Model):
questions = models.ManyToManyField(Question, related_name='book', db_table='book_question')
def get_absolute_url(self):
- return '%s' % reverse('book', args=[self.short_name])
+ return '%s' % reverse('book', args=[django_urlquote(self.short_name)])
def __unicode__(self):
return self.title
diff --git a/forum/views.py b/forum/views.py
index 20406536..9a974114 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -1,33 +1,35 @@
# encoding:utf-8
-import os.path
-import time, datetime, calendar, random
-import logging
-from urllib import quote, unquote
+import calendar
from django.conf import settings
-from django.core.files.storage import default_storage
-from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
-from django.http import HttpResponseRedirect, HttpResponse,Http404
-from django.core.paginator import Paginator, EmptyPage, InvalidPage
+from django.contrib.contenttypes.models import ContentType
+from django.core.files.storage import default_storage
+from django.core.paginator import EmptyPage
+from django.core.paginator import InvalidPage
+from django.core.paginator import Paginator
+from django.http import Http404
+from django.http import HttpResponse
+from django.http import HttpResponseRedirect
+from django.shortcuts import get_object_or_404
+from django.shortcuts import render_to_response
from django.template import RequestContext
-from django.utils.html import *
from django.utils import simplejson
-from django.core import serializers
-from django.db import transaction
-from django.contrib.contenttypes.models import ContentType
+from django.utils.html import *
from django.utils.translation import ugettext as _
-from django.template.defaultfilters import slugify
-
-from utils.html import sanitize_html
from markdown2 import Markdown
-#from lxml.html.diff import htmldiff
+import os.path
+import random
+import time
+
+import datetime
+from forum import auth
+from forum.auth import *
+from forum.const import *
from forum.diff import textDiff as htmldiff
from forum.forms import *
from forum.models import *
-from forum.auth import *
-from forum.const import *
from forum.user import *
-from forum import auth
+from utils.html import sanitize_html
# used in index page
INDEX_PAGE_SIZE = 20
@@ -47,7 +49,7 @@ answer_type = ContentType.objects.get_for_model(Answer)
comment_type = ContentType.objects.get_for_model(Comment)
question_revision_type = ContentType.objects.get_for_model(QuestionRevision)
answer_revision_type = ContentType.objects.get_for_model(AnswerRevision)
-repute_type =ContentType.objects.get_for_model(Repute)
+repute_type = ContentType.objects.get_for_model(Repute)
question_type_id = question_type.id
answer_type_id = answer_type.id
comment_type_id = comment_type.id
@@ -58,7 +60,7 @@ def _get_tags_cache_json():
tags = Tag.objects.filter(deleted=False).all()
tags_list = []
for tag in tags:
- dic = {'n': tag.name, 'c': tag.used_count }
+ dic = {'n': tag.name, 'c': tag.used_count}
tags_list.append(dic)
tags = simplejson.dumps(tags_list)
return tags
@@ -66,11 +68,11 @@ def _get_tags_cache_json():
def index(request):
view_id = request.GET.get('sort', None)
view_dic = {
- "latest":"-added_at",
- "hottest":"-answer_count",
- "mostvoted":"-score",
- "active": "-last_activity_at"
- }
+ "latest":"-last_activity_at",
+ "hottest":"-answer_count",
+ "mostvoted":"-score",
+ "trans": "-last_activity_at"
+ }
try:
orderby = view_dic[view_id]
except KeyError:
@@ -88,11 +90,11 @@ def index(request):
awards = Award.objects.get_recent_awards()
return render_to_response('index.html', {
- "questions" : questions,
- "tab_id" : view_id,
- "tags" : tags,
- "awards" : awards[:INDEX_AWARD_SIZE],
- }, context_instance=RequestContext(request))
+ "questions": questions,
+ "tab_id": view_id,
+ "tags": tags,
+ "awards": awards[:INDEX_AWARD_SIZE],
+ }, context_instance=RequestContext(request))
def about(request):
return render_to_response('about.html', context_instance=RequestContext(request))
@@ -113,17 +115,15 @@ def questions(request, tagname=None, categoryname=None, unanswered=False):
# template file
# "questions.html" or "unanswered.html"
template_file = "questions.html"
- # Set flag to False by default. If it is equal to True, then need to be saved.
- pagesize_changed = False
# get pagesize from session, if failed then get default value
- pagesize = request.session.get("pagesize",10)
+ pagesize = request.session.get("pagesize", 10)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
view_id = request.GET.get('sort', None)
- view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score" }
+ view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score"}
try:
orderby = view_dic[view_id]
except KeyError:
@@ -153,38 +153,38 @@ def questions(request, tagname=None, categoryname=None, unanswered=False):
else:
related_tags = None
return render_to_response(template_file, {
- "questions" : questions,
- "tab_id" : view_id,
- "questions_count" : objects_list.count,
- "tags" : related_tags,
- "searchtag" : tagname,
- "is_unanswered" : unanswered,
- "context" : {
- 'is_paginated' : True,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': questions.has_previous(),
- 'has_next': questions.has_next(),
- 'previous': questions.previous_page_number(),
- 'next': questions.next_page_number(),
- 'base_url' : request.path + '?sort=%s&' % view_id,
- 'pagesize' : pagesize
- }}, context_instance=RequestContext(request))
-
-def create_new_answer( question=None, author=None,\
- added_at=None, wiki=False,\
- text='', email_notify=False):
+ "questions": questions,
+ "tab_id": view_id,
+ "questions_count": objects_list.count,
+ "tags": related_tags,
+ "searchtag": tagname,
+ "is_unanswered": unanswered,
+ "context": {
+ 'is_paginated': True,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': questions.has_previous(),
+ 'has_next': questions.has_next(),
+ 'previous': questions.previous_page_number(),
+ 'next': questions.next_page_number(),
+ 'base_url': request.path + '?sort=%s&' % view_id,
+ 'pagesize': pagesize
+ }}, context_instance=RequestContext(request))
+
+def create_new_answer(question=None, author=None, \
+ added_at=None, wiki=False, \
+ text='', email_notify=False):
html = sanitize_html(markdowner.convert(text))
#create answer
answer = Answer(
- question = question,
- author = author,
- added_at = added_at,
- wiki = wiki,
- html = html
- )
+ question=question,
+ author=author,
+ added_at=added_at,
+ wiki=wiki,
+ html=html
+ )
if answer.wiki:
answer.last_edited_by = answer.author
answer.last_edited_at = added_at
@@ -200,48 +200,47 @@ def create_new_answer( question=None, author=None,\
#update revision
AnswerRevision.objects.create(
- answer = answer,
- revision = 1,
- author = author,
- revised_at = added_at,
- summary = CONST['default_version'],
- text = text
- )
+ answer=answer,
+ revision=1,
+ author=author,
+ revised_at=added_at,
+ summary=CONST['default_version'],
+ text=text
+ )
#set notification/delete
if email_notify:
try:
- EmailFeed.objects.get(feed_id = question.id, subscriber_id = author.id, feed_content_type=question_type)
+ EmailFeed.objects.get(feed_id=question.id, subscriber_id=author.id, feed_content_type=question_type)
except EmailFeed.DoesNotExist:
- feed = EmailFeed(content = question, subscriber = author)
+ feed = EmailFeed(content=question, subscriber=author)
feed.save()
else:
#not sure if this is necessary. ajax should take care of this...
try:
- feed = Email.objects.get(feed_id = question.id, subscriber_id = author.id, feed_content_type=question_type)
+ feed = Email.objects.get(feed_id=question.id, subscriber_id=author.id, feed_content_type=question_type)
feed.delete()
except:
pass
-def create_new_question(title=None,author=None,added_at=None,
- wiki=False,tagnames=None,summary=None,
- text=None, category=None):
+def create_new_question(title=None, author=None, added_at=None,
+ wiki=False, tagnames=None, summary=None,
+ text=None):
"""this is not a view
and maybe should become one of the methods on Question object?
"""
html = sanitize_html(markdowner.convert(text))
question = Question(
- title = title,
- author = author,
- added_at = added_at,
- last_activity_at = added_at,
- last_activity_by = author,
- wiki = wiki,
- tagnames = tagnames,
- html = html,
- summary = summary,
- category = category
- )
+ title=title,
+ author=author,
+ added_at=added_at,
+ last_activity_at=added_at,
+ last_activity_by=author,
+ wiki=wiki,
+ tagnames=tagnames,
+ html=html,
+ summary=summary
+ )
if question.wiki:
question.last_edited_by = question.author
question.last_edited_at = added_at
@@ -251,15 +250,15 @@ def create_new_question(title=None,author=None,added_at=None,
# create the first revision
QuestionRevision.objects.create(
- question = question,
- revision = 1,
- title = question.title,
- author = author,
- revised_at = added_at,
- tagnames = question.tagnames,
- summary = CONST['default_version'],
- text = text
- )
+ question=question,
+ revision=1,
+ title=question.title,
+ author=author,
+ revised_at=added_at,
+ tagnames=question.tagnames,
+ summary=CONST['default_version'],
+ text=text
+ )
return question
#TODO: allow anynomus user to ask question by providing email and username.
@@ -270,7 +269,7 @@ def ask(request):
if form.is_valid():
added_at = datetime.datetime.now()
- title = strip_tags(form.cleaned_data['title'])
+ title = strip_tags(form.cleaned_data['title']).strip()
wiki = form.cleaned_data['wiki']
tagnames = form.cleaned_data['tags'].strip()
text = form.cleaned_data['text']
@@ -282,40 +281,38 @@ def ask(request):
author = request.user
question = create_new_question(
- title = title,
- author = author,
- added_at = added_at,
- wiki = wiki,
- tagnames = tagnames,
- summary = summary,
- text = text,
- category = category
- )
-
+ title=title,
+ author=author,
+ added_at=added_at,
+ wiki=wiki,
+ tagnames=tagnames,
+ summary=summary,
+ text=text
+ )
return HttpResponseRedirect(question.get_absolute_url())
else:
request.session.flush()
session_key = request.session.session_key
question = AnonymousQuestion(
- session_key = session_key,
- title = title,
- tagnames = tagnames,
- wiki = wiki,
- text = text,
- summary = summary,
- added_at = added_at,
- ip_addr = request.META['REMOTE_ADDR'],
- )
+ session_key=session_key,
+ title=title,
+ tagnames=tagnames,
+ wiki=wiki,
+ text=text,
+ summary=summary,
+ added_at=added_at,
+ ip_addr=request.META['REMOTE_ADDR'],
+ )
question.save()
- return HttpResponseRedirect('/%s%s%s' % ( _('account/'),_('signin/'),_('newquestion/')))
+ return HttpResponseRedirect('%s%s%s' % (_('/account/'), _('signin/'), ('newquestion/')))
else:
form = AskForm()
tags = _get_tags_cache_json()
return render_to_response('ask.html', {
- 'form' : form,
- 'tags' : tags,
- }, context_instance=RequestContext(request))
+ 'form': form,
+ 'tags': tags,
+ }, context_instance=RequestContext(request))
def question(request, id):
try:
@@ -323,7 +320,7 @@ def question(request, id):
except ValueError:
page = 1
view_id = request.GET.get('sort', 'votes')
- view_dic = {"latest":"-added_at", "oldest":"added_at", "votes":"-score" }
+ view_dic = {"latest":"-added_at", "oldest":"added_at", "votes":"-score"}
try:
orderby = view_dic[view_id]
except KeyError:
@@ -333,8 +330,8 @@ def question(request, id):
question = get_object_or_404(Question, id=id)
if question.deleted and not can_view_deleted_post(request.user, question):
raise Http404
- answer_form = AnswerForm(question,request.user)
- answers = Answer.objects.get_answers_from_question(question, request.user)
+ answer_form = AnswerForm(question, request.user)
+ answers = Answer.objects.get_answers_from_question(question, request.user, orderby)
answers = answers.select_related(depth=1)
favorited = question.has_favorite_by_user(request.user)
@@ -346,18 +343,13 @@ def question(request, id):
question_vote = question_vote[0]
user_answer_votes = {}
- for answer in answers:
- vote = answer.get_user_vote(request.user)
- if vote is not None and not user_answer_votes.has_key(answer.id):
+ for vote in question.get_user_votes_in_answers(request.user):
+ if not user_answer_votes.has_key(vote.object_id):
vote_value = -1
if vote.is_upvote():
vote_value = 1
- user_answer_votes[answer.id] = vote_value
-
-
- if answers is not None:
- answers = answers.order_by("-accepted", orderby)
-
+ user_answer_votes[vote.object_id] = vote_value
+
filtered_answers = []
for answer in answers:
if answer.deleted == True:
@@ -371,28 +363,28 @@ def question(request, id):
# update view count
Question.objects.update_view_count(question)
return render_to_response('question.html', {
- "question" : question,
- "question_vote" : question_vote,
- "question_comment_count":question.comments.count(),
- "answer" : answer_form,
- "answers" : page_objects.object_list,
- "user_answer_votes": user_answer_votes,
- "tags" : question.tags.all(),
- "tab_id" : view_id,
- "favorited" : favorited,
- "similar_questions" : Question.objects.get_similar_questions(question),
- "context" : {
- 'is_paginated' : True,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': page_objects.has_previous(),
- 'has_next': page_objects.has_next(),
- 'previous': page_objects.previous_page_number(),
- 'next': page_objects.next_page_number(),
- 'base_url' : request.path + '?sort=%s&' % view_id,
- 'extend_url' : "#sort-top"
- }
- }, context_instance=RequestContext(request))
+ "question": question,
+ "question_vote": question_vote,
+ "question_comment_count":question.comments.count(),
+ "answer": answer_form,
+ "answers": page_objects.object_list,
+ "user_answer_votes": user_answer_votes,
+ "tags": question.tags.all(),
+ "tab_id": view_id,
+ "favorited": favorited,
+ "similar_questions": Question.objects.get_similar_questions(question),
+ "context": {
+ 'is_paginated': True,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': page_objects.has_previous(),
+ 'has_next': page_objects.has_next(),
+ 'previous': page_objects.previous_page_number(),
+ 'next': page_objects.next_page_number(),
+ 'base_url': request.path + '?sort=%s&' % view_id,
+ 'extend_url': "#sort-top"
+ }
+ }, context_instance=RequestContext(request))
@login_required
def close(request, id):
@@ -412,9 +404,9 @@ def close(request, id):
else:
form = CloseForm()
return render_to_response('close.html', {
- 'form' : form,
- 'question' : question,
- }, context_instance=RequestContext(request))
+ 'form': form,
+ 'question': question,
+ }, context_instance=RequestContext(request))
@login_required
def reopen(request, id):
@@ -422,14 +414,14 @@ def reopen(request, id):
# open question
if not can_reopen_question(request.user, question):
return HttpResponse('Permission denied.')
- if request.method == 'POST' :
+ if request.method == 'POST':
Question.objects.filter(id=question.id).update(closed=False,
- closed_by=None, closed_at=None, close_reason=None)
+ closed_by=None, closed_at=None, close_reason=None)
return HttpResponseRedirect(question.get_absolute_url())
else:
return render_to_response('reopen.html', {
- 'question' : question,
- }, context_instance=RequestContext(request))
+ 'question': question,
+ }, context_instance=RequestContext(request))
@login_required
def edit_question(request, id):
@@ -452,25 +444,25 @@ def _retag_question(request, question):
retagged_at = datetime.datetime.now()
# Update the Question itself
Question.objects.filter(id=question.id).update(
- tagnames = form.cleaned_data['tags'],
- last_edited_at = retagged_at,
- last_edited_by = request.user,
- last_activity_at = retagged_at,
- last_activity_by = request.user
- )
+ tagnames=form.cleaned_data['tags'],
+ last_edited_at=retagged_at,
+ last_edited_by=request.user,
+ last_activity_at=retagged_at,
+ last_activity_by=request.user
+ )
# Update the Question's tag associations
tags_updated = Question.objects.update_tags(question,
- form.cleaned_data['tags'], request.user)
+ form.cleaned_data['tags'], request.user)
# Create a new revision
QuestionRevision.objects.create(
- question = question,
- title = latest_revision.title,
- author = request.user,
- revised_at = retagged_at,
- tagnames = form.cleaned_data['tags'],
- summary = CONST['retagged'],
- text = latest_revision.text
- )
+ question=question,
+ title=latest_revision.title,
+ author=request.user,
+ revised_at=retagged_at,
+ tagnames=form.cleaned_data['tags'],
+ summary=CONST['retagged'],
+ text=latest_revision.text
+ )
# send tags updated singal
tags_updated.send(sender=question.__class__, question=question)
@@ -478,10 +470,10 @@ def _retag_question(request, question):
else:
form = RetagQuestionForm(question)
return render_to_response('question_retag.html', {
- 'question': question,
- 'form' : form,
- 'tags' : _get_tags_cache_json(),
- }, context_instance=RequestContext(request))
+ 'question': question,
+ 'form': form,
+ 'tags': _get_tags_cache_json(),
+ }, context_instance=RequestContext(request))
def _edit_question(request, question):
@@ -494,8 +486,8 @@ def _edit_question(request, question):
if revision_form.is_valid():
# Replace with those from the selected revision
form = EditQuestionForm(question,
- QuestionRevision.objects.get(question=question,
- revision=revision_form.cleaned_data['revision']))
+ QuestionRevision.objects.get(question=question,
+ revision=revision_form.cleaned_data['revision']))
else:
form = EditQuestionForm(question, latest_revision, request.POST)
else:
@@ -530,20 +522,20 @@ def _edit_question(request, question):
updated_fields['wikified_at'] = edited_at
Question.objects.filter(
- id=question.id).update(**updated_fields)
+ id=question.id).update(** updated_fields)
# Update the Question's tag associations
if tags_changed:
tags_updated = Question.objects.update_tags(
- question, form.cleaned_data['tags'], request.user)
+ question, form.cleaned_data['tags'], request.user)
# Create a new revision
revision = QuestionRevision(
- question = question,
- title = form.cleaned_data['title'],
- author = request.user,
- revised_at = edited_at,
- tagnames = form.cleaned_data['tags'],
- text = form.cleaned_data['text'],
- )
+ question=question,
+ title=form.cleaned_data['title'],
+ author=request.user,
+ revised_at=edited_at,
+ tagnames=form.cleaned_data['tags'],
+ text=form.cleaned_data['text'],
+ )
if form.cleaned_data['summary']:
revision.summary = form.cleaned_data['summary']
else:
@@ -556,11 +548,11 @@ def _edit_question(request, question):
revision_form = RevisionForm(question, latest_revision)
form = EditQuestionForm(question, latest_revision)
return render_to_response('question_edit.html', {
- 'question': question,
- 'revision_form': revision_form,
- 'form' : form,
- 'tags' : _get_tags_cache_json()
- }, context_instance=RequestContext(request))
+ 'question': question,
+ 'revision_form': revision_form,
+ 'form': form,
+ 'tags': _get_tags_cache_json()
+ }, context_instance=RequestContext(request))
@login_required
@@ -579,8 +571,8 @@ def edit_answer(request, id):
if revision_form.is_valid():
# Replace with those from the selected revision
form = EditAnswerForm(answer,
- AnswerRevision.objects.get(answer=answer,
- revision=revision_form.cleaned_data['revision']))
+ AnswerRevision.objects.get(answer=answer,
+ revision=revision_form.cleaned_data['revision']))
else:
form = EditAnswerForm(answer, latest_revision, request.POST)
else:
@@ -594,14 +586,14 @@ def edit_answer(request, id):
'last_edited_by': request.user,
'html': html,
}
- Answer.objects.filter(id=answer.id).update(**updated_fields)
+ Answer.objects.filter(id=answer.id).update(** updated_fields)
revision = AnswerRevision(
- answer = answer,
- author = request.user,
- revised_at = edited_at,
- text = form.cleaned_data['text']
- )
+ answer=answer,
+ author=request.user,
+ revised_at=edited_at,
+ text=form.cleaned_data['text']
+ )
if form.cleaned_data['summary']:
revision.summary = form.cleaned_data['summary']
@@ -618,14 +610,14 @@ def edit_answer(request, id):
revision_form = RevisionForm(answer, latest_revision)
form = EditAnswerForm(answer, latest_revision)
return render_to_response('answer_edit.html', {
- 'answer': answer,
- 'revision_form': revision_form,
- 'form' : form,
- }, context_instance=RequestContext(request))
+ 'answer': answer,
+ 'revision_form': revision_form,
+ 'form': form,
+ }, context_instance=RequestContext(request))
QUESTION_REVISION_TEMPLATE = ('<h1>%(title)s</h1>\n'
- '<div class="text">%(html)s</div>\n'
- '<div class="tags">%(tags)s</div>')
+ '<div class="text">%(html)s</div>\n'
+ '<div class="tags">%(tags)s</div>')
def question_revisions(request, id):
post = get_object_or_404(Question, id=id)
revisions = list(post.revisions.all())
@@ -634,7 +626,7 @@ def question_revisions(request, id):
'title': revision.title,
'html': sanitize_html(markdowner.convert(revision.text)),
'tags': ' '.join(['<a class="post-tag">%s</a>' % tag
- for tag in revision.tagnames.split(' ')]),
+ for tag in revision.tagnames.split(' ')]),
}
if i > 0:
revisions[i - 1].diff = htmldiff(revision.html,
@@ -644,13 +636,13 @@ def question_revisions(request, id):
'title': revisions[0].title,
'html': sanitize_html(markdowner.convert(revisions[0].text)),
'tags': ' '.join(['<a class="post-tag">%s</a>' % tag
- for tag in revisions[0].tagnames.split(' ')]),
+ for tag in revisions[0].tagnames.split(' ')]),
}
revisions[i - 1].summary = None
return render_to_response('revisions_question.html', {
- 'post': post,
- 'revisions': revisions,
- }, context_instance=RequestContext(request))
+ 'post': post,
+ 'revisions': revisions,
+ }, context_instance=RequestContext(request))
ANSWER_REVISION_TEMPLATE = ('<div class="text">%(html)s</div>')
def answer_revisions(request, id):
@@ -667,9 +659,9 @@ def answer_revisions(request, id):
revisions[i - 1].diff = revisions[i-1].text
revisions[i - 1].summary = None
return render_to_response('revisions_answer.html', {
- 'post': post,
- 'revisions': revisions,
- }, context_instance=RequestContext(request))
+ 'post': post,
+ 'revisions': revisions,
+ }, context_instance=RequestContext(request))
@login_required
def answer(request, id):
@@ -683,25 +675,25 @@ def answer(request, id):
if request.user.is_authenticated():
create_new_answer(
- question=question,
- author=request.user,
- added_at=update_time,
- wiki=wiki,
- text=text,
- email_notify=form.cleaned_data['email_notify']
- )
+ question=question,
+ author=request.user,
+ added_at=update_time,
+ wiki=wiki,
+ text=text,
+ email_notify=form.cleaned_data['email_notify']
+ )
else:
request.session.flush()
html = sanitize_html(markdowner.convert(text))
summary = strip_tags(html)[:120]
anon = AnonymousAnswer(
- question = question,
- wiki = wiki,
- text = text,
- summary = summary,
- session_key = request.session.session_key,
- ip_addr = request.META['REMOTE_ADDR'],
- )
+ question=question,
+ wiki=wiki,
+ text=text,
+ summary=summary,
+ session_key=request.session.session_key,
+ ip_addr=request.META['REMOTE_ADDR'],
+ )
anon.save()
return HttpResponseRedirect('/%s%s%s%s' % ( _('account/'),
_('signin/'),'?next=', question.get_absolute_url()))
@@ -719,36 +711,36 @@ def tags(request):
if request.method == "GET":
stag = request.GET.get("q", "").strip()
- if stag is not None:
+ if len(stag) > 0:
objects_list = Paginator(Tag.objects.filter(deleted=False).exclude(used_count=0).extra(where=['name like %s'], params=['%' + stag + '%']), DEFAULT_PAGE_SIZE)
else:
- if sortby == "name":
- objects_list = Paginator(Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("name"), DEFAULT_PAGE_SIZE)
+ if sortby == "used":
+ sortby = "-used_count"
else:
- objects_list = Paginator(Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("-used_count"), DEFAULT_PAGE_SIZE)
-
+ sortby = "name"
+ objects_list = Paginator(Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by(sortby), DEFAULT_PAGE_SIZE)
try:
tags = objects_list.page(page)
except (EmptyPage, InvalidPage):
tags = objects_list.page(objects_list.num_pages)
return render_to_response('tags.html', {
- "tags" : tags,
- "stag" : stag,
- "tab_id" : sortby,
- "keywords" : stag,
- "context" : {
- 'is_paginated' : is_paginated,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': tags.has_previous(),
- 'has_next': tags.has_next(),
- 'previous': tags.previous_page_number(),
- 'next': tags.next_page_number(),
- 'base_url' : '/%s?sort=%s&' % (_('tags/'), sortby)
- }
-
- }, context_instance=RequestContext(request))
+ "tags": tags,
+ "stag": stag,
+ "tab_id": sortby,
+ "keywords": stag,
+ "context": {
+ 'is_paginated': is_paginated,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': tags.has_previous(),
+ 'has_next': tags.has_next(),
+ 'previous': tags.previous_page_number(),
+ 'next': tags.next_page_number(),
+ 'base_url': '/tags/?sort=%s&' % sortby
+ }
+
+ }, context_instance=RequestContext(request))
def tag(request, tag):
return questions(request, tagname=tag)
@@ -828,9 +820,9 @@ def vote(request, id):
response_data = {
"allowed": 1,
"success": 1,
- "status" : 0,
- "count" : 0,
- "message" : ''
+ "status": 0,
+ "count": 0,
+ "message": ''
}
def can_vote(vote_score, user):
@@ -981,9 +973,9 @@ def vote(request, id):
user = request.user
if user.is_authenticated():
try:
- EmailFeed.objects.get(feed_id=question.id,subscriber_id=user.id,feed_content_type=question_type)
+ EmailFeed.objects.get(feed_id=question.id, subscriber_id=user.id, feed_content_type=question_type)
except EmailFeed.DoesNotExist:
- feed = EmailFeed(subscriber=user,content=question)
+ feed = EmailFeed(subscriber=user, content=question)
feed.save()
if settings.EMAIL_VALIDATION == 'on' and user.email_isvalid == False:
response_data['message'] = _('subscription saved, %(email)s needs validation') % {'email':user.email}
@@ -997,7 +989,7 @@ def vote(request, id):
user = request.user
if user.is_authenticated():
try:
- feed = EmailFeed.objects.get(feed_id=question.id,subscriber_id=user.id)
+ feed = EmailFeed.objects.get(feed_id=question.id, subscriber_id=user.id)
feed.delete()
except EmailFeed.DoesNotExist:
pass
@@ -1016,7 +1008,7 @@ def vote(request, id):
def users(request):
is_paginated = True
sortby = request.GET.get('sort', 'reputation')
- suser = request.REQUEST.get('q', "")
+ suser = request.REQUEST.get('q', "")
try:
page = int(request.GET.get('page', '1'))
except ValueError:
@@ -1044,22 +1036,22 @@ def users(request):
users = objects_list.page(objects_list.num_pages)
return render_to_response('users.html', {
- "users" : users,
- "suser" : suser,
- "keywords" : suser,
- "tab_id" : sortby,
- "context" : {
- 'is_paginated' : is_paginated,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': users.has_previous(),
- 'has_next': users.has_next(),
- 'previous': users.previous_page_number(),
- 'next': users.next_page_number(),
- 'base_url' : base_url
- }
-
- }, context_instance=RequestContext(request))
+ "users": users,
+ "suser": suser,
+ "keywords": suser,
+ "tab_id": sortby,
+ "context": {
+ 'is_paginated': is_paginated,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': users.has_previous(),
+ 'has_next': users.has_next(),
+ 'previous': users.previous_page_number(),
+ 'next': users.next_page_number(),
+ 'base_url': base_url
+ }
+
+ }, context_instance=RequestContext(request))
def user(request, id):
sort = request.GET.get('sort', 'stats')
@@ -1098,120 +1090,119 @@ def edit_user(request, id):
else:
form = EditUserForm(user)
return render_to_response('user_edit.html', {
- 'form' : form,
- }, context_instance=RequestContext(request))
+ 'form': form,
+ }, context_instance=RequestContext(request))
def user_stats(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
questions = Question.objects.extra(
- select={
- 'vote_count' : 'question.score',
- 'favorited_myself' : 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s AND f.question_id = question.id',
- 'la_user_id' : 'auth_user.id',
- 'la_username' : 'auth_user.username',
- 'la_user_gold' : 'auth_user.gold',
- 'la_user_silver' : 'auth_user.silver',
- 'la_user_bronze' : 'auth_user.bronze',
- 'la_user_reputation' : 'auth_user.reputation'
- },
- select_params=[user_id],
- tables=['question', 'auth_user'],
- where=['question.deleted = 0 AND question.author_id=%s AND question.last_activity_by_id = auth_user.id'],
- params=[user_id],
- order_by=['-vote_count', '-last_activity_at']
- ).values('vote_count',
- 'favorited_myself',
- 'id',
- 'title',
- 'author_id',
- 'added_at',
- 'answer_accepted',
- 'answer_count',
- 'comment_count',
- 'view_count',
- 'favourite_count',
- 'summary',
- 'tagnames',
- 'vote_up_count',
- 'vote_down_count',
- 'last_activity_at',
- 'la_user_id',
- 'la_username',
- 'la_user_gold',
- 'la_user_silver',
- 'la_user_bronze',
- 'la_user_reputation')[:100]
+ select={
+ 'vote_count': 'question.score',
+ 'favorited_myself': 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s AND f.question_id = question.id',
+ 'la_user_id': 'auth_user.id',
+ 'la_username': 'auth_user.username',
+ 'la_user_gold': 'auth_user.gold',
+ 'la_user_silver': 'auth_user.silver',
+ 'la_user_bronze': 'auth_user.bronze',
+ 'la_user_reputation': 'auth_user.reputation'
+ },
+ select_params=[user_id],
+ tables=['question', 'auth_user'],
+ where=['question.deleted = 0 AND question.author_id=%s AND question.last_activity_by_id = auth_user.id'],
+ params=[user_id],
+ order_by=['-vote_count', '-last_activity_at']
+ ).values('vote_count',
+ 'favorited_myself',
+ 'id',
+ 'title',
+ 'author_id',
+ 'added_at',
+ 'answer_accepted',
+ 'answer_count',
+ 'comment_count',
+ 'view_count',
+ 'favourite_count',
+ 'summary',
+ 'tagnames',
+ 'vote_up_count',
+ 'vote_down_count',
+ 'last_activity_at',
+ 'la_user_id',
+ 'la_username',
+ 'la_user_gold',
+ 'la_user_silver',
+ 'la_user_bronze',
+ 'la_user_reputation')[:100]
answered_questions = Question.objects.extra(
- select={
- 'vote_up_count' : 'answer.vote_up_count',
- 'vote_down_count' : 'answer.vote_down_count',
- 'answer_id' : 'answer.id',
- 'accepted' : 'answer.accepted',
- 'vote_count' : 'answer.score',
- 'comment_count' : 'answer.comment_count'
- },
- tables=['question', 'answer'],
- where=['answer.deleted=0 AND answer.author_id=%s AND answer.question_id=question.id'],
- params=[user_id],
- order_by=['-vote_count', '-answer_id'],
- select_params=[user_id]
- ).distinct().values('comment_count',
- 'id',
- 'answer_id',
- 'title',
- 'author_id',
- 'accepted',
- 'vote_count',
- 'answer_count',
- 'vote_up_count',
- 'vote_down_count')[:100]
+ select={
+ 'vote_up_count': 'answer.vote_up_count',
+ 'vote_down_count': 'answer.vote_down_count',
+ 'answer_id': 'answer.id',
+ 'accepted': 'answer.accepted',
+ 'vote_count': 'answer.score',
+ 'comment_count': 'answer.comment_count'
+ },
+ tables=['question', 'answer'],
+ where=['answer.deleted=0 AND answer.author_id=%s AND answer.question_id=question.id'],
+ params=[user_id],
+ order_by=['-vote_count', '-answer_id'],
+ select_params=[user_id]
+ ).distinct().values('comment_count',
+ 'id',
+ 'answer_id',
+ 'title',
+ 'author_id',
+ 'accepted',
+ 'vote_count',
+ 'answer_count',
+ 'vote_up_count',
+ 'vote_down_count')[:100]
up_votes = Vote.objects.get_up_vote_count_from_user(user)
down_votes = Vote.objects.get_down_vote_count_from_user(user)
votes_today = Vote.objects.get_votes_count_today_from_user(user)
votes_total = VOTE_RULES['scope_votes_per_user_per_day']
tags = user.created_tags.all().order_by('-used_count')[:50]
- if settings.DJANGO_VERSION < 1.1:
+
+ try:
+ from django.db.models import Count
awards = Award.objects.extra(
- select={'id': 'badge.id', 'count': 'count(badge_id)', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
- tables=['award', 'badge'],
- order_by=['-awarded_at'],
- where=['user_id=%s AND badge_id=badge.id'],
- params=[user.id]
- ).values('id', 'count', 'name', 'description', 'type')
+ select={'id': 'badge.id', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
+ tables=['award', 'badge'],
+ order_by=['-awarded_at'],
+ where=['user_id=%s AND badge_id=badge.id'],
+ params=[user.id]
+ ).values('id', 'name', 'description', 'type')
total_awards = awards.count()
- awards.query.group_by = ['badge_id']
- else:
+ awards = awards.annotate(count=Count('badge__id'))
+ except ImportError:
awards = Award.objects.extra(
- select={'id': 'badge.id', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
- tables=['award', 'badge'],
- order_by=['-awarded_at'],
- where=['user_id=%s AND badge_id=badge.id'],
- params=[user.id]
- ).values('id', 'name', 'description', 'type')
+ select={'id': 'badge.id', 'count': 'count(badge_id)', 'name':'badge.name', 'description': 'badge.description', 'type': 'badge.type'},
+ tables=['award', 'badge'],
+ order_by=['-awarded_at'],
+ where=['user_id=%s AND badge_id=badge.id'],
+ params=[user.id]
+ ).values('id', 'count', 'name', 'description', 'type')
total_awards = awards.count()
- try:
- from django.db.models import Count
- awards = awards.annotate(count = Count('badge__id'))
- except:
- pass
+ awards.query.group_by = ['badge_id']
+
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "questions" : questions,
- "answered_questions" : answered_questions,
- "up_votes" : up_votes,
- "down_votes" : down_votes,
- "total_votes": up_votes + down_votes,
- "votes_today_left": votes_total-votes_today,
- "votes_total_per_day": votes_total,
- "tags" : tags,
- "awards": awards,
- "total_awards" : total_awards,
- }, context_instance=RequestContext(request))
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ "questions": questions,
+ "answered_questions": answered_questions,
+ "up_votes": up_votes,
+ "down_votes": down_votes,
+ "total_votes": up_votes + down_votes,
+ "votes_today_left": votes_total-votes_today,
+ "votes_total_per_day": votes_total,
+ "tags": tags,
+ "awards": awards,
+ "total_awards": total_awards,
+ }, context_instance=RequestContext(request))
def user_recent(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
@@ -1227,11 +1218,8 @@ def user_recent(request, user_id, user_view):
self.type_id = type
self.title = title
self.summary = summary
- slug_title = slugify(title)
- if int(answer_id) > 0:
- self.title_link = u'/%s%s/%s#%s' %(_('questions/'),question_id, slug_title, answer_id)
- else:
- self.title_link = u'/%s%s/%s' %(_('questions/'),question_id, slug_title)
+ self.title_link = u'/questions/%s/%s#%s' % (question_id, title, answer_id)\
+ if int(answer_id) > 0 else u'/questions/%s/%s' % (question_id, title)
class AwardEvent:
def __init__(self, time, type, id):
@@ -1243,225 +1231,225 @@ def user_recent(request, user_id, user_view):
activities = []
# ask questions
questions = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'active_at' : 'activity.active_at',
- 'activity_type' : 'activity.activity_type'
- },
- tables=['activity', 'question'],
- where=['activity.content_type_id = %s AND activity.object_id = ' +
- 'question.id AND activity.user_id = %s AND activity.activity_type = %s'],
- params=[question_type_id, user_id, TYPE_ACTIVITY_ASK_QUESTION],
- order_by=['-activity.active_at']
- ).values(
- 'title',
- 'question_id',
- 'active_at',
- 'activity_type'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'active_at': 'activity.active_at',
+ 'activity_type': 'activity.activity_type'
+ },
+ tables=['activity', 'question'],
+ where=['activity.content_type_id = %s AND activity.object_id = ' +
+ 'question.id AND activity.user_id = %s AND activity.activity_type = %s'],
+ params=[question_type_id, user_id, TYPE_ACTIVITY_ASK_QUESTION],
+ order_by=['-activity.active_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'active_at',
+ 'activity_type'
+ )
if len(questions) > 0:
questions = [(Event(q['active_at'], q['activity_type'], q['title'], '', '0', \
- q['question_id'])) for q in questions]
+ q['question_id'])) for q in questions]
activities.extend(questions)
# answers
answers = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'active_at' : 'activity.active_at',
- 'activity_type' : 'activity.activity_type'
- },
- tables=['activity', 'answer', 'question'],
- where=['activity.content_type_id = %s AND activity.object_id = answer.id AND ' +
- 'answer.question_id=question.id AND activity.user_id=%s AND activity.activity_type=%s'],
- params=[answer_type_id, user_id, TYPE_ACTIVITY_ANSWER],
- order_by=['-activity.active_at']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'active_at',
- 'activity_type'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'active_at': 'activity.active_at',
+ 'activity_type': 'activity.activity_type'
+ },
+ tables=['activity', 'answer', 'question'],
+ where=['activity.content_type_id = %s AND activity.object_id = answer.id AND ' +
+ 'answer.question_id=question.id AND activity.user_id=%s AND activity.activity_type=%s'],
+ params=[answer_type_id, user_id, TYPE_ACTIVITY_ANSWER],
+ order_by=['-activity.active_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'active_at',
+ 'activity_type'
+ )
if len(answers) > 0:
answers = [(Event(q['active_at'], q['activity_type'], q['title'], '', q['answer_id'], \
- q['question_id'])) for q in answers]
+ q['question_id'])) for q in answers]
activities.extend(answers)
# question comments
comments = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'comment.object_id',
- 'added_at' : 'comment.added_at',
- 'activity_type' : 'activity.activity_type'
- },
- tables=['activity', 'question', 'comment'],
-
- where=['activity.content_type_id = %s AND activity.object_id = comment.id AND '+
- 'activity.user_id = comment.user_id AND comment.object_id=question.id AND '+
- 'comment.content_type_id=%s AND activity.user_id = %s AND activity.activity_type=%s'],
- params=[comment_type_id, question_type_id, user_id, TYPE_ACTIVITY_COMMENT_QUESTION],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'activity_type'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'comment.object_id',
+ 'added_at': 'comment.added_at',
+ 'activity_type': 'activity.activity_type'
+ },
+ tables=['activity', 'question', 'comment'],
+
+ where=['activity.content_type_id = %s AND activity.object_id = comment.id AND ' +
+ 'activity.user_id = comment.user_id AND comment.object_id=question.id AND ' +
+ 'comment.content_type_id=%s AND activity.user_id = %s AND activity.activity_type=%s'],
+ params=[comment_type_id, question_type_id, user_id, TYPE_ACTIVITY_COMMENT_QUESTION],
+ order_by=['-comment.added_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'added_at',
+ 'activity_type'
+ )
if len(comments) > 0:
comments = [(Event(q['added_at'], q['activity_type'], q['title'], '', '0', \
- q['question_id'])) for q in comments]
+ q['question_id'])) for q in comments]
activities.extend(comments)
# answer comments
comments = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'comment.added_at',
- 'activity_type' : 'activity.activity_type'
- },
- tables=['activity', 'question', 'answer', 'comment'],
-
- where=['activity.content_type_id = %s AND activity.object_id = comment.id AND '+
- 'activity.user_id = comment.user_id AND comment.object_id=answer.id AND '+
- 'comment.content_type_id=%s AND question.id = answer.question_id AND '+
- 'activity.user_id = %s AND activity.activity_type=%s'],
- params=[comment_type_id, answer_type_id, user_id, TYPE_ACTIVITY_COMMENT_ANSWER],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'activity_type'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'added_at': 'comment.added_at',
+ 'activity_type': 'activity.activity_type'
+ },
+ tables=['activity', 'question', 'answer', 'comment'],
+
+ where=['activity.content_type_id = %s AND activity.object_id = comment.id AND ' +
+ 'activity.user_id = comment.user_id AND comment.object_id=answer.id AND ' +
+ 'comment.content_type_id=%s AND question.id = answer.question_id AND ' +
+ 'activity.user_id = %s AND activity.activity_type=%s'],
+ params=[comment_type_id, answer_type_id, user_id, TYPE_ACTIVITY_COMMENT_ANSWER],
+ order_by=['-comment.added_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'added_at',
+ 'activity_type'
+ )
if len(comments) > 0:
comments = [(Event(q['added_at'], q['activity_type'], q['title'], '', q['answer_id'], \
- q['question_id'])) for q in comments]
+ q['question_id'])) for q in comments]
activities.extend(comments)
# question revisions
revisions = Activity.objects.extra(
- select={
- 'title' : 'question_revision.title',
- 'question_id' : 'question_revision.question_id',
- 'added_at' : 'activity.active_at',
- 'activity_type' : 'activity.activity_type',
- 'summary' : 'question_revision.summary'
- },
- tables=['activity', 'question_revision'],
- where=['activity.content_type_id = %s AND activity.object_id = question_revision.id AND '+
- 'activity.user_id = question_revision.author_id AND activity.user_id = %s AND '+
- 'activity.activity_type=%s'],
- params=[question_revision_type_id, user_id, TYPE_ACTIVITY_UPDATE_QUESTION],
- order_by=['-activity.active_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'activity_type',
- 'summary'
- )
+ select={
+ 'title': 'question_revision.title',
+ 'question_id': 'question_revision.question_id',
+ 'added_at': 'activity.active_at',
+ 'activity_type': 'activity.activity_type',
+ 'summary': 'question_revision.summary'
+ },
+ tables=['activity', 'question_revision'],
+ where=['activity.content_type_id = %s AND activity.object_id = question_revision.id AND ' +
+ 'activity.user_id = question_revision.author_id AND activity.user_id = %s AND ' +
+ 'activity.activity_type=%s'],
+ params=[question_revision_type_id, user_id, TYPE_ACTIVITY_UPDATE_QUESTION],
+ order_by=['-activity.active_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'added_at',
+ 'activity_type',
+ 'summary'
+ )
if len(revisions) > 0:
revisions = [(Event(q['added_at'], q['activity_type'], q['title'], q['summary'], '0', \
- q['question_id'])) for q in revisions]
+ q['question_id'])) for q in revisions]
activities.extend(revisions)
# answer revisions
revisions = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'activity.active_at',
- 'activity_type' : 'activity.activity_type',
- 'summary' : 'answer_revision.summary'
- },
- tables=['activity', 'answer_revision', 'question', 'answer'],
-
- where=['activity.content_type_id = %s AND activity.object_id = answer_revision.id AND '+
- 'activity.user_id = answer_revision.author_id AND activity.user_id = %s AND '+
- 'answer_revision.answer_id=answer.id AND answer.question_id = question.id AND '+
- 'activity.activity_type=%s'],
- params=[answer_revision_type_id, user_id, TYPE_ACTIVITY_UPDATE_ANSWER],
- order_by=['-activity.active_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'answer_id',
- 'activity_type',
- 'summary'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'added_at': 'activity.active_at',
+ 'activity_type': 'activity.activity_type',
+ 'summary': 'answer_revision.summary'
+ },
+ tables=['activity', 'answer_revision', 'question', 'answer'],
+
+ where=['activity.content_type_id = %s AND activity.object_id = answer_revision.id AND ' +
+ 'activity.user_id = answer_revision.author_id AND activity.user_id = %s AND ' +
+ 'answer_revision.answer_id=answer.id AND answer.question_id = question.id AND ' +
+ 'activity.activity_type=%s'],
+ params=[answer_revision_type_id, user_id, TYPE_ACTIVITY_UPDATE_ANSWER],
+ order_by=['-activity.active_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'added_at',
+ 'answer_id',
+ 'activity_type',
+ 'summary'
+ )
if len(revisions) > 0:
revisions = [(Event(q['added_at'], q['activity_type'], q['title'], q['summary'], \
- q['answer_id'], q['question_id'])) for q in revisions]
+ q['answer_id'], q['question_id'])) for q in revisions]
activities.extend(revisions)
# accepted answers
accept_answers = Activity.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'added_at' : 'activity.active_at',
- 'activity_type' : 'activity.activity_type',
- },
- tables=['activity', 'answer', 'question'],
- where=['activity.content_type_id = %s AND activity.object_id = answer.id AND '+
- 'activity.user_id = question.author_id AND activity.user_id = %s AND '+
- 'answer.question_id=question.id AND activity.activity_type=%s'],
- params=[answer_type_id, user_id, TYPE_ACTIVITY_MARK_ANSWER],
- order_by=['-activity.active_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'activity_type',
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'added_at': 'activity.active_at',
+ 'activity_type': 'activity.activity_type',
+ },
+ tables=['activity', 'answer', 'question'],
+ where=['activity.content_type_id = %s AND activity.object_id = answer.id AND ' +
+ 'activity.user_id = question.author_id AND activity.user_id = %s AND ' +
+ 'answer.question_id=question.id AND activity.activity_type=%s'],
+ params=[answer_type_id, user_id, TYPE_ACTIVITY_MARK_ANSWER],
+ order_by=['-activity.active_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'added_at',
+ 'activity_type',
+ )
if len(accept_answers) > 0:
accept_answers = [(Event(q['added_at'], q['activity_type'], q['title'], '', '0', \
- q['question_id'])) for q in accept_answers]
+ q['question_id'])) for q in accept_answers]
activities.extend(accept_answers)
#award history
awards = Activity.objects.extra(
- select={
- 'badge_id' : 'badge.id',
- 'awarded_at': 'award.awarded_at',
- 'activity_type' : 'activity.activity_type'
- },
- tables=['activity', 'award', 'badge'],
- where=['activity.user_id = award.user_id AND activity.user_id = %s AND '+
- 'award.badge_id=badge.id AND activity.object_id=award.id AND activity.activity_type=%s'],
- params=[user_id, TYPE_ACTIVITY_PRIZE],
- order_by=['-activity.active_at']
- ).values(
- 'badge_id',
- 'awarded_at',
- 'activity_type'
- )
+ select={
+ 'badge_id': 'badge.id',
+ 'awarded_at': 'award.awarded_at',
+ 'activity_type': 'activity.activity_type'
+ },
+ tables=['activity', 'award', 'badge'],
+ where=['activity.user_id = award.user_id AND activity.user_id = %s AND ' +
+ 'award.badge_id=badge.id AND activity.object_id=award.id AND activity.activity_type=%s'],
+ params=[user_id, TYPE_ACTIVITY_PRIZE],
+ order_by=['-activity.active_at']
+ ).values(
+ 'badge_id',
+ 'awarded_at',
+ 'activity_type'
+ )
if len(awards) > 0:
awards = [(AwardEvent(q['awarded_at'], q['activity_type'], q['badge_id'])) for q in awards]
activities.extend(awards)
- activities.sort(lambda x,y: cmp(y.time, x.time))
+ activities.sort(lambda x, y: cmp(y.time, x.time))
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "activities" : activities[:user_view.data_size]
- }, context_instance=RequestContext(request))
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ "activities": activities[:user_view.data_size]
+ }, context_instance=RequestContext(request))
def user_responses(request, user_id, user_view):
"""
@@ -1483,139 +1471,139 @@ def user_responses(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
responses = []
answers = Answer.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'answer.added_at',
- 'html' : 'answer.html',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- select_params=[user_id],
- tables=['answer', 'question', 'auth_user'],
- where=['answer.question_id = question.id AND answer.deleted=0 AND question.deleted = 0 AND '+
- 'question.author_id = %s AND answer.author_id <> %s AND answer.author_id=auth_user.id'],
- params=[user_id, user_id],
- order_by=['-answer.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'html',
- 'username',
- 'user_id'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'added_at': 'answer.added_at',
+ 'html': 'answer.html',
+ 'username': 'auth_user.username',
+ 'user_id': 'auth_user.id'
+ },
+ select_params=[user_id],
+ tables=['answer', 'question', 'auth_user'],
+ where=['answer.question_id = question.id AND answer.deleted=0 AND question.deleted = 0 AND ' +
+ 'question.author_id = %s AND answer.author_id <> %s AND answer.author_id=auth_user.id'],
+ params=[user_id, user_id],
+ order_by=['-answer.id']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'added_at',
+ 'html',
+ 'username',
+ 'user_id'
+ )
if len(answers) > 0:
answers = [(Response(TYPE_RESPONSE['QUESTION_ANSWERED'], a['title'], a['question_id'],
- a['answer_id'], a['added_at'], a['username'], a['user_id'], a['html'])) for a in answers]
+ a['answer_id'], a['added_at'], a['username'], a['user_id'], a['html'])) for a in answers]
responses.extend(answers)
# question comments
comments = Comment.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'comment.object_id',
- 'added_at' : 'comment.added_at',
- 'comment' : 'comment.comment',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- tables=['question', 'auth_user', 'comment'],
- where=['question.deleted = 0 AND question.author_id = %s AND comment.object_id=question.id AND '+
- 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id'],
- params=[user_id, question_type_id, user_id],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'comment',
- 'username',
- 'user_id'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'comment.object_id',
+ 'added_at': 'comment.added_at',
+ 'comment': 'comment.comment',
+ 'username': 'auth_user.username',
+ 'user_id': 'auth_user.id'
+ },
+ tables=['question', 'auth_user', 'comment'],
+ where=['question.deleted = 0 AND question.author_id = %s AND comment.object_id=question.id AND ' +
+ 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id'],
+ params=[user_id, question_type_id, user_id],
+ order_by=['-comment.added_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'added_at',
+ 'comment',
+ 'username',
+ 'user_id'
+ )
if len(comments) > 0:
comments = [(Response(TYPE_RESPONSE['QUESTION_COMMENTED'], c['title'], c['question_id'],
- '', c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
+ '', c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
responses.extend(comments)
# answer comments
comments = Comment.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'comment.added_at',
- 'comment' : 'comment.comment',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- tables=['answer', 'auth_user', 'comment', 'question'],
- where=['answer.deleted = 0 AND answer.author_id = %s AND comment.object_id=answer.id AND '+
- 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id '+
- 'AND question.id = answer.question_id'],
- params=[user_id, answer_type_id, user_id],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'comment',
- 'username',
- 'user_id'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'added_at': 'comment.added_at',
+ 'comment': 'comment.comment',
+ 'username': 'auth_user.username',
+ 'user_id': 'auth_user.id'
+ },
+ tables=['answer', 'auth_user', 'comment', 'question'],
+ where=['answer.deleted = 0 AND answer.author_id = %s AND comment.object_id=answer.id AND ' +
+ 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id ' +
+ 'AND question.id = answer.question_id'],
+ params=[user_id, answer_type_id, user_id],
+ order_by=['-comment.added_at']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'added_at',
+ 'comment',
+ 'username',
+ 'user_id'
+ )
if len(comments) > 0:
comments = [(Response(TYPE_RESPONSE['ANSWER_COMMENTED'], c['title'], c['question_id'],
- c['answer_id'], c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
+ c['answer_id'], c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
responses.extend(comments)
# answer has been accepted
answers = Answer.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'answer.accepted_at',
- 'html' : 'answer.html',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- select_params=[user_id],
- tables=['answer', 'question', 'auth_user'],
- where=['answer.question_id = question.id AND answer.deleted=0 AND question.deleted = 0 AND '+
- 'answer.author_id = %s AND answer.accepted=1 AND question.author_id=auth_user.id'],
- params=[user_id],
- order_by=['-answer.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'html',
- 'username',
- 'user_id'
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'added_at': 'answer.accepted_at',
+ 'html': 'answer.html',
+ 'username': 'auth_user.username',
+ 'user_id': 'auth_user.id'
+ },
+ select_params=[user_id],
+ tables=['answer', 'question', 'auth_user'],
+ where=['answer.question_id = question.id AND answer.deleted=0 AND question.deleted = 0 AND ' +
+ 'answer.author_id = %s AND answer.accepted=1 AND question.author_id=auth_user.id'],
+ params=[user_id],
+ order_by=['-answer.id']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'added_at',
+ 'html',
+ 'username',
+ 'user_id'
+ )
if len(answers) > 0:
answers = [(Response(TYPE_RESPONSE['ANSWER_ACCEPTED'], a['title'], a['question_id'],
- a['answer_id'], a['added_at'], a['username'], a['user_id'], a['html'])) for a in answers]
+ a['answer_id'], a['added_at'], a['username'], a['user_id'], a['html'])) for a in answers]
responses.extend(answers)
# sort posts by time
- responses.sort(lambda x,y: cmp(y.time, x.time))
+ responses.sort(lambda x, y: cmp(y.time, x.time))
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "responses" : responses[:user_view.data_size],
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ "responses": responses[:user_view.data_size],
- }, context_instance=RequestContext(request))
+ }, context_instance=RequestContext(request))
def user_votes(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
@@ -1623,74 +1611,85 @@ def user_votes(request, user_id, user_view):
raise Http404
votes = []
question_votes = Vote.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 0,
- 'voted_at' : 'vote.voted_at',
- 'vote' : 'vote',
- },
- select_params=[user_id],
- tables=['vote', 'question', 'auth_user'],
- where=['vote.content_type_id = %s AND vote.user_id = %s AND vote.object_id = question.id '+
- 'AND vote.user_id=auth_user.id'],
- params=[question_type_id, user_id],
- order_by=['-vote.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'voted_at',
- 'vote',
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 0,
+ 'voted_at': 'vote.voted_at',
+ 'vote': 'vote',
+ },
+ select_params=[user_id],
+ tables=['vote', 'question', 'auth_user'],
+ where=['vote.content_type_id = %s AND vote.user_id = %s AND vote.object_id = question.id ' +
+ 'AND vote.user_id=auth_user.id'],
+ params=[question_type_id, user_id],
+ order_by=['-vote.id']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'voted_at',
+ 'vote',
+ )
if(len(question_votes) > 0):
votes.extend(question_votes)
answer_votes = Vote.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'voted_at' : 'vote.voted_at',
- 'vote' : 'vote',
- },
- select_params=[user_id],
- tables=['vote', 'answer', 'question', 'auth_user'],
- where=['vote.content_type_id = %s AND vote.user_id = %s AND vote.object_id = answer.id '+
- 'AND answer.question_id = question.id AND vote.user_id=auth_user.id'],
- params=[answer_type_id, user_id],
- order_by=['-vote.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'voted_at',
- 'vote',
- )
+ select={
+ 'title': 'question.title',
+ 'question_id': 'question.id',
+ 'answer_id': 'answer.id',
+ 'voted_at': 'vote.voted_at',
+ 'vote': 'vote',
+ },
+ select_params=[user_id],
+ tables=['vote', 'answer', 'question', 'auth_user'],
+ where=['vote.content_type_id = %s AND vote.user_id = %s AND vote.object_id = answer.id ' +
+ 'AND answer.question_id = question.id AND vote.user_id=auth_user.id'],
+ params=[answer_type_id, user_id],
+ order_by=['-vote.id']
+ ).values(
+ 'title',
+ 'question_id',
+ 'answer_id',
+ 'voted_at',
+ 'vote',
+ )
if(len(answer_votes) > 0):
votes.extend(answer_votes)
- votes.sort(lambda x,y: cmp(y['voted_at'], x['voted_at']))
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "votes" : votes[:user_view.data_size]
+ votes.sort(lambda x, y: cmp(y['voted_at'], x['voted_at']))
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ "votes": votes[:user_view.data_size]
- }, context_instance=RequestContext(request))
+ }, context_instance=RequestContext(request))
def user_reputation(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
- reputation = Repute.objects.extra(
- select={'positive': 'sum(positive)', 'negative': 'sum(negative)', 'question_id':'question_id',
- 'title': 'question.title'},
- tables=['repute', 'question'],
- order_by=['-reputed_at'],
- where=['user_id=%s AND question_id=question.id'],
- params=[user.id]
- ).values('positive', 'negative', 'question_id', 'title', 'reputed_at', 'reputation')
-
- reputation.query.group_by = ['question_id']
+ try:
+ from django.db.models import Sum
+ reputation = Repute.objects.extra(
+ select={'question_id':'question_id',
+ 'title': 'question.title'},
+ tables=['repute', 'question'],
+ order_by=['-reputed_at'],
+ where=['user_id=%s AND question_id=question.id'],
+ params=[user.id]
+ ).values('question_id', 'title', 'reputed_at', 'reputation')
+ reputation = reputation.annotate(positive=Sum("positive"), negative=Sum("negative"))
+ except ImportError:
+ reputation = Repute.objects.extra(
+ select={'positive':'sum(positive)', 'negative':'sum(negative)', 'question_id':'question_id',
+ 'title': 'question.title'},
+ tables=['repute', 'question'],
+ order_by=['-reputed_at'],
+ where=['user_id=%s AND question_id=question.id'],
+ params=[user.id]
+ ).values('positive', 'negative', 'question_id', 'title', 'reputed_at', 'reputation')
+ reputation.query.group_by = ['question_id']
rep_list = []
for rep in Repute.objects.filter(user=user).order_by('reputed_at'):
@@ -1699,74 +1698,74 @@ def user_reputation(request, user_id, user_view):
reps = ','.join(rep_list)
reps = '[%s]' % reps
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "reputation" : reputation,
- "reps" : reps
- }, context_instance=RequestContext(request))
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ "reputation": reputation,
+ "reps": reps
+ }, context_instance=RequestContext(request))
def user_favorites(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
questions = Question.objects.extra(
- select={
- 'vote_count' : 'question.vote_up_count + question.vote_down_count',
- 'favorited_myself' : 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s '+
- 'AND f.question_id = question.id',
- 'la_user_id' : 'auth_user.id',
- 'la_username' : 'auth_user.username',
- 'la_user_gold' : 'auth_user.gold',
- 'la_user_silver' : 'auth_user.silver',
- 'la_user_bronze' : 'auth_user.bronze',
- 'la_user_reputation' : 'auth_user.reputation'
- },
- select_params=[user_id],
- tables=['question', 'auth_user', 'favorite_question'],
- where=['question.deleted = 0 AND question.last_activity_by_id = auth_user.id '+
- 'AND favorite_question.question_id = question.id AND favorite_question.user_id = %s'],
- params=[user_id],
- order_by=['-vote_count', '-question.id']
- ).values('vote_count',
- 'favorited_myself',
- 'id',
- 'title',
- 'author_id',
- 'added_at',
- 'answer_accepted',
- 'answer_count',
- 'comment_count',
- 'view_count',
- 'favourite_count',
- 'summary',
- 'tagnames',
- 'vote_up_count',
- 'vote_down_count',
- 'last_activity_at',
- 'la_user_id',
- 'la_username',
- 'la_user_gold',
- 'la_user_silver',
- 'la_user_bronze',
- 'la_user_reputation')
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "questions" : questions[:user_view.data_size],
- "view_user" : user
- }, context_instance=RequestContext(request))
+ select={
+ 'vote_count': 'question.vote_up_count + question.vote_down_count',
+ 'favorited_myself': 'SELECT count(*) FROM favorite_question f WHERE f.user_id = %s ' +
+ 'AND f.question_id = question.id',
+ 'la_user_id': 'auth_user.id',
+ 'la_username': 'auth_user.username',
+ 'la_user_gold': 'auth_user.gold',
+ 'la_user_silver': 'auth_user.silver',
+ 'la_user_bronze': 'auth_user.bronze',
+ 'la_user_reputation': 'auth_user.reputation'
+ },
+ select_params=[user_id],
+ tables=['question', 'auth_user', 'favorite_question'],
+ where=['question.deleted = 0 AND question.last_activity_by_id = auth_user.id ' +
+ 'AND favorite_question.question_id = question.id AND favorite_question.user_id = %s'],
+ params=[user_id],
+ order_by=['-vote_count', '-question.id']
+ ).values('vote_count',
+ 'favorited_myself',
+ 'id',
+ 'title',
+ 'author_id',
+ 'added_at',
+ 'answer_accepted',
+ 'answer_count',
+ 'comment_count',
+ 'view_count',
+ 'favourite_count',
+ 'summary',
+ 'tagnames',
+ 'vote_up_count',
+ 'vote_down_count',
+ 'last_activity_at',
+ 'la_user_id',
+ 'la_username',
+ 'la_user_gold',
+ 'la_user_silver',
+ 'la_user_bronze',
+ 'la_user_reputation')
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "questions": questions[:user_view.data_size],
+ "view_user": user
+ }, context_instance=RequestContext(request))
def user_preferences(request, user_id, user_view):
user = get_object_or_404(User, id=user_id)
- return render_to_response(user_view.template_file,{
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- }, context_instance=RequestContext(request))
+ return render_to_response(user_view.template_file, {
+ "tab_name": user_view.id,
+ "tab_description": user_view.tab_description,
+ "page_title": user_view.page_title,
+ "view_user": user,
+ }, context_instance=RequestContext(request))
def question_comments(request, id):
question = get_object_or_404(Question, id=id)
@@ -1801,14 +1800,14 @@ def __generate_comments_json(obj, type, user):
if user != None and auth.can_delete_comment(user, comment):
#/posts/392845/comments/219852/delete
delete_url = "/" + type + "s/%s/comments/%s/delete/" % (obj.id, comment.id)
- json_comments.append({"id" : comment.id,
- "object_id" : obj.id,
- "add_date" : comment.added_at.strftime('%Y-%m-%d'),
- "text" : comment.comment,
- "user_display_name" : comment_user.username,
- "user_url" : "/%s%s/%s" % (_('users/'), comment_user.id, comment_user.username),
- "delete_url" : delete_url
- })
+ json_comments.append({"id": comment.id,
+ "object_id": obj.id,
+ "add_date": comment.added_at.strftime('%Y-%m-%d'),
+ "text": comment.comment,
+ "user_display_name": comment_user.username,
+ "user_url": "/users/%s/%s" % (comment_user.id, comment_user.username),
+ "delete_url": delete_url
+ })
data = simplejson.dumps(json_comments)
return HttpResponse(data, mimetype="application/json")
@@ -1838,8 +1837,8 @@ def delete_answer_comment(request, answer_id, comment_id):
def logout(request):
url = request.GET.get('next')
return render_to_response('logout.html', {
- 'next' : url,
- }, context_instance=RequestContext(request))
+ 'next': url,
+ }, context_instance=RequestContext(request))
def badges(request):
badges = Badge.objects.all().order_by('type')
@@ -1849,28 +1848,28 @@ def badges(request):
my_badges.query.group_by = ['badge_id']
return render_to_response('badges.html', {
- 'badges' : badges,
- 'mybadges' : my_badges,
- }, context_instance=RequestContext(request))
+ 'badges': badges,
+ 'mybadges': my_badges,
+ }, context_instance=RequestContext(request))
def badge(request, id):
badge = get_object_or_404(Badge, id=id)
awards = Award.objects.extra(
- select={'id': 'auth_user.id',
- 'name': 'auth_user.username',
- 'rep':'auth_user.reputation',
- 'gold': 'auth_user.gold',
- 'silver': 'auth_user.silver',
- 'bronze': 'auth_user.bronze'},
- tables=['award', 'auth_user'],
- where=['badge_id=%s AND user_id=auth_user.id'],
- params=[id]
- ).values('id').distinct()
+ select={'id': 'auth_user.id',
+ 'name': 'auth_user.username',
+ 'rep':'auth_user.reputation',
+ 'gold': 'auth_user.gold',
+ 'silver': 'auth_user.silver',
+ 'bronze': 'auth_user.bronze'},
+ tables=['award', 'auth_user'],
+ where=['badge_id=%s AND user_id=auth_user.id'],
+ params=[id]
+ ).values('id').distinct()
return render_to_response('badge.html', {
- 'awards' : awards,
- 'badge' : badge,
- }, context_instance=RequestContext(request))
+ 'awards': awards,
+ 'badge': badge,
+ }, context_instance=RequestContext(request))
def read_message(request):
if request.method == "POST":
@@ -1903,7 +1902,7 @@ def upload(request):
raise FileTypeNotAllow
# genetate new file name
- new_file_name = str(time.time()).replace('.', str(random.randint(0,100000))) + file_name_suffix
+ new_file_name = str(time.time()).replace('.', str(random.randint(0, 100000))) + file_name_suffix
# use default storage to store file
default_storage.save(new_file_name, f)
# check file size
@@ -1939,7 +1938,7 @@ def book(request, short_name, unanswered=False):
"""
books = Book.objects.extra(where=['short_name = %s'], params=[short_name])
match_count = len(books)
- if match_count == 0 :
+ if match_count == 0:
raise Http404
else:
# the book info
@@ -1961,7 +1960,7 @@ def book(request, short_name, unanswered=False):
page = 1
view_id = request.GET.get('sort', None)
- view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score" }
+ view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score"}
try:
orderby = view_dic[view_id]
except KeyError:
@@ -1982,22 +1981,22 @@ def book(request, short_name, unanswered=False):
questions = objects_list.page(page)
return render_to_response('book.html', {
- "book" : book,
- "author_info" : author_info,
- "author_rss" : author_rss,
- "questions" : questions,
- "context" : {
- 'is_paginated' : True,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': questions.has_previous(),
- 'has_next': questions.has_next(),
- 'previous': questions.previous_page_number(),
- 'next': questions.next_page_number(),
- 'base_url' : request.path + '?sort=%s&' % view_id,
- 'pagesize' : user_page_size
- }
- }, context_instance=RequestContext(request))
+ "book": book,
+ "author_info": author_info,
+ "author_rss": author_rss,
+ "questions": questions,
+ "context": {
+ 'is_paginated': True,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': questions.has_previous(),
+ 'has_next': questions.has_next(),
+ 'previous': questions.previous_page_number(),
+ 'next': questions.next_page_number(),
+ 'base_url': request.path + '?sort=%s&' % view_id,
+ 'pagesize': user_page_size
+ }
+ }, context_instance=RequestContext(request))
@login_required
def ask_book(request, short_name):
@@ -2007,16 +2006,16 @@ def ask_book(request, short_name):
added_at = datetime.datetime.now()
html = sanitize_html(markdowner.convert(form.cleaned_data['text']))
question = Question(
- title = strip_tags(form.cleaned_data['title']),
- author = request.user,
- added_at = added_at,
- last_activity_at = added_at,
- last_activity_by = request.user,
- wiki = form.cleaned_data['wiki'],
- tagnames = form.cleaned_data['tags'].strip(),
- html = html,
- summary = strip_tags(html)[:120]
- )
+ title=strip_tags(form.cleaned_data['title']),
+ author=request.user,
+ added_at=added_at,
+ last_activity_at=added_at,
+ last_activity_by=request.user,
+ wiki=form.cleaned_data['wiki'],
+ tagnames=form.cleaned_data['tags'].strip(),
+ html=html,
+ summary=strip_tags(html)[:120]
+ )
if question.wiki:
question.last_edited_by = question.author
question.last_edited_at = added_at
@@ -2026,15 +2025,15 @@ def ask_book(request, short_name):
# create the first revision
QuestionRevision.objects.create(
- question = question,
- revision = 1,
- title = question.title,
- author = request.user,
- revised_at = added_at,
- tagnames = question.tagnames,
- summary = CONST['default_version'],
- text = form.cleaned_data['text']
- )
+ question=question,
+ revision=1,
+ title=question.title,
+ author=request.user,
+ revised_at=added_at,
+ tagnames=question.tagnames,
+ summary=CONST['default_version'],
+ text=form.cleaned_data['text']
+ )
books = Book.objects.extra(where=['short_name = %s'], params=[short_name])
match_count = len(books)
@@ -2049,9 +2048,9 @@ def ask_book(request, short_name):
tags = _get_tags_cache_json()
return render_to_response('ask.html', {
- 'form' : form,
- 'tags' : tags,
- }, context_instance=RequestContext(request))
+ 'form': form,
+ 'tags': tags,
+ }, context_instance=RequestContext(request))
def search(request):
"""
@@ -2102,7 +2101,7 @@ def search(request):
user.save()
view_id = request.GET.get('sort', None)
- view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score" }
+ view_dic = {"latest":"-added_at", "active":"-last_activity_at", "hottest":"-answer_count", "mostvoted":"-score"}
try:
orderby = view_dic[view_id]
except KeyError:
@@ -2125,25 +2124,25 @@ def search(request):
related_tags.append(tag)
return render_to_response(template_file, {
- "questions" : questions,
- "tab_id" : view_id,
- "questions_count" : objects_list.count,
- "tags" : related_tags,
- "searchtag" : None,
- "searchtitle" : keywords,
- "keywords" : keywords,
- "is_unanswered" : False,
- "context" : {
- 'is_paginated' : True,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': questions.has_previous(),
- 'has_next': questions.has_next(),
- 'previous': questions.previous_page_number(),
- 'next': questions.next_page_number(),
- 'base_url' : request.path + '?t=question&q=%s&sort=%s&' % (keywords, view_id),
- 'pagesize' : pagesize
- }}, context_instance=RequestContext(request))
+ "questions": questions,
+ "tab_id": view_id,
+ "questions_count": objects_list.count,
+ "tags": related_tags,
+ "searchtag": None,
+ "searchtitle": keywords,
+ "keywords": keywords,
+ "is_unanswered": False,
+ "context": {
+ 'is_paginated': True,
+ 'pages': objects_list.num_pages,
+ 'page': page,
+ 'has_previous': questions.has_previous(),
+ 'has_next': questions.has_next(),
+ 'previous': questions.previous_page_number(),
+ 'next': questions.next_page_number(),
+ 'base_url': request.path + '?t=question&q=%s&sort=%s&' % (keywords, view_id),
+ 'pagesize': pagesize
+ }}, context_instance=RequestContext(request))
else:
raise Http404
diff --git a/rmpyc b/rmpyc
deleted file mode 100644
index 014575f6..00000000
--- a/rmpyc
+++ /dev/null
@@ -1 +0,0 @@
-rm `find . -name '*.pyc'`
diff --git a/settings.py b/settings.py
index ebb81ed1..86b075e4 100644
--- a/settings.py
+++ b/settings.py
@@ -39,7 +39,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.transaction.TransactionMiddleware',
#'django.middleware.sqlprint.SqlPrintingMiddleware',
- #'middleware.pagesize.QuestionsPageSizeMiddleware',
+ 'middleware.pagesize.QuestionsPageSizeMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)
@@ -76,8 +76,9 @@ INSTALLED_APPS = (
'django.contrib.humanize',
'forum',
'django_authopenid',
- 'debug_toolbar' ,
+ #'debug_toolbar' ,
)
-
+import django
+DJANGO_VERSION = django.get_version()
# User settings
from settings_local import *
diff --git a/settings_local.py.dist b/settings_local.py.dist
index 48d7b567..003c7491 100644
--- a/settings_local.py.dist
+++ b/settings_local.py.dist
@@ -1,20 +1,25 @@
# encoding:utf-8
import os.path
-
SITE_SRC_ROOT = os.path.dirname(__file__)
LOG_FILENAME = 'django.lanai.log'
-
+
#for logging
import logging
logging.basicConfig(filename=os.path.join(SITE_SRC_ROOT, 'log', LOG_FILENAME), level=logging.DEBUG,)
-
+
DATABASE_NAME = '' # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_ENGINE = '' #mysql, etc
+<<<<<<< HEAD:settings_local.py.dist
#Moved from settings.py for better organization. (please check it up to clean up settings.py)
+=======
+
+#Moved from settings.py for better organization. (please check it up to clean up settings.py)
+
+>>>>>>> 6214863f362fd0702af79abaade0de6736d12e96:settings_local.py.dist
#email server settings
SERVER_EMAIL = ''
DEFAULT_FROM_EMAIL = 'team@cnprog.com'
@@ -24,18 +29,30 @@ EMAIL_SUBJECT_PREFIX = '[cnprog.com]'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT='587'
EMAIL_USE_TLS=True
+<<<<<<< HEAD:settings_local.py.dist
#LOCALIZATIONS
TIME_ZONE = 'Asia/Chongqing Asia/Chungking'
# LANGUAGE_CODE = 'en-us'
+=======
+
+#LOCALIZATIONS
+TIME_ZONE = 'Asia/Chongqing Asia/Chungking'
+# LANGUAGE_CODE = 'en-us'
+
+>>>>>>> 6214863f362fd0702af79abaade0de6736d12e96:settings_local.py.dist
#OTHER SETTINGS
APP_TITLE = u'CNProg.com 程序员问答社区'
APP_KEYWORDS = u'技术问答社区,中国程序员,编程技术社区,程序员社区,程序员论坛,程序员wiki,程序员博客'
APP_DESCRIPTION = u'中国程序员的编程技术问答社区。我们做专业的、可协作编辑的技术问答社区。'
APP_INTRO = u' <p>CNProg是一个<strong>面向程序员</strong>的可协作编辑的<strong>开放源代码问答社区</strong>。</p><p> 您可以在这里提问各类<strong>程序技术问题</strong> - 问题不分语言和平台。 同时也希望您对力所能及的问题,给予您的宝贵答案。</p>'
APP_COPYRIGHT = 'Copyright CNPROG.COM 2009'
+<<<<<<< HEAD:settings_local.py.dist
+=======
+
+>>>>>>> 6214863f362fd0702af79abaade0de6736d12e96:settings_local.py.dist
USE_I18N = True
LANGUAGE_CODE = 'en'
EMAIL_VALIDATION = 'off'
@@ -43,5 +60,9 @@ MIN_USERNAME_LENGTH = 1
EMAIL_UNIQUE = False
APP_URL = 'http://server.com' #used by email notif system and RSS
GOOGLE_SITEMAP_CODE = '55uGNnQVJW8p1bbXeF/Xbh9I7nZBM/wLhRz6N/I1kkA='
+<<<<<<< HEAD:settings_local.py.dist
GOOGLE_ANALYTICS_KEY = ''
BOOKS_ON = True
+=======
+GOOGLE_ANALYTICS_KEY = ''
+>>>>>>> 6214863f362fd0702af79abaade0de6736d12e96:settings_local.py.dist
diff --git a/sql_scripts/update_2009_01_25_001.sql b/sql_scripts/update_2009_01_25_001.sql
index 1f1942e3..f6f3bed2 100644
--- a/sql_scripts/update_2009_01_25_001.sql
+++ b/sql_scripts/update_2009_01_25_001.sql
@@ -1,2 +1,2 @@
-ALTER TABLE `award` ADD `content_type_id` INT NULL
+ALTER TABLE `award` ADD `content_type_id` INT NULL
ALTER TABLE `award` ADD `object_id` INT NULL \ No newline at end of file
diff --git a/sql_scripts/update_2009_02_26_001.sql b/sql_scripts/update_2009_02_26_001.sql
index 9cc80974..4113d8f5 100644
--- a/sql_scripts/update_2009_02_26_001.sql
+++ b/sql_scripts/update_2009_02_26_001.sql
@@ -1,19 +1,19 @@
-ALTER TABLE answer ADD COLUMN `accepted_at` datetime default null;
-
-/* Update accepted_at column with answer added datetime for existing data */
-UPDATE answer
-SET accepted_at = added_at
-WHERE accepted = 1 AND accepted_at IS NULL;
-
-/* workround for c# url problem on bluehost server */
-UPDATE tag
-SET name = 'csharp'
-WHERE name = 'c#'
-
-UPDATE question
-SET tagnames = replace(tagnames, 'c#', 'csharp')
-WHERE tagnames like '%c#%'
-
-UPDATE question_revision
-SET tagnames = replace(tagnames, 'c#', 'csharp')
+ALTER TABLE answer ADD COLUMN `accepted_at` datetime default null;
+
+/* Update accepted_at column with answer added datetime for existing data */
+UPDATE answer
+SET accepted_at = added_at
+WHERE accepted = 1 AND accepted_at IS NULL;
+
+/* workround for c# url problem on bluehost server */
+UPDATE tag
+SET name = 'csharp'
+WHERE name = 'c#'
+
+UPDATE question
+SET tagnames = replace(tagnames, 'c#', 'csharp')
+WHERE tagnames like '%c#%'
+
+UPDATE question_revision
+SET tagnames = replace(tagnames, 'c#', 'csharp')
WHERE tagnames like '%c#%' \ No newline at end of file
diff --git a/sql_scripts/update_2009_04_10_001.sql b/sql_scripts/update_2009_04_10_001.sql
index b0d05ac7..e1ceb3bc 100644
--- a/sql_scripts/update_2009_04_10_001.sql
+++ b/sql_scripts/update_2009_04_10_001.sql
@@ -1,3 +1,3 @@
-ALTER TABLE Tag ADD COLUMN deleted_at datetime default null;
-ALTER TABLE Tag ADD COLUMN deleted_by_id INTEGER NULL;
+ALTER TABLE Tag ADD COLUMN deleted_at datetime default null;
+ALTER TABLE Tag ADD COLUMN deleted_by_id INTEGER NULL;
ALTER TABLE Tag ADD COLUMN deleted TINYINT NOT NULL; \ No newline at end of file
diff --git a/templates/content/js/compress.bat b/templates/content/js/compress.bat
index aa31271c..41e1882a 100644
--- a/templates/content/js/compress.bat
+++ b/templates/content/js/compress.bat
@@ -1,6 +1,6 @@
-#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 wmd\wmd.js -o wmd\wmd-min.js
-#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 wmd\showdown.js -o wmd\showdown-min.js
-#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 com.cnprog.post.js -o com.cnprog.post.pack.js
-java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 se_hilite_src.js -o se_hilite.js
-
+#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 wmd\wmd.js -o wmd\wmd-min.js
+#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 wmd\showdown.js -o wmd\showdown-min.js
+#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 com.cnprog.post.js -o com.cnprog.post.pack.js
+java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 se_hilite_src.js -o se_hilite.js
+
pause \ No newline at end of file
diff --git a/templates/content/js/flot-build.bat b/templates/content/js/flot-build.bat
index 28304966..fc715e3a 100644
--- a/templates/content/js/flot-build.bat
+++ b/templates/content/js/flot-build.bat
@@ -1,3 +1,3 @@
-java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 jquery.flot.js -o jquery.flot.pack.js
-
+java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 jquery.flot.js -o jquery.flot.pack.js
+
pause \ No newline at end of file
diff --git a/templates/content/style/style.css b/templates/content/style/style.css
index 0fb96c7f..241d72da 100644
--- a/templates/content/style/style.css
+++ b/templates/content/style/style.css
@@ -107,7 +107,6 @@ blockquote
margin-left:20px;text-decoration:underline; font-size:12px; color:#333333;}
#logo {
padding: 5px 0px 0px 0px;
- margin-bottom:-3px;
}
#navBar {float:clear;position:relative;display:block;width:960px;}
#navBar .nav {margin:20px 0px 0px 16px;