\r
\r
class QuestionViewAction(DummyActionProxy):\r
- def __init__(self, question, user):\r
+ def __init__(self, node, user):\r
self.viewuser = user\r
- self.question = question\r
+ self.node = node\r
\r
def process_action(self):\r
- self.question.extra_count = F('extra_count') + 1\r
- self.question.save()\r
+ self.node.extra_count = F('extra_count') + 1\r
+ self.node.save()\r
class Meta:\r
proxy = True\r
\r
-class DummyActionProxy(Action):\r
- __metaclass__ = ActionProxyMetaClass\r
+class DummyActionProxyMetaClass(type):\r
+ def __new__(cls, *args, **kwargs):\r
+ new_cls = super(DummyActionProxyMetaClass, cls).__new__(cls, *args, **kwargs)\r
+ ActionProxyMetaClass.types[new_cls.get_type()] = new_cls\r
+ return new_cls\r
+\r
+class DummyActionProxy(object):\r
+ __metaclass__ = DummyActionProxyMetaClass\r
\r
hooks = []\r
\r
self.set_value(self.default)
def _parse(self, value):
- return value
+ try:
+ return self.base_type(value)
+ except:
+ return value
class Setting(object):
emul = Setting.emulators[deftype]
else:
emul = type(deftype.__name__ + cls.__name__, (BaseSetting,), {})
+ emul.base_type = deftype
fns = [n for n, f in [(p, getattr(deftype, p)) for p in dir(deftype) if not p in dir(cls)] if callable(f)]
for n in fns:
return\r
\r
try:\r
- subscription = QuestionSubscription.objects.get(question=action.question, user=action.viewuser)\r
+ subscription = QuestionSubscription.objects.get(question=action.node, user=action.viewuser)\r
subscription.last_view = datetime.datetime.now()\r
subscription.save()\r
except:\r
if action.viewuser.subscription_settings.questions_viewed:\r
- subscription = QuestionSubscription(question=action.question, user=action.viewuser)\r
+ subscription = QuestionSubscription(question=action.node, user=action.viewuser)\r
subscription.save()\r
\r
QuestionViewAction.hook(question_viewed)\r
return _('Asked a question with %s views') % str(self.nviews)
def award_to(self, action):
- if action.question.extra_count == int(self.nviews):
- return action.question.author
+ if action.node.extra_count == int(self.nviews):
+ return action.node.author
class PopularQuestion(QuestionViewBadge):