]> git.openstreetmap.org Git - osqa.git/commitdiff
Reverting the merges due to unsuccessfull conflict resolvement.
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 10 Mar 2011 22:36:25 +0000 (22:36 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 10 Mar 2011 22:36:25 +0000 (22:36 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@818 0cfe37f9-358a-4d5e-be75-b63607b5c754

29 files changed:
forum/authentication/__init__.py
forum/http_responses.py
forum/management/commands/module_command.py [deleted file]
forum/models/node.py
forum/models/question.py
forum/models/tag.py
forum/models/user.py
forum/modules/__init__.py
forum/modules/decorators.py
forum/modules/template_loader.py [deleted file]
forum/registry.py
forum/skins/__init__.py
forum/skins/default/templates/base_content.html
forum/skins/default/templates/node/award_points.html [deleted file]
forum/templatetags/node_tags.py
forum/templatetags/ui_registry.py
forum/urls.py
forum/utils/userlinking.py
forum/views/auth.py
forum/views/commands.py
forum/views/meta.py
forum/views/readers.py
forum/views/vars.py [deleted file]
forum/views/writers.py
forum_modules/openidauth/consumer.py
forum_modules/sximporter/importer.py
forum_modules/sximporter/views.py
settings.py
urls.py

index 79c47a8dd2e05908b96e2e7ea438a2cf72372576..8dbf825a525c2ab49c17a38834961ac6135706ce 100644 (file)
@@ -8,8 +8,7 @@ class ConsumerAndContext:
         self.id = id
         self._consumer = consumer
 
-        if context:
-            context.id = id
+        context.id = id
         self.context = context
 
     @property
@@ -28,7 +27,7 @@ contexts = dict([
         ])
 
 AUTH_PROVIDERS = dict([
-            (name, ConsumerAndContext(name, consumers[name], contexts.get(name, None))) for name in consumers.keys()
+            (name, ConsumerAndContext(name, consumers[name], contexts[name])) for name in consumers.keys()
+            if name in contexts
         ])
 
-
index 2ff4866fdb89a89e9efea173bb47e1f3e468ca9c..7fae3b69f3bd63b9d60fc93f91b733633e8af2a8 100644 (file)
@@ -24,18 +24,4 @@ class HttpResponseUnauthorized(HttpResponse):
             super(HttpResponseUnauthorized, self).__init__(
                 content=render_to_string('401.html', context_instance=RequestContext(request)),
                 status=401
-            )
-
-class HttpResponseNotFound(HttpResponse):
-    def __init__(self, request):
-        super(HttpResponseNotFound, self).__init__(
-            content=render_to_string('404.html', context_instance=RequestContext(request)),
-            status=404
-        )
-
-class HttpResponseIntServerError(HttpResponse):
-    def __init__(self, request):
-        super(HttpResponseIntServerError, self).__init__(
-            content=render_to_string('500.html', context_instance=RequestContext(request)),
-            status=500
-        )
\ No newline at end of file
+            )
\ No newline at end of file
diff --git a/forum/management/commands/module_command.py b/forum/management/commands/module_command.py
deleted file mode 100644 (file)
index 378d15a..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-from django.core.management.base import BaseCommand, CommandError
-
-class Command(BaseCommand):
-
-    def handle(self, *args, **options):
-
-        for path in args:
-            m = __import__('forum_modules.%s' % path, globals(), locals(), ['forum_modules'])
-
-            if hasattr(m, 'run'):
-                run = getattr(m, 'run')
-                if callable(run):
-                    run()
index 74490829b46245097af166dca69c0632e5ec812a..abd1f5a3b402f8cf946c1cdf626e77fb91c93dbc 100644 (file)
@@ -8,7 +8,6 @@ from django.utils.safestring import mark_safe
 from django.utils.html import strip_tags
 from forum.utils.html import sanitize_html
 from forum.settings import SUMMARY_LENGTH
-from forum.modules import MODULES_PACKAGE
 from utils import PickledObjectField
 
 class NodeContent(models.Model):
@@ -143,30 +142,12 @@ class NodeManager(CachedManager):
     use_for_related_fields = True
 
     def get_query_set(self):
-        CurrentUserHolder = None
-
-        moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE
-        exec moderation_import
-
         qs = NodeQuerySet(self.model)
 
         if self.model is not Node:
-            qs = qs.filter(node_type=self.model.get_type())
-
-        if CurrentUserHolder is not None:
-            user = CurrentUserHolder.user
-
-            try:
-                filter_content = not user.is_staff and not user.is_superuser
-            except:
-                filter_content = True
-
-            if filter_content:
-                qs = qs.exclude(state_string__contains="(in_moderation)").exclude(state_string__contains="(deleted)").exclude(
-                    state_string__contains="(rejected)"
-                )
-
-        return qs
+            return qs.filter(node_type=self.model.get_type())
+        else:
+            return qs
 
     def get_for_types(self, types, *args, **kwargs):
         kwargs['node_type__in'] = [t.get_type() for t in types]
index ef4a37d814390a25f4de23734991570947db755c..bef5bb511b544546ca8acf21ea4746ad4196efb5 100644 (file)
@@ -2,6 +2,8 @@ from base import *
 from tag import Tag
 from django.utils.translation import ugettext as _
 
+question_view = django.dispatch.Signal(providing_args=['instance', 'user'])
+
 class QuestionManager(NodeManager):
     def search(self, keywords):
         return False, self.filter(models.Q(title__icontains=keywords) | models.Q(body__icontains=keywords))
@@ -76,6 +78,12 @@ class Question(Node):
         
         return active_users
 
+def question_viewed(instance, **kwargs):
+    instance.extra_count += 1
+    instance.save()
+
+question_view.connect(question_viewed)
+
 
 class QuestionSubscription(models.Model):
     user = models.ForeignKey(User)
index 2a3609a9636d6f4cd6fdbe2f7461620a5162ef48..44e0a749aa40f0bdbd6fe274c59f374dc55c774f 100644 (file)
@@ -1,36 +1,13 @@
 import datetime
 from base import *
 
-from forum.modules import MODULES_PACKAGE
-
 from django.utils.translation import ugettext as _
 import django.dispatch
 
 class ActiveTagManager(models.Manager):
     def get_query_set(self):
-        qs = super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1)
-
-        CurrentUserHolder = None
-
-        moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE
-        exec moderation_import
-
-        if CurrentUserHolder is not None:
-            user = CurrentUserHolder.user
-
-            try:
-                filter_content = not user.is_staff and not user.is_superuser
-            except:
-                filter_content = True
-
-            if filter_content:
-                moderation_import = 'from %s.moderation.hooks import get_tag_ids' % MODULES_PACKAGE
-                exec moderation_import
-                qs = qs.exclude(id__in=get_tag_ids('deleted')).exclude(id__in=get_tag_ids('rejected')).exclude(
-                    id__in=get_tag_ids('in_moderation')
-                )
+        return super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1)
 
-        return qs
 
 class Tag(BaseModel):
     name            = models.CharField(max_length=255, unique=True)
@@ -41,7 +18,6 @@ class Tag(BaseModel):
     used_count = models.PositiveIntegerField(default=0)
 
     active = ActiveTagManager()
-    objects = ActiveTagManager()
 
     class Meta:
         ordering = ('-used_count', 'name')
index d96426e2ad909db291bb6140d5377cda70686c5d..9d6324875f9273c6d9ab5da77290f7bb5c4645e9 100644 (file)
@@ -15,6 +15,12 @@ from random import Random
 from django.utils.translation import ugettext as _
 import logging
 
+QUESTIONS_PER_PAGE_CHOICES = (
+(10, u'10'),
+(30, u'30'),
+(50, u'50'),
+)
+
 class AnonymousUser(DjangoAnonymousUser):
     reputation = 0
     
@@ -182,6 +188,9 @@ class User(BaseModel, DjangoUser):
             sub_settings = SubscriptionSettings(user=self)
             sub_settings.save()
 
+    def get_absolute_url(self):
+        return self.get_profile_url()
+
     def get_messages(self):
         messages = []
         for m in self.message_set.all():
index 976d9eb448a05fd2b2fa78e741ee9e4c59ae8993..cbac6eddcad1bc2a5951da0d53e61aea2c0e1313 100644 (file)
@@ -1,32 +1,29 @@
 import os
 import types
+import re
 import logging
 
-MODULES_PACKAGE = 'forum_modules'
+from django.template import Template, TemplateDoesNotExist
+from django.conf import settings
 
-MODULES_FOLDER = None
-MODULE_LIST = []
+MODULES_PACKAGE = 'forum_modules'
 
+MODULES_FOLDER = os.path.join(os.path.dirname(__file__), '../../' + MODULES_PACKAGE)
 
-def init_modules_engine(site_src_root, disabled_modules):
-    MODULES_FOLDER = os.path.join(site_src_root, MODULES_PACKAGE)
+DISABLED_MODULES = getattr(settings, 'DISABLED_MODULES', [])
 
-    MODULE_LIST.extend(filter(lambda m: getattr(m, 'CAN_USE', True), [
-            __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules'])
-            for f in os.listdir(MODULES_FOLDER)
-            if os.path.isdir(os.path.join(MODULES_FOLDER, f)) and
-               os.path.exists(os.path.join(MODULES_FOLDER, "%s/__init__.py" % f)) and
-               not f in disabled_modules
-    ]))
+MODULE_LIST = filter(lambda m: getattr(m, 'CAN_USE', True), [
+        __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules'])
+        for f in os.listdir(MODULES_FOLDER)
+        if os.path.isdir(os.path.join(MODULES_FOLDER, f)) and
+           os.path.exists(os.path.join(MODULES_FOLDER, "%s/__init__.py" % f)) and
+           not f in DISABLED_MODULES
+])
 
 def get_modules_script(script_name):
     all = []
 
     for m in MODULE_LIST:
-        if hasattr(m, script_name):
-            all.append(getattr(m, script_name))
-            continue
-
         try:
             all.append(__import__('%s.%s' % (m.__name__, script_name), globals(), locals(), [m.__name__]))
         except ImportError, e:
@@ -35,7 +32,7 @@ def get_modules_script(script_name):
         except:
             import traceback
             msg = "Error importing %s from module %s: \n %s" % (
-                script_name, m, traceback.format_exc()
+                script_name, m.__name__, traceback.format_exc()
             )
             logging.error(msg)
 
@@ -91,4 +88,25 @@ def get_handler(name, default):
     all = get_all_handlers(name)
     return len(all) and all[0] or default
 
+module_template_re = re.compile('^modules\/(\w+)\/(.*)$')
+
+def module_templates_loader(name, dirs=None):
+    result = module_template_re.search(name)
+
+    if result is not None:
+        file_name = os.path.join(MODULES_FOLDER, result.group(1), 'templates', result.group(2))
+
+        if os.path.exists(file_name):
+            try:
+                f = open(file_name, 'r')
+                source = f.read()
+                f.close()
+                return (source, file_name)
+            except:
+                pass
+
+    raise TemplateDoesNotExist, name 
+
+module_templates_loader.is_usable = True
+
 from decorators import decorate, ReturnImediatelyException
index 11af9e3d1c4c1cd49e60b04db024a9344f7269f9..3c53412dc0505c4c92bbe183a6709ca007dc5a34 100644 (file)
@@ -69,7 +69,7 @@ class ReturnImediatelyException(Exception):
         self.ret = ret\r
 \r
 def _check_decoratable(origin, install=True):\r
-    if not hasattr(origin, '_decoratable_obj'):\r
+    if not isinstance(origin, DecoratableObject):\r
         if inspect.ismethod(origin) and not hasattr(origin, '_decoratable_obj'):\r
             decoratable = DecoratableObject(origin)\r
 \r
@@ -91,18 +91,10 @@ def _check_decoratable(origin, install=True):
         elif inspect.isfunction(origin):\r
             decoratable = DecoratableObject(origin)\r
 \r
-            def decorated(*args, **kwargs):\r
-                return decoratable(*args, **kwargs)\r
-\r
-            decorated._decoratable_obj = decoratable\r
-\r
             if install:\r
-                setattr(inspect.getmodule(origin), origin.__name__, decorated)\r
-\r
-            decorated.__name__ = origin.__name__\r
-            decorated.__module__ = origin.__module__\r
+                setattr(inspect.getmodule(origin), origin.__name__, decoratable)\r
 \r
-            return decorated\r
+            return decoratable\r
 \r
     return origin\r
 \r
@@ -111,7 +103,7 @@ def decorate(origin, needs_origin=True):
     origin = _check_decoratable(origin)\r
 \r
     def decorator(fn):\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=needs_origin)\r
+        origin._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=needs_origin)\r
         \r
     return decorator\r
 \r
@@ -120,7 +112,7 @@ def _decorate_params(origin):
     origin = _check_decoratable(origin)\r
 \r
     def decorator(fn):\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_PARAMS)\r
+        origin._decorate(fn, DecoratableObject.MODE_PARAMS)\r
 \r
     return decorator\r
 \r
@@ -130,7 +122,7 @@ def _decorate_result(origin, needs_params=False):
     origin = _check_decoratable(origin)\r
 \r
     def decorator(fn):\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params)\r
+        origin._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params)\r
 \r
     return decorator\r
 \r
@@ -139,7 +131,7 @@ decorate.result = _decorate_result
 def _decorate_with(fn):\r
     def decorator(origin):\r
         origin = _check_decoratable(origin)\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=True)\r
+        origin._decorate(fn, DecoratableObject.MODE_OVERRIDE, needs_origin=True)\r
         return origin\r
     return decorator\r
 \r
@@ -148,7 +140,7 @@ decorate.withfn = _decorate_with
 def _decorate_result_with(fn, needs_params=False):\r
     def decorator(origin):\r
         origin = _check_decoratable(origin)\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params)\r
+        origin._decorate(fn, DecoratableObject.MODE_RESULT, needs_params=needs_params)\r
         return origin\r
     return decorator\r
 \r
@@ -157,7 +149,7 @@ decorate.result.withfn = _decorate_result_with
 def _decorate_params_with(fn):\r
     def decorator(origin):\r
         origin = _check_decoratable(origin)\r
-        origin._decoratable_obj._decorate(fn, DecoratableObject.MODE_PARAMS)\r
+        origin._decorate(fn, DecoratableObject.MODE_PARAMS)\r
         return origin\r
     return decorator\r
 \r
diff --git a/forum/modules/template_loader.py b/forum/modules/template_loader.py
deleted file mode 100644 (file)
index 61cb44e..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-import os, re
-
-from forum.skins import load_template_source as skins_template_loader, Template, BaseTemplateLoader
-from forum import modules
-
-MODULES_TEMPLATE_PREFIX = 'modules/'
-NO_OVERRIDE_TEMPLATE_PREFIX = 'no_override/'
-MODULES_TEMPLATE_FOLDER = 'templates'
-MODULES_TEMPLATE_OVERRIDES_FOLDER = 'template_overrides'
-
-TEMPLATE_OVERRIDE_LOOKUP_PATHS = [f for f in [
-        os.path.join(os.path.dirname(m.__file__), MODULES_TEMPLATE_OVERRIDES_FOLDER) for m in modules.MODULE_LIST
-    ] if os.path.exists(f)
-]
-
-class ModulesTemplateLoader(BaseTemplateLoader):
-
-    modules_re = re.compile('^%s(\w+)\/(.*)$' % MODULES_TEMPLATE_PREFIX)
-
-    def load_template_source(self, name, dirs=None):
-        template = None
-
-        if name.startswith(MODULES_TEMPLATE_PREFIX):
-            match = self.modules_re.search(name)
-            file_name = os.path.join(modules.MODULES_FOLDER, match.group(1), MODULES_TEMPLATE_FOLDER, match.group(2))
-
-            if os.path.exists(file_name):
-                template = Template(file_name)
-
-        elif name.startswith(NO_OVERRIDE_TEMPLATE_PREFIX):
-            return skins_template_loader.load_template_source(name[len(NO_OVERRIDE_TEMPLATE_PREFIX):], dirs)
-
-        else:
-            for override_path in TEMPLATE_OVERRIDE_LOOKUP_PATHS:
-                file_name = os.path.join(override_path, name)
-
-                if os.path.exists(file_name):
-                    template = Template(file_name)
-                    break
-
-
-        return template
-
-module_templates_loader = ModulesTemplateLoader()
index aedf5b0d1b0e1dbcc4d773ff8a4d4c3a021cfb87..ff5a1157941eea91d21b19f5822fd89329bf6921 100644 (file)
@@ -1,19 +1,12 @@
-from forum.modules import ui, get_modules_script
+from forum.modules import ui
 from django.utils.translation import ugettext as _
 from django.core.urlresolvers import reverse
 from django.template.defaultfilters import slugify
-from django.template import get_templatetags_modules
 from forum.templatetags.extra_tags import get_score_badge
 from forum.utils.html import cleanup_urls
 from forum import settings
 
 
-modules_template_tags = get_modules_script('templatetags')
-django_template_tags = get_templatetags_modules()
-
-for m in modules_template_tags:
-    django_template_tags.append(m.__name__)
-
 ui.register(ui.HEADER_LINKS,
             ui.Link(_('faq'), ui.Url('faq'), weight=400),
             ui.Link(_('about'), ui.Url('about'), weight=300),
index 33e0097cc147f15054f95ec997ffb596f0b47ef0..7a7e0cdb7ca1d20624889f08c9586f55b857a117 100644 (file)
 from django.conf import settings
-from django.template.loaders import filesystem
-from django.template import TemplateDoesNotExist, Template as DJTemplate
-from django.conf import settings as djsettings
+from django.template import loader
+from django.template.loaders import filesystem 
+from django.http import HttpResponse
 import os.path
 import logging
 
-UNEXISTENT_TEMPLATE = object()
+#module for skinning osqa
+#at this point skin can be changed only in settings file
+#via OSQA_DEFAULT_SKIN variable
 
-SKINS_FOLDER = os.path.dirname(__file__)
-SKIN_TEMPLATES_FOLDER = 'templates'
-DEFAULT_SKIN_NAME = 'default'
-FORCE_DEFAULT_PREFIX = "%s/" % DEFAULT_SKIN_NAME
-
-
-class Template(object):
-
-    def __init__(self, file_name):
-        self._file_name = file_name
-        self._loaded = False
-
-    def _get_mtime(self):
-        return os.path.getmtime(self._file_name)
-
-    def _check_mtime(self):
-        if self._last_mtime is None:
-            return False
-
-        return self._last_mtime == self._get_mtime()
-
-    def _load(self):
-        try:
-            f = open(self._file_name, 'r')
-            self._source = f.read()
-            f.close()
-            self._loaded = True
-
-            self._last_mtime = self._get_mtime()
-        except:
-            self._loaded = False
-            self._last_mtime = None
-
-            raise
-
-    def return_tuple(self):
-        if not (self._loaded and self._check_mtime()):
-            try:
-                self._load()
-            except:
-                raise TemplateDoesNotExist, self._file_name
-
-        return self._source, self._file_name
-
-class BaseTemplateLoader(object):
-    is_usable = True
-
-    def __init__(self):
-        self.cache = {}
-
-    def __call__(self, name=None, dirs=None):
-        if name is None:
-            return self
-
-        return self.load_template(name, dirs)
-
-    def load_template(self, name, dirs=None):
-        if not djsettings.TEMPLATE_DEBUG:
-            if name in self.cache:
-                if self.cache[name] is UNEXISTENT_TEMPLATE:
-                    raise TemplateDoesNotExist, name
-
-                try:
-                    return self.cache[name].return_tuple()
-                except:
-                    del self.cache[name]
-
-        template = self.load_template_source(name, dirs)
-
-        if template is not None:
-            if not djsettings.DEBUG:
-                self.cache[name] = template
-
-            return template.return_tuple()
-        else:
-            if not djsettings.DEBUG:
-                self.cache[name] = UNEXISTENT_TEMPLATE
-
-            raise TemplateDoesNotExist, name
-
-    def load_template_source(self, name, dirs=None):
-        raise NotImplementedError
-
-
-class SkinsTemplateLoader(BaseTemplateLoader):
-
-    def load_template_source(self, name, dirs=None):
-
-        if name.startswith(FORCE_DEFAULT_PREFIX):
-
-            file_name = os.path.join(SKINS_FOLDER, DEFAULT_SKIN_NAME, SKIN_TEMPLATES_FOLDER, name[len(FORCE_DEFAULT_PREFIX):])
-
-            if os.path.exists(file_name):
-                return Template(file_name)
-            else:
-                return None
-
-        for skin in (settings.OSQA_DEFAULT_SKIN, DEFAULT_SKIN_NAME):
-            file_name = os.path.join(SKINS_FOLDER, skin, SKIN_TEMPLATES_FOLDER, name)
-
-            if os.path.exists(file_name):
-                return Template(file_name)
-
-        return None
-
-load_template_source = SkinsTemplateLoader()
+#note - Django template loaders use method django.utils._os.safe_join
+#to work on unicode file paths
+#here it is ignored because it is assumed that we won't use unicode paths
 
+def load_template_source(name, dirs=None):
+    try:
+        tname = os.path.join(settings.OSQA_DEFAULT_SKIN,'templates',name)
+        return filesystem.load_template_source(tname,dirs)
+    except:
+        tname = os.path.join('default','templates',name)
+        return filesystem.load_template_source(tname,dirs)
+load_template_source.is_usable = True
 
 def find_media_source(url):
     """returns url prefixed with the skin name
@@ -149,3 +56,5 @@ def find_media_source(url):
                 return None
     return use_skin + '/' + url
 
+
+
index 021437ce4c3115fc3597562056463317b46e3e59..2281f0e6e3cc36ec8f17ad30b22ff405f88cf123 100644 (file)
         {% if settings.USE_CUSTOM_CSS|or_preview:request %}
         <link href="{% url custom_css %}" rel="stylesheet" type="text/css" />
         {% endif %}
-        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" />
         {% block forestyle %}{% endblock %}
         <script src="http://www.google.com/jsapi" type="text/javascript"></script>
-        <script type="text/javascript">
-            google.load("jquery", "1.4.2");
-            google.load("jqueryui", "1", {autoload:true});
-        </script>
+        <script type="text/javascript">google.load("jquery", "1.4.2");</script>
         <script type="text/javascript">
         /* <![CDATA[ */
             var i18nLang = '{{settings.LANGUAGE_CODE}}';
diff --git a/forum/skins/default/templates/node/award_points.html b/forum/skins/default/templates/node/award_points.html
deleted file mode 100644 (file)
index 8210069..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{% load i18n %}
-
-<p>
-{% blocktrans %}
-Award {{ awarded_user }} with reputation points.
-{% endblocktrans %}
-</p>
-
-<p>
-    Points:
-    <span id="reputation_points_award">1</span>
-</p>
-
-<div class="award_points_slider"></div>
-
-<script>
-$('.award_points_slider').slider({
-    min: 1, max: {{ user.reputation }},
-    slide: function(evt, ui) {
-        $('#reputation_points_award').html(ui.value)
-    }
-});
-</script>
\ No newline at end of file
index 18e4522066a4c31e3d00ae19dae8ee8c1b968e51..aab4d99ae350c142c2fcf142bb940ff7319ce639 100644 (file)
@@ -90,12 +90,6 @@ def post_controls(post, user):
         controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id}),\r
                                      title=_("answer permanent link"), command=True, withprompt=True))\r
 \r
-        # Users should be able to award points for an answer. Users cannot award their own answers\r
-        if user != post.author and user.is_authenticated():\r
-            controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id,\r
-                                         'answer_id' : post.id}), title=_("award points to %s") % post.author,\r
-                                         command=True, withprompt=True))\r
-\r
     # The other controls are visible only to authenticated users.\r
     if user.is_authenticated():\r
         edit_url = reverse('edit_' + post_type, kwargs={'id': post.id})\r
@@ -212,10 +206,10 @@ def comments(post, user):
 \r
 \r
 @register.inclusion_tag("node/contributors_info.html")\r
-def contributors_info(node, verb=None):\r
+def contributors_info(node):\r
     return {\r
-        'node_verb': verb and verb or ((node.node_type == "question") and _("asked") or (\r
-                    (node.node_type == "answer") and _("answered") or _("posted"))),\r
+        'node_verb': (node.node_type == "question") and _("asked") or (\r
+                    (node.node_type == "answer") and _("answered") or _("posted")),\r
         'node': node,\r
     }\r
 \r
index 8b28e2c67c1aa063c96c95c168b5003ce813653d..21ba3bbdc0436ff2b2300df20e39252ec67ff62d 100644 (file)
@@ -1,5 +1,4 @@
 from django import template
-from django.conf import settings
 from forum.modules import ui
 import logging
 
@@ -22,11 +21,10 @@ class LoadRegistryNode(template.Node):
                             result += separator
                         result += ui_object.render(context)
             except (KeyError, Exception), e:
-                if settings.DEBUG:
-                    import traceback
-                    logging.error("Exception %s rendering ui objects %s: \n%s" % (
-                        e, ui_object, traceback.format_exc()
-                    ))
+                import traceback
+                logging.error("Exception %s rendering ui objects %s: \n%s" % (
+                    e, ui_object, traceback.format_exc()
+                ))
 
         return result
 
index fc64e28ac953c980a2dcb1272bd1ccd70c0f9a70..f53ccae3530f4cca85ede58eb506b1156bb2f8a5 100644 (file)
@@ -85,9 +85,8 @@ urlpatterns += patterns('',
                             name="convert_comment"),
                         url(r'^%s(?P<id>\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"),
                         url(r'^%s(?P<id>\d+)/$' % _('answer_link/'), app.commands.answer_permanent_link, name="answer_permanent_link"),
-                        url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite"),
-                        url(r'^%s%s(?P<user_id>\d+)/%s(?P<answer_id>\d+)/$' % (_('award_points/'), _('user/'), _('answer/')), app.commands.award_points, name="award_points"),
-
+                        url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite")
+                        ,
                         url(r'^%s(?P<id>\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'),
                         url(r'^%s(?P<id>\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'),
                         url(r'^%s(?P<id>\d+)/(?P<user>\d+)?$' % _('subscribe/'), app.commands.subscribe, name="subscribe"),
@@ -216,6 +215,5 @@ urlpatterns += patterns('',
 
                         url(r'^feeds/rss[/]?$', app.readers.feed, name="latest_questions_feed"),
 
-                        #url(r'^.+$', app.meta.page, name="static_page"),
+                        url(r'^(?P<path>.+)$', app.meta.page, name="static_page"),
                         )
-
index 53a49dc05ecedab60e8153ed10639bc6026ed86d..da476ee9cc9bf58c07d5f1d34ecb74e1b07aee13 100644 (file)
@@ -31,8 +31,6 @@ def auto_user_link(node, content):
             question = node.question
         elif node.answer:
             question = node.answer.question
-    else:
-        return content
     
     # Now we've got the root question. Let's get the list of active users.
     active_users = question.get_active_users()
index 38d86b2111ae4b146c1d38d4689768390949463f..f8eb897d06b5ea15a44cd6c488bc86b63f55a271 100644 (file)
@@ -38,9 +38,9 @@ def signin_page(request):
     # If the referer is equal to the sign up page, e. g. if the previous login attempt was not successful we do not
     # change the sign in URL. The user should go to the same page.
     if not referer.replace(settings.APP_URL, '') == reverse('auth_signin'):
-        request.session[ON_SIGNIN_SESSION_ATTR] = referer
+        request.session['on_signin_url'] = referer
 
-    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]
+    all_providers = [provider.context for provider in AUTH_PROVIDERS.values()]
 
     sort = lambda c1, c2: c1.weight - c2.weight
     can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user
@@ -146,7 +146,7 @@ def process_provider_signin(request, provider):
             assoc = AuthKeyUserAssociation.objects.get(key=assoc_key)
             user_ = assoc.user
             return login_and_forward(request, user_)
-        except AuthKeyUserAssociation.DoesNotExist:
+        except:
             request.session['assoc_key'] = assoc_key
             request.session['auth_provider'] = provider
             return HttpResponseRedirect(reverse('auth_external_register'))
@@ -225,7 +225,7 @@ def external_register(request):
     return render_to_response('auth/complete.html', {
     'form1': form1,
     'email_feeds_form': email_feeds_form,
-    'provider':provider_context and mark_safe(provider_context.human_name) or _('unknown'),
+    'provider':mark_safe(provider_context.human_name),
     'login_type':provider_context.id,
     'gravatar_faq_url':reverse('faq') + '#gravatar',
     }, context_instance=RequestContext(request))
@@ -391,14 +391,14 @@ def login_and_forward(request, user, forward=None, message=None):
     request.user.message_set.create(message=message)
 
     if not forward:
-        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse('index'))
+        forward = request.session.get('on_signin_url', reverse('index'))
 
-    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)
+    pending_data = request.session.get('pending_submission_data', None)
 
     if pending_data and (user.email_isvalid or pending_data['type'] not in settings.REQUIRE_EMAIL_VALIDATION_TO):
         submission_time = pending_data['time']
         if submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)):
-            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
+            del request.session['pending_submission_data']
         elif submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.WARN_PENDING_POSTS_MINUTES)):
             user.message_set.create(message=(_("You have a %s pending submission.") % pending_data['data_name']) + " %s, %s, %s" % (
                 html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('save')}), _("save it")),
index 11818ecacf30c17539ae8d13867683e43ce8bf56..3d2f9d32de268da53eb053e0f746b5b30577c3c7 100644 (file)
@@ -580,20 +580,3 @@ def answer_permanent_link(request, id):
 
     # Display the template
     return render_to_response('node/permanent_link.html', { 'url' : url, })
-
-@decorate.withfn(command)
-def award_points(request, user_id, answer_id):
-    user = request.user
-    awarded_user = get_object_or_404(User, id=user_id)
-
-    # Users shouldn't be able to award themselves
-    if awarded_user.id == user.id:
-        raise CannotDoOnOwnException(_("award"))
-
-    # Anonymous users cannot award  points, they just don't have such
-    if not user.is_authenticated():
-        raise AnonymousNotAllowedException(_('award'))
-
-    return render_to_response("node/award_points.html", { 'user' : user, 'awarded_user' : awarded_user, })
-    # Display the template
-    return render_to_response('node/permanent_link.html', { 'url' : url, })
index a0c5cede68f84b5d49c2c6cae90e0ee2abf489f7..536cf2603515cee8a6cfda653450691e57eff7a9 100644 (file)
@@ -15,13 +15,12 @@ from django.db.models import Count
 from forum.forms import get_next_url
 from forum.models import Badge, Award, User, Page
 from forum.badges.base import BadgesMeta
-from forum.http_responses import HttpResponseNotFound, HttpResponseIntServerError
 from forum import settings
 from forum.utils.mail import send_template_email
 from django.utils.safestring import mark_safe
 from forum.templatetags.extra_filters import or_preview
 import decorators
-import re, sys, logging, traceback
+import re
 
 def favicon(request):
     return HttpResponseRedirect(str(settings.APP_FAVICON))
@@ -114,19 +113,17 @@ def badge(request, id, slug):
     'badge' : badge,
     }, context_instance=RequestContext(request))
 
-def page(request):
-    path = request.path[1:]
-
+def page(request, path):
     if path in settings.STATIC_PAGE_REGISTRY:
         try:
             page = Page.objects.get(id=settings.STATIC_PAGE_REGISTRY[path])
 
             if (not page.published) and (not request.user.is_superuser):
-                return HttpResponseNotFound(request)
+                raise Http404
         except:
-            return HttpResponseNotFound(request)
+            raise Http404
     else:
-        return HttpResponseNotFound(request)
+        raise Http404
 
     template = page.extra.get('template', 'default')
     sidebar = page.extra.get('sidebar', '')
@@ -163,39 +160,3 @@ def page(request):
     }, context_instance=RequestContext(request))
 
 
-def error_handler(request):
-
-    stacktrace = "".join(["\t\t%s\n" % l for l in traceback.format_exc().split("\n")])
-
-    try:
-        log_msg = """
-        error executing request:
-        PATH: %(path)s
-        USER: %(user)s
-        METHOD: %(method)s
-        POST PARAMETERS:
-        %(post)s
-        GET PARAMETERS:
-        %(get)s
-        HTTP HEADERS:
-        %(headers)s
-        COOKIES:
-        %(cookies)s
-        EXCEPTION INFO:
-        %(stacktrace)s
-        """ % {
-            'path': request.path,
-            'user': request.user.is_authenticated() and ("%s (%s)" % (request.user.username, request.user.id)) or "<anonymous>",
-            'method': request.method,
-            'post': request.POST and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.POST.items()]) or "None",
-            'get': request.GET and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.GET.items()]) or "None",
-            'cookies': request.COOKIES and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.COOKIES.items()]) or "None",
-            'headers': request.META and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.META.items()]) or "None",
-            'stacktrace': stacktrace
-        }
-    except:
-        log_msg = "error executing request:\n%s" % stacktrace
-
-
-    logging.error(log_msg)
-    return HttpResponseIntServerError(request)
index 69edf3cfa9243df64602542f1ab8ec7af775ba33..9a6f66eaf2caaa78ec8439ea4e8715cad8948201 100644 (file)
@@ -238,14 +238,16 @@ def tags(request):
     })
 
 def update_question_view_times(request, question):
-    last_seen_in_question = request.session.get('last_seen_in_question', {})
+    if not 'last_seen_in_question' in request.session:
+        request.session['last_seen_in_question'] = {}
 
-    last_seen = last_seen_in_question.get(question.id, None)
+    last_seen = request.session['last_seen_in_question'].get(question.id, None)
 
-    if (not last_seen) or (last_seen < question.last_activity_at):
+    if (not last_seen) or last_seen < question.last_activity_at:
         QuestionViewAction(question, request.user, ip=request.META['REMOTE_ADDR']).save()
-        last_seen_in_question[question.id] = datetime.datetime.now()
-        request.session['last_seen_in_question'] = last_seen_in_question
+        request.session['last_seen_in_question'][question.id] = datetime.datetime.now()
+
+    request.session['last_seen_in_question'][question.id] = datetime.datetime.now()
 
 def match_question_slug(id, slug):
     slug_words = slug.split('-')
diff --git a/forum/views/vars.py b/forum/views/vars.py
deleted file mode 100644 (file)
index 3ac5c2c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-ON_SIGNIN_SESSION_ATTR = 'on_signin_url'
-PENDING_SUBMISSION_SESSION_ATTR = 'pending_submission_data'
index a5c5d704f817f926f28d5328842ed72ad02494e9..dbc68c017c4c583160e453031e2400fef4b013d6 100644 (file)
@@ -18,7 +18,6 @@ from forum.models import *
 from forum.forms import get_next_url
 from forum.utils import html
 
-from vars import PENDING_SUBMISSION_SESSION_ATTR
 
 def upload(request):#ajax upload file to a question or answer
     class FileTypeNotAllow(Exception):
@@ -85,7 +84,7 @@ def ask(request):
 
                     return HttpResponseRedirect(question.get_absolute_url())
                 else:
-                    request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
+                    request.session['pending_submission_data'] = {
                         'POST': request.POST,
                         'data_name': _("question"),
                         'type': 'ask',
@@ -234,7 +233,7 @@ def answer(request, id):
 
             return HttpResponseRedirect(answer.get_absolute_url())
         else:
-            request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
+            request.session['pending_submission_data'] = {
                 'POST': request.POST,
                 'data_name': _("answer"),
                 'type': 'answer',
@@ -254,7 +253,7 @@ def answer(request, id):
 
 
 def manage_pending_data(request, action, forward=None):
-    pending_data = request.session.pop(PENDING_SUBMISSION_SESSION_ATTR, None)
+    pending_data = request.session.pop('pending_submission_data', None)
 
     if not pending_data:
         raise Http404
index 4c3818cbc41c47c6fa43e2cfe6b20dcc551a003f..cc1e97d78ef30c75bef87fd9258d623efd3fd5eb 100644 (file)
@@ -26,13 +26,6 @@ class OpenIdAbstractAuthConsumer(AuthenticationConsumer):
         #'birthdate': 'http://axschema.org/birthDate',
     }
 
-    sreg_attributes = {
-        "required": {
-            "email": "email",
-            "nickname": "username"
-        }
-    }
-
     def get_user_url(self, request):
         try:
             return request.POST['openid_identifier']
@@ -57,26 +50,23 @@ class OpenIdAbstractAuthConsumer(AuthenticationConsumer):
         except DiscoveryFailure:
             raise InvalidAuthentication(_('Sorry, but your input is not a valid OpenId'))
 
-        sreg = getattr(self, 'sreg_attributes', False)
-
-        if sreg:
-            s = SRegRequest()
-
-            for k, attr_dic in sreg.items():
-                if k == "policy_url":
-                    s.policy_url = attr_dic
-                    continue
+        #sreg = getattr(settings, 'OPENID_SREG', False)
 
-                for attr_name in attr_dic.keys():
-                    s.requestField(field_name=attr_name, required=(k == "required"))
+        #if sreg:
+        #    s = SRegRequest()
+        #    for sarg in sreg:
+        #        if sarg.lower().lstrip() == "policy_url":
+        #            s.policy_url = sreg[sarg]
+        #        else:
+        #            for v in sreg[sarg].split(','):
+        #                s.requestField(field_name=v.lower().lstrip(), required=(sarg.lower().lstrip() == "required"))
+        #    auth_request.addExtension(s)
 
-            auth_request.addExtension(s)
+        #auth_request.addExtension(SRegRequest(required=['email']))
 
-        ax_schema = getattr(self, 'dataype2ax_schema', False)
-
-        if ax_schema and request.session.get('force_email_request', True):
+        if request.session.get('force_email_request', True):
             axr = AXFetchRequest()
-            for data_type, schema in ax_schema.items():
+            for data_type, schema in self.dataype2ax_schema.items():
                 if isinstance(schema, tuple):
                     axr.add(AttrInfo(schema[0], 1, True, schema[1]))
                 else:
@@ -104,41 +94,31 @@ class OpenIdAbstractAuthConsumer(AuthenticationConsumer):
         openid_response = consumer.complete(query_dict, url)
 
         if openid_response.status == SUCCESS:
+            if request.session.get('force_email_request', True):
+                try:
+                    ax = AXFetchResponse.fromSuccessResponse(openid_response)
 
-            consumer_data = {}
-
-            sreg_attrs = getattr(self, 'sreg_attributes', False)
-
-            if sreg_attrs:
-                sreg_response = SRegResponse.fromSuccessResponse(openid_response)
+                    axargs = ax.getExtensionArgs()
 
-                all_attrs = {}
-                [all_attrs.update(d) for k,d in sreg_attrs.items() if k != "policy_url"]
+                    ax_schema2data_type = dict([(s, t) for t, s in self.dataype2ax_schema.items()])
 
-                for attr_name, local_name in all_attrs.items():
-                    if attr_name in sreg_response:
-                        consumer_data[local_name] = sreg_response[attr_name]
+                    available_types = dict([
+                        (ax_schema2data_type[s], re.sub('^type\.', '', n))
+                        for n, s in axargs.items() if s in ax_schema2data_type
+                    ])
 
-            ax_schema = getattr(self, 'dataype2ax_schema', False)
-
-            if ax_schema:
-                ax = AXFetchResponse.fromSuccessResponse(openid_response)
-
-                axargs = ax.getExtensionArgs()
-
-                ax_schema2data_type = dict([(s, t) for t, s in ax_schema.items()])
-
-                available_types = dict([
-                    (ax_schema2data_type[s], re.sub('^type\.', '', n))
-                    for n, s in axargs.items() if s in ax_schema2data_type
-                ])
-
-                for t, s in available_types.items():
-                    if not t in consumer_data:
-                        consumer_data[t] = axargs["value.%s.1" % s]
+                    available_data = dict([
+                        (t, axargs["value.%s.1" % s]) for t, s in available_types.items()
+                    ])
                     
-            request.session['auth_consumer_data'] = consumer_data
-
+                    request.session['auth_consumer_data'] = {
+                        'email': available_data.get('email', None),
+                    }
+
+                except Exception, e:
+                    pass
+                    #import sys, traceback
+                    #traceback.print_exc(file=sys.stdout)
 
             return request.GET['openid.identity']
         elif openid_response.status == CANCEL:
index 8887f8096a6083b4fecaa305b7ad9ad8f316c758..0f7f812626e23968ff072493092218a5d984a383 100644 (file)
@@ -1,11 +1,14 @@
 # -*- coding: utf-8 -*-
 
-from datetime import datetime
+from xml.dom import minidom
+from datetime import datetime, timedelta
 import time
 import re
 import os
 import gc
 from django.utils.translation import ugettext as _
+from django.template.defaultfilters import slugify
+from forum.models.utils import dbsafe_encode
 from orm import orm
 
 from django.utils.encoding import force_unicode
@@ -164,12 +167,13 @@ class IdIncrementer():
 
 openidre = re.compile('^https?\:\/\/')
 def userimport(path, options):
+#users = readTable(dump, "Users")
 
     usernames = []
     openids = set()
     uidmapper = IdMapper()
+    #merged_users = []
 
-    authenticated_user = options.get('authenticated_user', None)
     owneruid = options.get('owneruid', None)
     #check for empty values
     if not owneruid:
@@ -181,29 +185,14 @@ def userimport(path, options):
         if sxu.get('id') == '-1':
             return
         #print "\n".join(["%s : %s" % i for i in sxu.items()])
-
         if int(sxu.get('id')) == int(owneruid):
-            if authenticated_user:
-                osqau = orm.User.objects.get(id=authenticated_user.id)
-
-                for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
-                    openids.add(assoc.key)
-
-                uidmapper[owneruid] = osqau.id
-                uidmapper[-1] = osqau.id
-                create = False
-            else:
-                uidmapper[owneruid] = int(owneruid)
-                uidmapper[-1] = int(owneruid)
-
-
-        sxbadges = sxu.get('badgesummary', None)
-        badges = {'1':'0', '2':'0', '3':'0'}
-
-        if sxbadges:
-            badges.update(dict([b.split('=') for b in sxbadges.split()]))
-
-        if create:
+            osqau = orm.User.objects.get(id=1)
+            for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
+                openids.add(assoc.key)
+            uidmapper[owneruid] = 1
+            uidmapper[-1] = 1
+            create = False
+        else:
             username = unicode(sxu.get('displayname',
                                sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu)))))[:30]
 
@@ -221,8 +210,15 @@ def userimport(path, options):
 
                     if not totest in usernames:
                         username = totest
-                        break
+                        break          
+
+        sxbadges = sxu.get('badgesummary', None)
+        badges = {'1':'0', '2':'0', '3':'0'}
 
+        if sxbadges:
+            badges.update(dict([b.split('=') for b in sxbadges.split()]))
+
+        if create:
             osqau = orm.User(
                     id           = sxu.get('id'),
                     username     = username,
@@ -316,6 +312,7 @@ def userimport(path, options):
     return uidmapper
 
 def tagsimport(dump, uidmap):
+#tags = readTable(dump, "Tags")
 
     tagmap = {}
 
@@ -357,8 +354,18 @@ def remove_post_state(name, post):
     post.state_string = "".join("(%s)" % s for s in re.findall('\w+', post.state_string) if s != name)
 
 def postimport(dump, uidmap, tagmap):
+#history = {}
+#accepted = {}
     all = []
 
+    #for h in readTable(dump, "PostHistory"):
+    #    if not history.get(h.get('postid'), None):
+    #        history[h.get('postid')] = []
+    #
+    #    history[h.get('postid')].append(h)
+
+    #posts = readTable(dump, "Posts")
+
     def callback(sxpost):
         nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"
 
@@ -434,6 +441,7 @@ def postimport(dump, uidmap, tagmap):
     return all
 
 def comment_import(dump, uidmap, posts):
+#comments = readTable(dump, "PostComments")
     currid = IdIncrementer(max(posts))
     mapping = {}
 
@@ -508,6 +516,7 @@ def create_and_activate_revision(post):
     post.save()
 
 def post_vote_import(dump, uidmap, posts):
+#votes = readTable(dump, "Posts2Votes")
     close_reasons = {}
 
     def close_callback(r):
@@ -637,6 +646,7 @@ def post_vote_import(dump, uidmap, posts):
 
 
 def comment_vote_import(dump, uidmap, comments):
+#votes = readTable(dump, "Comments2Votes")
     user2vote = []
     comments2score = {}
 
@@ -678,6 +688,7 @@ def comment_vote_import(dump, uidmap, comments):
 
 
 def badges_import(dump, uidmap, post_list):
+#node_ctype = orm['contenttypes.contenttype'].objects.get(name='node')
 
     sxbadges = {}
 
@@ -739,19 +750,10 @@ def badges_import(dump, uidmap, post_list):
     for badge in obadges.values():
         badge.save()
 
-def save_setting(k, v):
-    try:
-        kv = orm.KeyValue.objects.get(key=k)
-        kv.value = v
-    except:
-        kv = orm.KeyValue(key = k, value = v)
-
-    kv.save()
-
-
 def pages_import(dump, currid):
     currid = IdIncrementer(currid)
     registry = {}
+    #sx_pages = readTable(dump, "FlatPages")
 
     def callback(sxp):
         currid.inc()
@@ -798,7 +800,8 @@ def pages_import(dump, currid):
 
     readTable(dump, "FlatPages", callback)
 
-    save_setting('STATIC_PAGE_REGISTRY', dbsafe_encode(registry))
+    kv = orm.KeyValue(key='STATIC_PAGE_REGISTRY', value=dbsafe_encode(registry))
+    kv.save()
 
 sx2osqa_set_map = {
 u'theme.html.name': 'APP_TITLE',
@@ -829,17 +832,28 @@ def html_decode(html):
 
 
 def static_import(dump):
+#sx_sets = readTable(dump, "ThemeTextResources")
     sx_unknown = {}
 
     def callback(set):
         if unicode(set['name']) in sx2osqa_set_map:
-            save_setting(sx2osqa_set_map[set['name']], dbsafe_encode(html_decode(set['value'])))
+            try:
+                kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
+                kv.value = dbsafe_encode(html_decode(set['value']))
+            except:
+                kv = orm.KeyValue(
+                        key = sx2osqa_set_map[set['name']],
+                        value = dbsafe_encode(html_decode(set['value']))
+                        )
+
+            kv.save()
         else:
             sx_unknown[set['name']] = html_decode(set['value'])
 
     readTable(dump, "ThemeTextResources", callback)
 
-    save_setting('SXIMPORT_UNKNOWN_SETS', dbsafe_encode(sx_unknown))
+    unknown = orm.KeyValue(key='SXIMPORT_UNKNOWN_SETS', value=dbsafe_encode(sx_unknown))
+    unknown.save()
 
 def disable_triggers():
     from south.db import db
index ebaed2133e8c2957c814b991524e646a5202a780..dcca241c3a49b081172a4a07904f1fc1326a2c81 100644 (file)
@@ -1,38 +1,30 @@
 from django.shortcuts import render_to_response\r
 from django.template import RequestContext\r
-from forum.http_responses import HttpResponseUnauthorized\r
-from forum.models import User\r
+from forum.views.admin import super_user_required\r
 import importer\r
 from zipfile import ZipFile\r
 import os\r
 \r
+@super_user_required\r
 def sximporter(request):\r
-    if (not User.objects.exists()) or (request.user.is_authenticated() and request.user.is_superuser):\r
-        list = []\r
-        if request.method == "POST" and "dump" in request.FILES:\r
-            dump = ZipFile(request.FILES['dump'])\r
-            members = [f for f in dump.namelist() if f.endswith('.xml')]\r
-            extract_to = os.path.join(os.path.dirname(__file__), 'tmp')\r
-\r
-            if not os.path.exists(extract_to):\r
-                os.makedirs(extract_to)\r
-\r
-            for m in members:\r
-                f = open(os.path.join(extract_to, m), 'w')\r
-                f.write(dump.read(m))\r
-                f.close()\r
-\r
-            #dump.extractall(extract_to, members)\r
-            dump.close()\r
-\r
-            options = dict([(k, v) for k, v in request.POST.items()])\r
-            options['authenticated_user'] = (request.user.is_authenticated() and (request.user,) or (None,))[0]\r
-\r
-            importer.sximport(extract_to, options)\r
-\r
-        return render_to_response('modules/sximporter/page.html', {\r
-        'names': list\r
-        }, context_instance=RequestContext(request))\r
-    else:\r
-        return HttpResponseUnauthorized(request)\r
-\r
+    list = []\r
+    if request.method == "POST" and "dump" in request.FILES:\r
+        dump = ZipFile(request.FILES['dump'])\r
+        members = [f for f in dump.namelist() if f.endswith('.xml')]\r
+        extract_to = os.path.join(os.path.dirname(__file__), 'tmp')\r
+\r
+        if not os.path.exists(extract_to):\r
+            os.makedirs(extract_to)\r
+\r
+        for m in members:\r
+            f = open(os.path.join(extract_to, m), 'w')\r
+            f.write(dump.read(m))\r
+            f.close()\r
+\r
+        #dump.extractall(extract_to, members)\r
+        dump.close()\r
+        importer.sximport(extract_to, request.POST)\r
+\r
+    return render_to_response('modules/sximporter/page.html', {\r
+    'names': list\r
+    }, context_instance=RequestContext(request))\r
index 61c47a8279411bc8370c6baffba665e1960ec291..6e7c106c3b886128e8366366b9e1f5f834b8504c 100644 (file)
@@ -1,4 +1,5 @@
 # encoding:utf-8
+# Django settings for lanai project.
 import os.path
 import sys
 
@@ -6,18 +7,24 @@ SITE_ID = 1
 
 ADMIN_MEDIA_PREFIX = '/admin_media/'
 SECRET_KEY = '$oo^&_m&qwbib=(_4m_n*zn-d=g#s0he5fx9xonnym#8p6yigm'
-
-TEMPLATE_LOADERS = [
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
     'django.template.loaders.filesystem.load_template_source',
     'django.template.loaders.app_directories.load_template_source',
-    'forum.modules.template_loader.module_templates_loader',
+    'forum.modules.module_templates_loader',
     'forum.skins.load_template_source',
-]
+#     'django.template.loaders.eggs.load_template_source',
+)
 
 MIDDLEWARE_CLASSES = [
+    #'django.middleware.gzip.GZipMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
+    #'django.middleware.locale.LocaleMiddleware',
+    #'django.middleware.cache.UpdateCacheMiddleware',
     'django.middleware.common.CommonMiddleware',
+    #'django.middleware.cache.FetchFromCacheMiddleware',
     'forum.middleware.extended_user.ExtendedUser',
+    #'django.middleware.sqlprint.SqlPrintingMiddleware',
     'forum.middleware.anon_user.ConnectToSessionMessagesMiddleware',
     'forum.middleware.request_utils.RequestUtils',
     'forum.middleware.cancel.CancelActionMiddleware',
@@ -26,27 +33,28 @@ MIDDLEWARE_CLASSES = [
     'django.middleware.transaction.TransactionMiddleware',
 ]
 
-TEMPLATE_CONTEXT_PROCESSORS = [
+TEMPLATE_CONTEXT_PROCESSORS = (
     'django.core.context_processors.request',
     'forum.context.application_settings',
-    'forum.user_messages.context_processors.user_messages',
-    'django.core.context_processors.auth',
-]
+    #'django.core.context_processors.i18n',
+    'forum.user_messages.context_processors.user_messages',#must be before auth
+    'django.core.context_processors.auth', #this is required for admin
+)
 
 ROOT_URLCONF = 'urls'
-APPEND_SLASH = True
 
 TEMPLATE_DIRS = (
     os.path.join(os.path.dirname(__file__),'forum','skins').replace('\\','/'),
 )
 
-
+#UPLOAD SETTINGS
 FILE_UPLOAD_TEMP_DIR = os.path.join(os.path.dirname(__file__), 'tmp').replace('\\','/')
 FILE_UPLOAD_HANDLERS = ("django.core.files.uploadhandler.MemoryFileUploadHandler",
  "django.core.files.uploadhandler.TemporaryFileUploadHandler",)
 DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
-
+# for user upload
 ALLOW_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff')
+# unit byte
 ALLOW_MAX_FILE_SIZE = 1024 * 1024
 
 # User settings
@@ -72,19 +80,6 @@ for path in app_url_split[1].split('/')[1:]:
 if FORCE_SCRIPT_NAME.endswith('/'):
     FORCE_SCRIPT_NAME = FORCE_SCRIPT_NAME[:-1]
 
-from forum import modules
-
-modules.init_modules_engine(SITE_SRC_ROOT, DISABLED_MODULES)
-
-[MIDDLEWARE_CLASSES.extend(
-        ["%s.%s" % (m.__name__, mc) for mc in getattr(m, 'MIDDLEWARE_CLASSES', [])]
-                          ) for m in modules.MODULE_LIST]
-
-[TEMPLATE_LOADERS.extend(
-        ["%s.%s" % (m.__name__, tl) for tl in getattr(m, 'TEMPLATE_LOADERS', [])]
-                          ) for m in modules.MODULE_LIST]
-
-
 INSTALLED_APPS = [
     'django.contrib.auth',
     'django.contrib.contenttypes',
diff --git a/urls.py b/urls.py
index aa8bdf98d3e8051069fe9f05f873ea89c128d419..0355657c9d3d7d279c19009ea10398fa90c3da94 100644 (file)
--- a/urls.py
+++ b/urls.py
@@ -11,7 +11,3 @@ if 'rosetta' in settings.INSTALLED_APPS:
         url(r'^rosetta/', include('rosetta.urls')),
     )
 
-handler404 = 'forum.views.meta.page'
-handler500 = 'forum.views.meta.error_handler'
-
-