From: hernani Date: Sat, 8 May 2010 15:17:55 +0000 (+0000) Subject: Fix on error with decoding settings from database. Ans dome other stuff. X-Git-Tag: live~957 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/87e592dc4c9e0321635350da8c9f1624554a604f?ds=sidebyside Fix on error with decoding settings from database. Ans dome other stuff. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@172 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/__init__.py b/forum/__init__.py index 85cd5d2..8b13789 100644 --- a/forum/__init__.py +++ b/forum/__init__.py @@ -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 index b44ed04..0000000 --- a/forum/const.py +++ /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')), -) diff --git a/forum/feed.py b/forum/feed.py index 4017d61..02a7d3c 100644 --- a/forum/feed.py +++ b/forum/feed.py @@ -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 diff --git a/forum/forms.py b/forum/forms.py index bf14d54..2196981 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -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) diff --git a/forum/management/commands/base_command.py b/forum/management/commands/base_command.py index c073bf7..4a8a4b6 100644 --- a/forum/management/commands/base_command.py +++ b/forum/management/commands/base_command.py @@ -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): diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index ba1d943..4b6a05f 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -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): diff --git a/forum/models/base.py b/forum/models/base.py index 56124a8..676f1c7 100644 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -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): diff --git a/forum/models/user.py b/forum/models/user.py index ff7bef1..3e92e16 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -1,5 +1,4 @@ from base import * -from forum import const from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser from django.db.models import Q @@ -151,12 +150,9 @@ class User(BaseModel, DjangoUser): def get_reputation_by_upvoted_today(self): today = datetime.datetime.now() - sum = self.reputes.filter( - models.Q(reputation_type=TYPE_REPUTATION_GAIN_BY_UPVOTED) | - models.Q(reputation_type=TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED), - reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value')) - - if sum.get('value__sum', None) is not None: return sum['value__sum'] + sum = self.reputes.filter(reputed_at__range=(today - datetime.timedelta(days=1), today)).aggregate(models.Sum('value')) + #todo: redo this, maybe transform in the daily cap + #if sum.get('value__sum', None) is not None: return sum['value__sum'] return 0 def get_flagged_items_count_today(self): @@ -248,10 +244,10 @@ class SubscriptionSettings(models.Model): enable_notifications = models.BooleanField(default=True) #notify if - member_joins = models.CharField(max_length=1, default='n', choices=const.NOTIFICATION_CHOICES) - new_question = models.CharField(max_length=1, default='d', choices=const.NOTIFICATION_CHOICES) - new_question_watched_tags = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES) - subscribed_questions = models.CharField(max_length=1, default='i', choices=const.NOTIFICATION_CHOICES) + member_joins = models.CharField(max_length=1, default='n') + new_question = models.CharField(max_length=1, default='d') + new_question_watched_tags = models.CharField(max_length=1, default='i') + subscribed_questions = models.CharField(max_length=1, default='i') #auto_subscribe_to all_questions = models.BooleanField(default=False) diff --git a/forum/settings/about.py b/forum/settings/about.py index 45c8857..d8e6a27 100644 --- a/forum/settings/about.py +++ b/forum/settings/about.py @@ -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** diff --git a/forum/settings/base.py b/forum/settings/base.py index 08f3ea8..5bcf5fc 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -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) diff --git a/forum/settings/basic.py b/forum/settings/basic.py index 23427ea..2952bd7 100644 --- a/forum/settings/basic.py +++ b/forum/settings/basic.py @@ -18,28 +18,28 @@ label = _("Favicon"), help_text = _("Your site favicon."), widget=ImageFormWidget)) -APP_TITLE = Setting('APP_TITLE', 'OSQA: Open Source Q&A Forum', BASIC_SET, dict( +APP_TITLE = Setting('APP_TITLE', u'OSQA: Open Source Q&A Forum', BASIC_SET, dict( label = _("Application title"), help_text = _("The title of your application that will show in the browsers title bar"))) -APP_SHORT_NAME = Setting('APP_SHORT_NAME', 'OSQA', BASIC_SET, dict( +APP_SHORT_NAME = Setting(u'APP_SHORT_NAME', 'OSQA', BASIC_SET, dict( label = _("Application short name"), help_text = "The short name for your application that will show up in many places.")) -APP_KEYWORDS = Setting('APP_KEYWORDS', 'OSQA,CNPROG,forum,community', BASIC_SET, dict( +APP_KEYWORDS = Setting('APP_KEYWORDS', u'OSQA,CNPROG,forum,community', BASIC_SET, dict( label = _("Application keywords"), help_text = _("The meta keywords that will be available through the HTML meta tags."))) -APP_DESCRIPTION = Setting('APP_DESCRIPTION', 'Ask and answer questions.', BASIC_SET, dict( +APP_DESCRIPTION = Setting('APP_DESCRIPTION', u'Ask and answer questions.', BASIC_SET, dict( label = _("Application description"), help_text = _("The description of your application"), widget=Textarea)) -APP_INTRO = Setting('APP_INTRO', '

Ask and answer questions, make the world better!

', BASIC_SET, dict( +APP_INTRO = Setting('APP_INTRO', u'

Ask and answer questions, make the world better!

', BASIC_SET, dict( label = _("Application intro"), help_text = _("The introductory page that is visible in the sidebar for anonymous users."), widget=Textarea)) -APP_COPYRIGHT = Setting('APP_COPYRIGHT', 'Copyright OSQA, 2010. Some rights reserved under creative commons license.', BASIC_SET, dict( +APP_COPYRIGHT = Setting('APP_COPYRIGHT', u'Copyright OSQA, 2010. Some rights reserved under creative commons license.', BASIC_SET, dict( label = _("Copyright notice"), help_text = _("The copyright notice visible at the footer of your page."))) \ No newline at end of file diff --git a/forum/settings/faq.py b/forum/settings/faq.py index 09c1d8c..e3dccd6 100644 --- a/forum/settings/faq.py +++ b/forum/settings/faq.py @@ -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)** diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index a6c9047..e519504 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -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 diff --git a/forum/templatetags/user_tags.py b/forum/templatetags/user_tags.py index 3ca19ac..960bd53 100644 --- a/forum/templatetags/user_tags.py +++ b/forum/templatetags/user_tags.py @@ -1,7 +1,6 @@ from django import template from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe -from forum import const register = template.Library() diff --git a/forum/views/admin.py b/forum/views/admin.py index 32bee10..ca0f813 100644 --- a/forum/views/admin.py +++ b/forum/views/admin.py @@ -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)) diff --git a/forum/views/commands.py b/forum/views/commands.py index 8591930..452d57d 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -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 diff --git a/forum/views/readers.py b/forum/views/readers.py index c192820..b199bea 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -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 diff --git a/forum/views/writers.py b/forum/views/writers.py index 98b523e..980357e 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -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 - #%s xml_template = "%s" try: diff --git a/settings.py b/settings.py index 1a9f7e1..a7c5893 100644 --- a/settings.py +++ b/settings.py @@ -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',] diff --git a/settings_local.py.dist b/settings_local.py.dist index ac14d84..aab362a 100644 --- a/settings_local.py.dist +++ b/settings_local.py.dist @@ -24,7 +24,7 @@ logging.basicConfig( ADMINS = (('Forum Admin', 'forum@example.com'),) MANAGERS = ADMINS -DEBUG = True +DEBUG = False DEBUG_TOOLBAR_CONFIG = { 'INTERCEPT_REDIRECTS': True }