from base import *
from tag import Tag
from django.utils.translation import ugettext as _
from base import *
from tag import Tag
from django.utils.translation import ugettext as _
-from forum.modules.decorators import decoratable
question_view = django.dispatch.Signal(providing_args=['instance', 'user'])
class QuestionManager(NodeManager):
question_view = django.dispatch.Signal(providing_args=['instance', 'user'])
class QuestionManager(NodeManager):
def search(self, keywords):
return self.filter(models.Q(title__icontains=keywords) | models.Q(body__icontains=keywords))
def search(self, keywords):
return self.filter(models.Q(title__icontains=keywords) | models.Q(body__icontains=keywords))
raise TemplateDoesNotExist, name
module_templates_loader.is_usable = True
raise TemplateDoesNotExist, name
module_templates_loader.is_usable = True
+
+from decorators import decorate
def __init__(self, fn):\r
self._callable = fn\r
\r
def __init__(self, fn):\r
self._callable = fn\r
\r
- def decorate(self, fn, needs_origin):\r
+ def _decorate(self, fn, needs_origin):\r
origin = self._callable\r
\r
if needs_origin:\r
origin = self._callable\r
\r
if needs_origin:\r
else:\r
self._callable = lambda *args, **kwargs: fn(*args, **kwargs)\r
\r
else:\r
self._callable = lambda *args, **kwargs: fn(*args, **kwargs)\r
\r
- def __call__(self, *args, **kwargs):\r
- return self._callable(*args, **kwargs)\r
+ def _decorate_method(self, fn, needs_origin):\r
+ origin = self._callable\r
+ if needs_origin:\r
+ self._callable = lambda inst, *args, **kwargs: fn(inst, origin, *args, **kwargs)\r
+ else:\r
+ self._callable = lambda inst, *args, **kwargs: fn(inst, *args, **kwargs)\r
-def decoratable(fn):\r
- return DecoratableObject(fn)\r
-def decoratable_method(fn):\r
- obj = DecoratableObject(fn)\r
- def decorated(self, *args, **kwargs):\r
- return obj(self, *args, **kwargs)\r
+ def __call__(self, *args, **kwargs):\r
+ return self._callable(*args, **kwargs)\r
- decorated.__obj = obj\r
- return decorated\r
-decoratable.method = decoratable_method\r
+def _decorate_method(origin, needs_origin):\r
+ if not hasattr(origin, '_decoratable_obj'):\r
+ name = origin.__name__\r
+ cls = origin.im_class\r
-def decorate(origin, needs_origin=True):\r
- if not isinstance(origin, DecoratableObject):\r
- if hasattr(origin, '__obj'):\r
- def decorator(fn):\r
- origin.__obj.decorate(fn, needs_origin)\r
- return origin\r
- return decorator\r
+ decoratable = DecoratableObject(origin)\r
+\r
+ def decoratable_method(self, *args, **kwargs):\r
+ return decoratable(self, *args, **kwargs)\r
- raise TypeError('Not a decoratable function: %s' % origin.__name__)\r
+ decoratable_method._decoratable_obj = decoratable\r
+ setattr(cls, name, decoratable_method)\r
+ else:\r
+ decoratable = origin._decoratable_obj\r
- origin.decorate(fn, needs_origin)\r
- return origin\r
+ decoratable._decorate_method(fn, needs_origin)\r
+def _decorate_function(origin, needs_origin):\r
+ if not isinstance(origin, DecoratableObject):\r
+ mod = inspect.getmodule(origin)\r
-def decorate_all(module):\r
- [setattr(module, n, decoratable(f)) for n, f in\r
- [(n, getattr(module, n)) for n in dir(module)]\r
- if (callable(f)) and (not inspect.isclass(f)) and (f.__module__ == module.__name__)]\r
-\r
-\r
+ name = origin.__name__\r
+ origin = DecoratableObject(origin)\r
+ setattr(mod, name, DecoratableObject(origin))\r
+ def decorator(fn):\r
+ origin._decorate(fn, needs_origin)\r
+def decorate(origin, needs_origin=True):\r
+ if inspect.ismethod(origin):\r
+ return _decorate_method(origin, needs_origin)\r
+ if inspect.isfunction(origin):\r
+ return _decorate_function(origin, needs_origin)
\ No newline at end of file
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from forum.utils.decorators import ajax_method, ajax_login_required
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from forum.utils.decorators import ajax_method, ajax_login_required
-from forum.modules.decorators import decoratable
from decorators import command, CommandException, RefreshPageCommand
from forum import settings
import logging
from decorators import command, CommandException, RefreshPageCommand
from forum import settings
import logging
@command
def comment(request, id):
post = get_object_or_404(Node, id=id)
@command
def comment(request, id):
post = get_object_or_404(Node, id=id)
from forum.models import *
from forum.forms import get_next_url
from forum.actions import QuestionViewAction
from forum.models import *
from forum.forms import get_next_url
from forum.actions import QuestionViewAction
-from forum.modules.decorators import decoratable
import decorators
# used in index page
import decorators
# used in index page
from django.core.exceptions import PermissionDenied
from forum.actions import AskAction, AnswerAction, ReviseAction, RollbackAction, RetagAction
from django.core.exceptions import PermissionDenied
from forum.actions import AskAction, AnswerAction, ReviseAction, RollbackAction, RetagAction
-from forum.modules.decorators import decoratable
from forum.forms import *
from forum.models import *
from forum.forms import get_next_url
from forum.forms import *
from forum.models import *
from forum.forms import get_next_url
return HttpResponse(result, mimetype="application/xml")
return HttpResponse(result, mimetype="application/xml")
def ask(request):
if request.POST and "text" in request.POST:
form = AskForm(request.POST, user=request.user)
def ask(request):
if request.POST and "text" in request.POST:
form = AskForm(request.POST, user=request.user)
'form': form,
}, context_instance=RequestContext(request))
'form': form,
}, context_instance=RequestContext(request))
def answer(request, id):
question = get_object_or_404(Question, id=id)
if request.POST:
def answer(request, id):
question = get_object_or_404(Question, id=id)
if request.POST:
from django.utils import simplejson
from django.utils.encoding import smart_str
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.utils.encoding import smart_str
from django.shortcuts import render_to_response
-from forum.modules.decorators import decorate
+from forum.modules import decorate
from forum import views
from lib.akismet import Akismet
from forum.settings import APP_URL, OSQA_VERSION
from forum import views
from lib.akismet import Akismet
from forum.settings import APP_URL, OSQA_VERSION
import re
from django.db.models import Q
from forum.models.question import Question, QuestionManager
import re
from django.db.models import Q
from forum.models.question import Question, QuestionManager
-from forum.modules.decorators import decorate
+from forum.modules import decorate
repl_re = re.compile(r"^'|[^\'\-_\s\w]|'$", re.UNICODE)
sing_quote_re = re.compile(r"\'+")
repl_re = re.compile(r"^'|[^\'\-_\s\w]|'$", re.UNICODE)
sing_quote_re = re.compile(r"\'+")