]> git.openstreetmap.org Git - osqa.git/commitdiff
Fix on error with decoding settings from database. Ans dome other stuff.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 8 May 2010 15:17:55 +0000 (15:17 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 8 May 2010 15:17:55 +0000 (15:17 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@172 0cfe37f9-358a-4d5e-be75-b63607b5c754

20 files changed:
forum/__init__.py
forum/const.py [deleted file]
forum/feed.py
forum/forms.py
forum/management/commands/base_command.py
forum/management/commands/send_email_alerts.py
forum/models/base.py
forum/models/user.py
forum/settings/about.py
forum/settings/base.py
forum/settings/basic.py
forum/settings/faq.py
forum/templatetags/extra_tags.py
forum/templatetags/user_tags.py
forum/views/admin.py
forum/views/commands.py
forum/views/readers.py
forum/views/writers.py
settings.py
settings_local.py.dist

index 85cd5d26f1fc2890c75d6ef07db9086cdd46376a..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1 +1 @@
-__all__ = ['admin','auth','const','feed','forms','managers','models','sitemap','urls','views']
+
diff --git a/forum/const.py b/forum/const.py
deleted file mode 100644 (file)
index b44ed04..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-# encoding:utf-8
-from django.utils.translation import ugettext as _
-"""
-All constants could be used in other modules
-For reasons that models, views can't have unicode text in this project, all unicode text go here.
-"""
-CLOSE_REASONS = (
-    (1, _('duplicate question')),
-    (2, _('question is off-topic or not relevant')),
-    (3, _('too subjective and argumentative')),
-    (4, _('is not an answer to the question')),
-    (5, _('the question is answered, right answer was accepted')),
-    (6, _('problem is not reproducible or outdated')),
-    (7, _('question contains offensive inappropriate, or malicious remarks')),
-    (8, _('spam or advertising')),
-)
-
-TYPE_REPUTATION_GAIN_BY_UPVOTED = 1
-TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED = 2
-TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER = 3
-TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED = 4
-TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE = 5
-TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER = -1
-TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED = -2
-TYPE_REPUTATION_LOST_BY_DOWNVOTED = -3
-TYPE_REPUTATION_LOST_BY_FLAGGED = -4
-TYPE_REPUTATION_LOST_BY_DOWNVOTING = -5
-TYPE_REPUTATION_LOST_BY_FLAGGED_3_TIMES = -6
-TYPE_REPUTATION_LOST_BY_FLAGGED_5_TIMES = -7
-TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED = -8
-
-TYPE_REPUTATION = (
-    (TYPE_REPUTATION_GAIN_BY_UPVOTED, 'gain_by_upvoted'),
-    (TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED, 'gain_by_answer_accepted'),
-    (TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER, 'gain_by_accepting_answer'),
-    (TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED, 'gain_by_downvote_canceled'),
-    (TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE, 'gain_by_canceling_downvote'),
-    (TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER, 'lose_by_canceling_accepted_answer'),
-    (TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED, 'lose_by_accepted_answer_cancled'),
-    (TYPE_REPUTATION_LOST_BY_DOWNVOTED, 'lose_by_downvoted'),
-    (TYPE_REPUTATION_LOST_BY_FLAGGED, 'lose_by_flagged'),
-    (TYPE_REPUTATION_LOST_BY_DOWNVOTING, 'lose_by_downvoting'),
-    (TYPE_REPUTATION_LOST_BY_FLAGGED_3_TIMES, 'lose_by_flagged_lastrevision_3_times'),
-    (TYPE_REPUTATION_LOST_BY_FLAGGED_5_TIMES, 'lose_by_flagged_lastrevision_5_times'),
-    (TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED, 'lose_by_upvote_canceled'),
-)
-
-TYPE_ACTIVITY_ASK_QUESTION=1
-TYPE_ACTIVITY_ANSWER=2
-TYPE_ACTIVITY_COMMENT_QUESTION=3
-TYPE_ACTIVITY_COMMENT_ANSWER=4
-TYPE_ACTIVITY_UPDATE_QUESTION=5
-TYPE_ACTIVITY_UPDATE_ANSWER=6
-TYPE_ACTIVITY_PRIZE=7
-TYPE_ACTIVITY_MARK_ANSWER=8
-TYPE_ACTIVITY_VOTE_UP=9
-TYPE_ACTIVITY_VOTE_DOWN=10
-TYPE_ACTIVITY_CANCEL_VOTE_UP=11
-TYPE_ACTIVITY_CANCEL_VOTE_DOWN=19
-TYPE_ACTIVITY_DELETE_QUESTION=12
-TYPE_ACTIVITY_DELETE_ANSWER=13
-TYPE_ACTIVITY_MARK_OFFENSIVE=14
-TYPE_ACTIVITY_UPDATE_TAGS=15
-TYPE_ACTIVITY_FAVORITE=16
-TYPE_ACTIVITY_USER_FULL_UPDATED = 17
-TYPE_ACTIVITY_QUESTION_EMAIL_UPDATE_SENT = 18
-#TYPE_ACTIVITY_EDIT_QUESTION=17
-#TYPE_ACTIVITY_EDIT_ANSWER=18
-
-TYPE_ACTIVITY = (
-    (TYPE_ACTIVITY_ASK_QUESTION, _('question')),
-    (TYPE_ACTIVITY_ANSWER, _('answer')),
-    (TYPE_ACTIVITY_COMMENT_QUESTION, _('commented question')),
-    (TYPE_ACTIVITY_COMMENT_ANSWER, _('commented answer')),
-    (TYPE_ACTIVITY_UPDATE_QUESTION, _('edited question')),
-    (TYPE_ACTIVITY_UPDATE_ANSWER, _('edited answer')),
-    (TYPE_ACTIVITY_PRIZE, _('received award')),
-    (TYPE_ACTIVITY_MARK_ANSWER, _('marked best answer')),
-    (TYPE_ACTIVITY_VOTE_UP, _('upvoted')),
-    (TYPE_ACTIVITY_VOTE_DOWN, _('downvoted')),
-    (TYPE_ACTIVITY_CANCEL_VOTE_UP, _('upvote canceled')),
-    (TYPE_ACTIVITY_CANCEL_VOTE_DOWN, _('downvote canceled')),
-    (TYPE_ACTIVITY_DELETE_QUESTION, _('deleted question')),
-    (TYPE_ACTIVITY_DELETE_ANSWER, _('deleted answer')),
-    (TYPE_ACTIVITY_MARK_OFFENSIVE, _('marked offensive')),
-    (TYPE_ACTIVITY_UPDATE_TAGS, _('updated tags')),
-    (TYPE_ACTIVITY_FAVORITE, _('selected favorite')),
-    (TYPE_ACTIVITY_USER_FULL_UPDATED, _('completed user profile')),
-    (TYPE_ACTIVITY_QUESTION_EMAIL_UPDATE_SENT, _('email update sent to user')),
-)
-
-TYPE_RESPONSE = {
-    'QUESTION_ANSWERED' : _('question_answered'),
-    'QUESTION_COMMENTED': _('question_commented'),
-    'ANSWER_COMMENTED'  : _('answer_commented'),
-    'ANSWER_ACCEPTED'   : _('answer_accepted'),
-}
-
-CONST = {
-    'closed'            : _('[closed]'),
-       'deleted'           : _('[deleted]'),
-    'default_version'   : _('initial version'),
-    'retagged'          : _('retagged'),
-}
-
-BRONZE_BADGE = 3
-SILVER_BADGE = 2
-GOLD_BADGE = 1
-
-NOTIFICATION_CHOICES = (
-    ('i', _('Instantly')),
-    ('d', _('Daily')),
-    ('w', _('Weekly')),
-    ('n', _('No notifications')),
-)
index 4017d61e35eec34146b2da441181ee23faf1a03b..02a7d3c432441278f19d67ba69636a9ab9b50281 100644 (file)
@@ -15,7 +15,7 @@ from django.utils.translation import ugettext as _
 from models import Question
 from django.conf import settings
 class RssLastestQuestionsFeed(Feed):
-    title = str(settings.APP_TITLE) + _(' - ')+ _('latest questions')
+    title = settings.APP_TITLE + _(' - ')+ _('latest questions')
     link = settings.APP_URL #+ '/' + _('question/')
     description = settings.APP_DESCRIPTION
     #ttl = 10
index bf14d54aed5e7aac2493d497b981f0810540ee78..2196981f6258c31e1c3ca373a7e45a66c0d4e2ce 100644 (file)
@@ -2,7 +2,6 @@ import re
 from datetime import date
 from django import forms
 from models import *
-from const import *
 from django.utils.translation import ugettext as _
 from django.contrib.humanize.templatetags.humanize import apnumber
 from forum.models import User
@@ -130,9 +129,6 @@ class AnswerForm(forms.Form):
             self.fields['wiki'].initial = True
 
 
-class CloseForm(forms.Form):
-    reason = forms.ChoiceField(choices=CLOSE_REASONS)
-
 class RetagQuestionForm(forms.Form):
     tags   = TagNamesField()
     # initialize the default values
@@ -233,6 +229,12 @@ class EditUserForm(forms.Form):
                     raise forms.ValidationError(_('this email has already been registered, please use another one'))
         return self.cleaned_data['email']
 
+NOTIFICATION_CHOICES = (
+    ('i', _('Instantly')),
+    ('d', _('Daily')),
+    ('w', _('Weekly')),
+    ('n', _('No notifications')),
+)
 
 class SubscriptionSettingsForm(forms.Form):
     member_joins = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES)
index c073bf7a2e0b1044c4ebdf20b86a3b9155b322c6..4a8a4b60f3b778bbafbad0df824089f2b479cdae 100644 (file)
@@ -19,7 +19,6 @@ from django.shortcuts import get_object_or_404
 from django.contrib.contenttypes.models import ContentType
 
 from forum.models import *
-from forum.const import *
 
 class BaseCommand(NoArgsCommand):
     def update_activities_auditted(self, cursor, activity_ids):
index ba1d9436d49635c02b10fc22901c51717acd54dc..4b6a05f761be026c26d2dc8e98a76c127d130960 100644 (file)
@@ -6,7 +6,6 @@ from django.core.mail import EmailMultiAlternatives
 from django.conf import settings
 from forum.models import KeyValue, Activity, User, QuestionSubscription
 from forum.utils.mail import send_email
-from forum import const
 
 class QuestionRecord:
     def __init__(self, question):
index 56124a82e9a66be5d37f5fee8f883e30c4a0dcc3..676f1c7b6258a54b41c3c3e5739bf6208fcbf7b9 100644 (file)
@@ -15,10 +15,8 @@ from django.utils.safestring import mark_safe
 from django.contrib.sitemaps import ping_google
 import django.dispatch
 from django.conf import settings
-from forum import const
 import logging
 
-from forum.const import *
 
 class LazyQueryList(object):
     def __init__(self, model, items):
index ff7bef1d2f011ede2e96f9b233598904e2b3f529..3e92e1670c6d2fa548dfc4df184a2825fbce746b 100644 (file)
@@ -1,5 +1,4 @@
 from base import *\r
-from forum import const\r
 from django.contrib.contenttypes.models import ContentType\r
 from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser\r
 from django.db.models import Q\r
@@ -151,12 +150,9 @@ class User(BaseModel, DjangoUser):
 \r
     def get_reputation_by_upvoted_today(self):\r
         today = datetime.datetime.now()\r
-        sum = self.reputes.filter(\r
-                models.Q(reputation_type=TYPE_REPUTATION_GAIN_BY_UPVOTED) |\r
-                models.Q(reputation_type=TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED),\r
-                reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value'))\r
-\r
-        if sum.get('value__sum', None) is not None: return sum['value__sum']\r
+        sum = self.reputes.filter(reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value'))\r
+        #todo: redo this, maybe transform in the daily cap\r
+        #if sum.get('value__sum', None) is not None: return sum['value__sum']\r
         return 0\r
 \r
     def get_flagged_items_count_today(self):\r
@@ -248,10 +244,10 @@ class SubscriptionSettings(models.Model):
     enable_notifications = models.BooleanField(default=True)\r
 \r
     #notify if\r
-    member_joins = models.CharField(max_length=1, default='n', choices=const.NOTIFICATION_CHOICES)\r
-    new_question = models.CharField(max_length=1, default='d', choices=const.NOTIFICATION_CHOICES)\r
-    new_question_watched_tags = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES)\r
-    subscribed_questions = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES)\r
+    member_joins = models.CharField(max_length=1, default='n')\r
+    new_question = models.CharField(max_length=1, default='d')\r
+    new_question_watched_tags = models.CharField(max_length=1, default='i')\r
+    subscribed_questions = models.CharField(max_length=1, default='i')\r
     \r
     #auto_subscribe_to\r
     all_questions = models.BooleanField(default=False)\r
index 45c88579a637a83338c2e96d104e5edf68c39ba9..d8e6a27d707f6dbbe16caace288b4919f5b26998 100644 (file)
@@ -4,7 +4,7 @@ from django.forms.widgets import Textarea
 PAGES_SET = SettingSet('about', 'About page', "Define the text in the about page. You can use markdown and some basic html tags.", 2000, True)
 
 ABOUT_PAGE_TEXT = Setting('ABOUT_PAGE_TEXT',
-"""
+u"""
 **Please customize this text in the administration area**
 
 Here you can **ask** and **answer** questions, **comment**
index 08f3ea8b60ca66504b9eb7477c30f3818356d717..5bcf5fc51a6d929c6c82209c15ca2a3b1d22e9a9 100644 (file)
@@ -29,6 +29,9 @@ class BaseSetting(object):
 
             Setting.sets[set.name].append(self)
 
+    def __str__(self):
+        return str(self.value)
+
     def __unicode__(self):
         return unicode(self.value)
 
index 23427ea0fed8253fdc1703b5e8f627efbc579ab2..2952bd79d34676cd7ef1ba864241c1dd6681a99f 100644 (file)
@@ -18,28 +18,28 @@ label = _("Favicon"),
 help_text = _("Your site favicon."),\r
 widget=ImageFormWidget))\r
 \r
-APP_TITLE = Setting('APP_TITLE', 'OSQA: Open Source Q&A Forum', BASIC_SET, dict(\r
+APP_TITLE = Setting('APP_TITLE', u'OSQA: Open Source Q&A Forum', BASIC_SET, dict(\r
 label = _("Application title"),\r
 help_text = _("The title of your application that will show in the browsers title bar")))\r
 \r
-APP_SHORT_NAME = Setting('APP_SHORT_NAME', 'OSQA', BASIC_SET, dict(\r
+APP_SHORT_NAME = Setting(u'APP_SHORT_NAME', 'OSQA', BASIC_SET, dict(\r
 label = _("Application short name"),\r
 help_text = "The short name for your application that will show up in many places."))\r
 \r
-APP_KEYWORDS = Setting('APP_KEYWORDS', 'OSQA,CNPROG,forum,community', BASIC_SET, dict(\r
+APP_KEYWORDS = Setting('APP_KEYWORDS', u'OSQA,CNPROG,forum,community', BASIC_SET, dict(\r
 label = _("Application keywords"),\r
 help_text = _("The meta keywords that will be available through the HTML meta tags.")))\r
 \r
-APP_DESCRIPTION = Setting('APP_DESCRIPTION', 'Ask and answer questions.', BASIC_SET, dict(\r
+APP_DESCRIPTION = Setting('APP_DESCRIPTION', u'Ask and answer questions.', BASIC_SET, dict(\r
 label = _("Application description"),\r
 help_text = _("The description of your application"),\r
 widget=Textarea))\r
 \r
-APP_INTRO = Setting('APP_INTRO', '<p>Ask and answer questions, make the world better!</p>', BASIC_SET, dict(\r
+APP_INTRO = Setting('APP_INTRO', u'<p>Ask and answer questions, make the world better!</p>', BASIC_SET, dict(\r
 label = _("Application intro"),\r
 help_text = _("The introductory page that is visible in the sidebar for anonymous users."),\r
 widget=Textarea))\r
 \r
-APP_COPYRIGHT = Setting('APP_COPYRIGHT', 'Copyright OSQA, 2010. Some rights reserved under creative commons license.', BASIC_SET, dict(\r
+APP_COPYRIGHT = Setting('APP_COPYRIGHT', u'Copyright OSQA, 2010. Some rights reserved under creative commons license.', BASIC_SET, dict(\r
 label = _("Copyright notice"),\r
 help_text = _("The copyright notice visible at the footer of your page.")))
\ No newline at end of file
index 09c1d8c935c6c611e9b7647a79274b9666329839..e3dccd6b2d5c8d19b96715cf9bb5e2188e38d08f 100644 (file)
@@ -4,7 +4,7 @@ from django.forms.widgets import Textarea
 FAQ_SET = SettingSet('faq', 'FAQ page', "Define the text in the about page. You can use markdown and some basic html tags.", 2000, True)
 
 FAQ_PAGE_TEXT = Setting('FAQ_PAGE_TEXT',
-"""
+u"""
 **Please customize this text in the administration area**
 
 **Frequently Asked Questions (FAQ)**
index a6c9047dbcccd9c8d263b4092be29a1ba0367b1c..e51950411cc65f9369c4b774fb0d768eea4ce91f 100644 (file)
@@ -8,7 +8,6 @@ import logging
 from django import template
 from django.utils.encoding import smart_unicode
 from django.utils.safestring import mark_safe
-from forum.const import *
 from forum.models import Question, Answer, QuestionRevision, AnswerRevision, NodeRevision
 from django.utils.translation import ugettext as _
 from django.utils.translation import ungettext
index 3ca19ac4b7aad12bf06ad4e5212bae5aff54df48..960bd5333a0975de3aa52e5afae880aa92715332 100644 (file)
@@ -1,7 +1,6 @@
 from django import template\r
 from django.utils.translation import ugettext as _\r
 from django.utils.safestring import mark_safe\r
-from forum import const\r
 \r
 register = template.Library()\r
 \r
index 32bee103e90f30399e58775bbfdaf590a520f1a8..ca0f81357359dfa31154091eafe0b7a4f4a9e7f7 100644 (file)
@@ -11,7 +11,6 @@ from forum.settings.base import Setting
 from forum.settings.forms import SettingsSetForm
 
 from forum.models import Question, Answer, User, Node, Action
-from forum import const
 from forum import settings
 
 def super_user_required(fn):
@@ -27,7 +26,7 @@ def super_user_required(fn):
 def index(request):
     return render_to_response('osqaadmin/index.html', {
         'sets': get_all_sets(),
-        'settings_pack': str(settings.SETTINGS_PACK),
+        'settings_pack': unicode(settings.SETTINGS_PACK),
         'statistics': get_statistics(),
         'recent_activity': get_recent_activity(),
     }, context_instance=RequestContext(request))
index 8591930c7ae2233543ae7c3ac15d1466fbaf6cc1..452d57d0f0f0022c02667c195030ca4bc19f3f4d 100644 (file)
@@ -7,7 +7,6 @@ from django.shortcuts import get_object_or_404, render_to_response
 from django.utils.translation import ungettext, ugettext as _
 from django.template import RequestContext
 from forum.models import *
-from forum.forms import CloseForm
 from forum.actions import *
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
index c19282042d6bca2eee471e093cc163dfcc663f45..b199bea2cf850837c605f2541f92c2a132df0e05 100644 (file)
@@ -24,7 +24,6 @@ from forum.utils.html import sanitize_html
 from forum.utils.diff import textDiff as htmldiff
 from forum.forms import *
 from forum.models import *
-from forum.const import *
 from forum.utils.forms import get_next_url
 from forum.actions import QuestionViewAction
 from forum.modules.decorators import decoratable
index 98b523e6f0eb85ca912b06a82a1a2d2220ada89d..980357e3531442f93d0012bb7687a81adcfdb9a1 100644 (file)
@@ -16,7 +16,6 @@ from django.core.exceptions import PermissionDenied
 from forum.actions import AskAction, AnswerAction, ReviseAction, RollbackAction, RetagAction
 from forum.forms import *
 from forum.models import *
-from forum.const import *
 from forum.utils.forms import get_next_url
 from forum.views.commands import SpamNotAllowedException
 
@@ -29,7 +28,6 @@ def upload(request):#ajax upload file to a question or answer
     class UploadPermissionNotAuthorized(Exception):
         pass
 
-    #<result><msg><![CDATA[%s]]></msg><error><![CDATA[%s]]></error><file_url>%s</file_url></result>
     xml_template = "<result><msg><![CDATA[%s]]></msg><error><![CDATA[%s]]></error><file_url>%s</file_url></result>"
 
     try:
index 1a9f7e169dd56cf885ddb7a38f32bb60c01c06bf..a7c589300508523648a62fe07d68b59b85765799 100644 (file)
@@ -85,10 +85,11 @@ try:
 except:
     pass
 
-try:
-    import rosetta
-    INSTALLED_APPS.append('rosetta')
-except:
-    pass
+if not DEBUG:
+    try:
+        import rosetta
+        INSTALLED_APPS.append('rosetta')
+    except:
+        pass
 
 AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend',]
index ac14d8450f79e91fbae80ef7c2027b23658cea23..aab362a696d4513022fb40a9eb9d5dcdab1265b8 100644 (file)
@@ -24,7 +24,7 @@ logging.basicConfig(
 ADMINS = (('Forum Admin', 'forum@example.com'),)
 MANAGERS = ADMINS
 
-DEBUG = True
+DEBUG = False
 DEBUG_TOOLBAR_CONFIG = {
     'INTERCEPT_REDIRECTS': True
 }