diff options
author | hrcerqueira <hrcerqueira@gmail.com> | 2010-02-18 00:14:01 +0000 |
---|---|---|
committer | hrcerqueira <hrcerqueira@gmail.com> | 2010-02-18 00:14:01 +0000 |
commit | 710574352dabcab4c710f2795a26501e54329e79 (patch) | |
tree | c34a60217501a582d6fe5b7f0ca655d88bd03c62 | |
parent | 473bdf5773aed8bdd91a16e371f75e628d20511e (diff) | |
download | askbot-710574352dabcab4c710f2795a26501e54329e79.tar.gz askbot-710574352dabcab4c710f2795a26501e54329e79.tar.bz2 askbot-710574352dabcab4c710f2795a26501e54329e79.zip |
Fixed some errors and moved some folders to inside the forum folder.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | django_authopenid/forms.py | 4 | ||||
-rw-r--r-- | django_authopenid/util.py | 2 | ||||
-rwxr-xr-x | django_authopenid/views.py | 2 | ||||
-rw-r--r-- | forum/forms.py | 2 | ||||
-rw-r--r-- | forum/management/commands/send_email_alerts.py | 2 | ||||
-rw-r--r-- | forum/middleware/__init__.py (renamed from middleware/__init__.py) | 0 | ||||
-rw-r--r-- | forum/middleware/anon_user.py (renamed from middleware/anon_user.py) | 2 | ||||
-rw-r--r-- | forum/middleware/cancel.py (renamed from middleware/cancel.py) | 2 | ||||
-rw-r--r-- | forum/middleware/pagesize.py (renamed from middleware/pagesize.py) | 0 | ||||
-rwxr-xr-x | forum/models/answer.py | 27 | ||||
-rwxr-xr-x | forum/models/base.py | 3 | ||||
-rwxr-xr-x | forum/models/question.py | 10 | ||||
-rw-r--r-- | forum/utils/__init__.py (renamed from utils/__init__.py) | 0 | ||||
-rw-r--r-- | forum/utils/cache.py (renamed from utils/cache.py) | 0 | ||||
-rw-r--r-- | forum/utils/decorators.py (renamed from utils/decorators.py) | 0 | ||||
-rw-r--r-- | forum/utils/forms.py (renamed from utils/forms.py) | 0 | ||||
-rw-r--r-- | forum/utils/html.py (renamed from utils/html.py) | 0 | ||||
-rw-r--r-- | forum/utils/lists.py (renamed from utils/lists.py) | 0 | ||||
-rw-r--r-- | forum/utils/odict.py (renamed from utils/odict.py) | 0 | ||||
-rw-r--r-- | forum/views/commands.py | 2 | ||||
-rw-r--r-- | forum/views/content.py | 6 | ||||
-rw-r--r-- | forum/views/meta.py | 2 | ||||
-rw-r--r-- | forum/views/readers.py | 4 | ||||
-rw-r--r-- | forum/views/writers.py | 11 | ||||
-rwxr-xr-x | settings.py | 6 | ||||
-rwxr-xr-x | settings_local.py.dist | 110 |
27 files changed, 154 insertions, 45 deletions
@@ -4,3 +4,5 @@ osqa.wsgi nbproject settings_local.py +.idea +*.iml diff --git a/django_authopenid/forms.py b/django_authopenid/forms.py index 5ec21c1c..2f34986c 100644 --- a/django_authopenid/forms.py +++ b/django_authopenid/forms.py @@ -39,7 +39,7 @@ import types import re from django.utils.safestring import mark_safe from recaptcha_django import ReCaptchaField -from utils.forms import NextUrlField, UserNameField, UserEmailField, SetPasswordForm +from forum.utils.forms import NextUrlField, UserNameField, UserEmailField, SetPasswordForm EXTERNAL_LOGIN_APP = settings.LOAD_EXTERNAL_LOGIN_APP() # needed for some linux distributions like debian @@ -48,7 +48,7 @@ try: except ImportError: from yadis import xri -from utils.forms import clean_next +from forum.utils.forms import clean_next from django_authopenid.models import ExternalLoginData __all__ = ['OpenidSigninForm', 'ClassicLoginForm', 'OpenidVerifyForm', diff --git a/django_authopenid/util.py b/django_authopenid/util.py index 969af0b9..cd2c2e2c 100644 --- a/django_authopenid/util.py +++ b/django_authopenid/util.py @@ -15,7 +15,7 @@ except: from yadis import xri import time, base64, hashlib, operator, logging -from utils.forms import clean_next, get_next_url +from forum.utils.forms import clean_next, get_next_url from models import Association, Nonce diff --git a/django_authopenid/views.py b/django_authopenid/views.py index 16a78864..7c7d9e07 100755 --- a/django_authopenid/views.py +++ b/django_authopenid/views.py @@ -67,7 +67,7 @@ from django_authopenid.forms import OpenidSigninForm, ClassicLoginForm, OpenidRe OpenidVerifyForm, ClassicRegisterForm, ChangePasswordForm, ChangeEmailForm, \ ChangeopenidForm, DeleteForm, EmailPasswordForm import logging -from utils.forms import get_next_url +from forum.utils.forms import get_next_url EXTERNAL_LOGIN_APP = settings.LOAD_EXTERNAL_LOGIN_APP() diff --git a/forum/forms.py b/forum/forms.py index 5796e2c1..f22763f7 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -5,7 +5,7 @@ from models import * from const import * from django.utils.translation import ugettext as _ from django.contrib.auth.models import User -from utils.forms import NextUrlField, UserNameField +from forum.utils.forms import NextUrlField, UserNameField from recaptcha_django import ReCaptchaField from django.conf import settings import logging diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index 62f13d69..26eb7790 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -9,7 +9,7 @@ from django.utils.translation import ungettext import datetime from django.conf import settings import logging -from utils.odict import OrderedDict +from forum.utils.odict import OrderedDict class Command(NoArgsCommand): def handle_noargs(self,**options): diff --git a/middleware/__init__.py b/forum/middleware/__init__.py index e69de29b..e69de29b 100644 --- a/middleware/__init__.py +++ b/forum/middleware/__init__.py diff --git a/middleware/anon_user.py b/forum/middleware/anon_user.py index fa2686f0..5295d9c0 100644 --- a/middleware/anon_user.py +++ b/forum/middleware/anon_user.py @@ -1,5 +1,5 @@ from django.http import HttpResponseRedirect -from utils.forms import get_next_url +from forum.utils.forms import get_next_url from django.utils.translation import ugettext as _ from user_messages import create_message, get_and_delete_messages from django.conf import settings diff --git a/middleware/cancel.py b/forum/middleware/cancel.py index 51e1b253..15a4371d 100644 --- a/middleware/cancel.py +++ b/forum/middleware/cancel.py @@ -1,5 +1,5 @@ from django.http import HttpResponseRedirect -from utils.forms import get_next_url +from forum.utils.forms import get_next_url import logging class CancelActionMiddleware(object): def process_view(self, request, view_func, view_args, view_kwargs): diff --git a/middleware/pagesize.py b/forum/middleware/pagesize.py index f6e6fcfd..f6e6fcfd 100644 --- a/middleware/pagesize.py +++ b/forum/middleware/pagesize.py diff --git a/forum/models/answer.py b/forum/models/answer.py index 4a44bd49..a1580828 100755 --- a/forum/models/answer.py +++ b/forum/models/answer.py @@ -24,9 +24,6 @@ class AnswerManager(models.Manager): question.save()
Question.objects.update_answer_count(question)
- #update revision
- from models import AnswerRevision
-
AnswerRevision.objects.create(
answer = answer,
revision = 1,
@@ -47,7 +44,7 @@ class AnswerManager(models.Manager): except:
pass
- 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'
+ #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):
"""
Retrieves visibile answers for the given question. Delete answers
@@ -57,16 +54,17 @@ class AnswerManager(models.Manager): if user is None or not user.is_authenticated():
return self.filter(question=question, deleted=False)
else:
- return self.filter(Q(question=question),
- Q(deleted=False) | Q(deleted_by=user))
-
- def get_answers_from_questions(self, user_id):
- """
- Retrieves visibile answers for the given question. Which are not included own answers
- """
- cursor = connection.cursor()
- cursor.execute(self.GET_ANSWERS_FROM_USER_QUESTIONS, [user_id, user_id])
- return cursor.fetchall()
+ return self.filter(models.Q(question=question),
+ models.Q(deleted=False) | models.Q(deleted_by=user))
+
+ #todo: I think this method is not being used anymore, I'll just comment it for now
+ #def get_answers_from_questions(self, user_id):
+ # """
+ # Retrieves visibile answers for the given question. Which are not included own answers
+ # """
+ # cursor = connection.cursor()
+ # cursor.execute(self.GET_ANSWERS_FROM_USER_QUESTIONS, [user_id, user_id])
+ # return cursor.fetchall()
class Answer(Content, DeletableContent):
question = models.ForeignKey('Question', related_name='answers')
@@ -99,6 +97,7 @@ class Answer(Content, DeletableContent): def __unicode__(self):
return self.html
+
class AnswerRevision(ContentRevision):
"""A revision of an Answer."""
diff --git a/forum/models/base.py b/forum/models/base.py index 24fe2b0d..2c28a470 100755 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -1,7 +1,7 @@ import datetime
import hashlib
from urllib import quote_plus, urlencode
-from django.db import models, IntegrityError
+from django.db import models, IntegrityError, connection, transaction
from django.utils.http import urlquote as django_urlquote
from django.utils.html import strip_tags
from django.core.urlresolvers import reverse
@@ -20,7 +20,6 @@ import logging if settings.USE_SPHINX_SEARCH == True:
from djangosphinx.models import SphinxSearch
-from forum.managers import *
from forum.const import *
class MetaContent(models.Model):
diff --git a/forum/models/question.py b/forum/models/question.py index cfa2f6be..20779d26 100755 --- a/forum/models/question.py +++ b/forum/models/question.py @@ -21,8 +21,6 @@ class QuestionManager(models.Manager): question.save()
- from models import QuestionRevision
-
# create the first revision
QuestionRevision.objects.create(
question = question,
@@ -77,7 +75,7 @@ class QuestionManager(models.Manager): # for some reasons, this Answer class failed to be imported,
# although we have imported all classes from models on top.
- from models import Answer
+ from answer import Answer
self.filter(id=question.id).update(
answer_count=Answer.objects.get_answers_from_question(question).filter(deleted=False).count())
@@ -91,7 +89,6 @@ class QuestionManager(models.Manager): """
update favourite_count for given question
"""
- from models import FavoriteQuestion
self.filter(id=question.id).update(favourite_count = FavoriteQuestion.objects.filter(question=question).count())
def get_similar_questions(self, question):
@@ -176,11 +173,10 @@ class Question(Content, DeletableContent): if not user.is_authenticated():
return False
- from models import FavoriteQuestion
return FavoriteQuestion.objects.filter(question=self, user=user).count() > 0
def get_answer_count_by_user(self, user_id):
- from models import Answer
+ from answer import Answer
query_set = Answer.objects.filter(author__id=user_id)
return query_set.filter(question=self).count()
@@ -273,6 +269,8 @@ class Question(Content, DeletableContent): def __unicode__(self):
return self.title
+
+
class QuestionView(models.Model):
question = models.ForeignKey(Question, related_name='viewed')
who = models.ForeignKey(User, related_name='question_views')
diff --git a/utils/__init__.py b/forum/utils/__init__.py index e69de29b..e69de29b 100644 --- a/utils/__init__.py +++ b/forum/utils/__init__.py diff --git a/utils/cache.py b/forum/utils/cache.py index 410c0662..410c0662 100644 --- a/utils/cache.py +++ b/forum/utils/cache.py diff --git a/utils/decorators.py b/forum/utils/decorators.py index e4e7acb3..e4e7acb3 100644 --- a/utils/decorators.py +++ b/forum/utils/decorators.py diff --git a/utils/forms.py b/forum/utils/forms.py index c54056ca..c54056ca 100644 --- a/utils/forms.py +++ b/forum/utils/forms.py diff --git a/utils/html.py b/forum/utils/html.py index 25a74a4a..25a74a4a 100644 --- a/utils/html.py +++ b/forum/utils/html.py diff --git a/utils/lists.py b/forum/utils/lists.py index bbcfae98..bbcfae98 100644 --- a/utils/lists.py +++ b/forum/utils/lists.py diff --git a/utils/odict.py b/forum/utils/odict.py index 2c8391d7..2c8391d7 100644 --- a/utils/odict.py +++ b/forum/utils/odict.py diff --git a/forum/views/commands.py b/forum/views/commands.py index 38915728..65121862 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -9,7 +9,7 @@ from forum.models import * from forum.forms import CloseForm from forum import auth from django.contrib.auth.decorators import login_required -from utils.decorators import ajax_method, ajax_login_required +from forum.utils.decorators import ajax_method, ajax_login_required import logging def vote(request, id):#refactor - pretty incomprehensible view used by various ajax calls diff --git a/forum/views/content.py b/forum/views/content.py index 9506fe3a..84fed42b 100644 --- a/forum/views/content.py +++ b/forum/views/content.py @@ -22,8 +22,8 @@ from django.template.defaultfilters import slugify from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse -from utils.html import sanitize_html -from utils.decorators import ajax_method, ajax_login_required +from forum.utils.html import sanitize_html +from forum.utils.decorators import ajax_method, ajax_login_required from markdown2 import Markdown #from lxml.html.diff import htmldiff from forum.diff import textDiff as htmldiff @@ -32,7 +32,7 @@ from forum.models import * from forum.auth import * from forum.const import * from forum import auth -from utils.forms import get_next_url +from forum.utils.forms import get_next_url # used in index page INDEX_PAGE_SIZE = 20 diff --git a/forum/views/meta.py b/forum/views/meta.py index 07e222b0..bb42f022 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect, HttpResponse from forum.forms import FeedbackForm from django.core.mail import mail_admins from django.utils.translation import ugettext as _ -from utils.forms import get_next_url +from forum.utils.forms import get_next_url from forum.models import Badge, Award def about(request): diff --git a/forum/views/readers.py b/forum/views/readers.py index 88b786aa..46e2885c 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -14,7 +14,7 @@ from django.utils.translation import ugettext as _ from django.template.defaultfilters import slugify from django.utils.datastructures import SortedDict -from utils.html import sanitize_html +from forum.utils.html import sanitize_html from markdown2 import Markdown #from lxml.html.diff import htmldiff from forum.diff import textDiff as htmldiff @@ -23,7 +23,7 @@ from forum.models import * from forum.auth import * from forum.const import * from forum import auth -from utils.forms import get_next_url +from forum.utils.forms import get_next_url # used in index page #refactor - move these numbers somewhere? diff --git a/forum/views/writers.py b/forum/views/writers.py index bb966b9f..666b936a 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -10,16 +10,17 @@ from django.template import RequestContext from django.utils.html import * from django.utils import simplejson from django.utils.translation import ugettext as _ +from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied -from utils.html import sanitize_html +from forum.utils.html import sanitize_html from markdown2 import Markdown from forum.forms import * from forum.models import * from forum.auth import * from forum.const import * from forum import auth -from utils.forms import get_next_url +from forum.utils.forms import get_next_url from forum.views.readers import _get_tags_cache_json # used in index page @@ -103,14 +104,14 @@ def ask(request):#view used to ask a new question if request.user.is_authenticated(): author = request.user - Question.objects.create_new( + question = Question.objects.create_new( title = title, author = author, added_at = added_at, wiki = wiki, tagnames = tagnames, summary = summary, - text = text + text = sanitize_html(markdowner.convert(text)) ) return HttpResponseRedirect(question.get_absolute_url()) @@ -348,7 +349,7 @@ def answer(request, id):#process a new answer author=request.user, added_at=update_time, wiki=wiki, - text=text, + text=sanitize_html(markdowner.convert(text)), email_notify=form.cleaned_data['email_notify'] ) else: diff --git a/settings.py b/settings.py index b384e3fa..426a12ff 100755 --- a/settings.py +++ b/settings.py @@ -24,9 +24,9 @@ MIDDLEWARE_CLASSES = [ #'django.middleware.cache.FetchFromCacheMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', #'django.middleware.sqlprint.SqlPrintingMiddleware', - 'middleware.anon_user.ConnectToSessionMessagesMiddleware', - 'middleware.pagesize.QuestionsPageSizeMiddleware', - 'middleware.cancel.CancelActionMiddleware', + 'forum.middleware.anon_user.ConnectToSessionMessagesMiddleware', + 'forum.middleware.pagesize.QuestionsPageSizeMiddleware', + 'forum.middleware.cancel.CancelActionMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', 'recaptcha_django.middleware.ReCaptchaMiddleware', 'django.middleware.transaction.TransactionMiddleware', diff --git a/settings_local.py.dist b/settings_local.py.dist new file mode 100755 index 00000000..3a71b389 --- /dev/null +++ b/settings_local.py.dist @@ -0,0 +1,110 @@ +# encoding:utf-8
+import os.path
+from django.utils.translation import ugettext as _
+
+def check_local_setting(name, value):
+ local_vars = locals()
+ if name in local_vars and local_vars[name] == value:
+ return True
+ else:
+ return False
+
+SITE_SRC_ROOT = os.path.dirname(__file__)
+LOG_FILENAME = 'django.osqa.log'
+
+#for logging
+import logging
+logging.basicConfig(
+ filename=os.path.join(SITE_SRC_ROOT, 'log', LOG_FILENAME),
+ level=logging.DEBUG,
+ format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',
+)
+
+#ADMINS and MANAGERS
+ADMINS = (('Forum Admin', 'forum@example.com'),)
+MANAGERS = ADMINS
+
+#DEBUG SETTINGS
+DEBUG = False
+TEMPLATE_DEBUG = DEBUG
+INTERNAL_IPS = ('127.0.0.1',)
+
+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
+DATABASE_HOST = ''
+DATABASE_PORT = ''
+
+#Moved from settings.py for better organization. (please check it up to clean up settings.py)
+
+#email server settings
+SERVER_EMAIL = ''
+DEFAULT_FROM_EMAIL = ''
+EMAIL_HOST_USER = ''
+EMAIL_HOST_PASSWORD = ''
+EMAIL_SUBJECT_PREFIX = '[OSQA] '
+EMAIL_HOST='osqa.net'
+EMAIL_PORT='25'
+EMAIL_USE_TLS=False
+
+#LOCALIZATIONS
+TIME_ZONE = 'America/New_York'
+
+###########################
+#
+# this will allow running your forum with url like http://site.com/forum
+#
+# FORUM_SCRIPT_ALIAS = 'forum/'
+#
+FORUM_SCRIPT_ALIAS = '' #no leading slash, default = '' empty string
+
+
+#OTHER SETTINGS
+APP_TITLE = u'OSQA: Open Source Q&A Forum'
+APP_SHORT_NAME = u'OSQA'
+APP_KEYWORDS = u'OSQA,CNPROG,forum,community'
+APP_DESCRIPTION = u'Ask and answer questions.'
+APP_INTRO = u'<p>Ask and answer questions, make the world better!</p>'
+APP_COPYRIGHT = 'Copyright OSQA, 2009. Some rights reserved under creative commons license.'
+LOGIN_URL = '/%s%s%s' % (FORUM_SCRIPT_ALIAS,'account/','signin/')
+GREETING_URL = LOGIN_URL #may be url of "faq" page or "about", etc
+
+USE_I18N = True
+LANGUAGE_CODE = 'en'
+EMAIL_VALIDATION = 'off' #string - on|off
+MIN_USERNAME_LENGTH = 1
+EMAIL_UNIQUE = False
+APP_URL = 'http://osqa.net' #used by email notif system and RSS
+GOOGLE_SITEMAP_CODE = ''
+GOOGLE_ANALYTICS_KEY = ''
+BOOKS_ON = False
+WIKI_ON = True
+USE_EXTERNAL_LEGACY_LOGIN = False
+EXTERNAL_LEGACY_LOGIN_HOST = 'login.osqa.net'
+EXTERNAL_LEGACY_LOGIN_PORT = 80
+EXTERNAL_LEGACY_LOGIN_PROVIDER_NAME = '<span class="orange">OSQA</span>'
+FEEDBACK_SITE_URL = None #None or url
+EDITABLE_SCREEN_NAME = False #True or False - can user change screen name?
+
+DJANGO_VERSION = 1.1
+RESOURCE_REVISION=4
+
+USE_SPHINX_SEARCH = False #if True all SPHINX_* settings are required
+#also sphinx search engine and djangosphinxs app must be installed
+#sample sphinx configuration file is /sphinx/sphinx.conf
+SPHINX_API_VERSION = 0x113 #refer to djangosphinx documentation
+SPHINX_SEARCH_INDICES=('osqa',) #a tuple of index names remember about a comma after the
+#last item, especially if you have just one :)
+SPHINX_SERVER='localhost'
+SPHINX_PORT=3312
+
+#please get these at recaptcha.net
+RECAPTCHA_PRIVATE_KEY='...'
+RECAPTCHA_PUBLIC_KEY='...'
+OSQA_DEFAULT_SKIN = 'default'
+
+#Facebook settings
+USE_FB_CONNECT=False
+FB_API_KEY='' #your api key from facebook
+FB_SECRET='' #your application secret
|