Пример #1
0
 def test_can_load_classes_from_both_the_local_app_and_the_vanilla_app(
         self):
     with override_settings(INSTALLED_APPS=self.installed_apps):
         ForumView, MyNewForumView = get_classes(
             'forum.views', ('ForumView', 'MyNewForumView'))
         assert 'machina.apps.forum.views' == ForumView.__module__
         assert 'tests._testsite.apps.forum.views' == MyNewForumView.__module__
Пример #2
0
 def test_can_load_many_classes(self):
     # Run & check
     PostForm, TopicForm = get_classes('forum_conversation.forms', [
         'PostForm',
         'TopicForm',
     ])
     assert 'machina.apps.forum_conversation.forms' == PostForm.__module__
     assert 'machina.apps.forum_conversation.forms' == TopicForm.__module__
Пример #3
0
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic import TemplateView
from django.views.generic.detail import BaseDetailView
from django.views.generic.detail import SingleObjectTemplateResponseMixin

from machina.conf import settings as machina_settings
from machina.core.db.models import get_model
from machina.core.loading import get_class
from machina.core.loading import get_classes


Forum = get_model('forum', 'Forum')
ForumReadTrack, TopicReadTrack = get_classes('forum_tracking.models',
                                             ['ForumReadTrack', 'TopicReadTrack'])
Topic = get_model('forum_conversation', 'Topic')

TrackingHandler = get_class('forum_tracking.handler', 'TrackingHandler')
track_handler = TrackingHandler()

PermissionRequiredMixin = get_class('forum_permission.viewmixins', 'PermissionRequiredMixin')


class MarkForumsReadView(TemplateView):
    """ Marks a set of forums as read. """

    success_message = _('Forums have been marked read.')
    template_name = 'forum_tracking/mark_forums_read.html'

    @method_decorator(login_required)
Пример #4
0
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic import View

# Local application / specific library imports
from machina.conf import settings as machina_settings
from machina.core.db.models import get_model
from machina.core.loading import get_class
from machina.core.loading import get_classes

Forum = get_model('forum', 'Forum')
ForumReadTrack, TopicReadTrack = get_classes('forum_tracking.models',
                                             ['ForumReadTrack', 'TopicReadTrack'])
Topic = get_model('forum_conversation', 'Topic')

TrackingHandler = get_class('forum_tracking.handler', 'TrackingHandler')
track_handler = TrackingHandler()

PermissionRequiredMixin = get_class('forum_permission.viewmixins', 'PermissionRequiredMixin')


class MarkForumsReadView(View):
    """
    Marks a set of forums as read.
    """
    success_message = _('Forums have been marked read.')

    def get(self, request, pk=None):
Пример #5
0
 def test_can_load_classes_from_both_the_local_app_and_the_vanilla_app(self):
     with override_settings(INSTALLED_APPS=self.installed_apps):
         ForumView, MyNewForumView = get_classes(
             'forum.views', ('ForumView', 'MyNewForumView'))
         assert 'machina.apps.forum.views' == ForumView.__module__
         assert 'tests._testsite.apps.forum.views' == MyNewForumView.__module__
Пример #6
0
 def test_can_load_many_classes(self):
     # Run & check
     PostForm, TopicForm = get_classes('forum_conversation.forms', ['PostForm', 'TopicForm', ])
     assert 'machina.apps.forum_conversation.forms' == PostForm.__module__
     assert 'machina.apps.forum_conversation.forms' == TopicForm.__module__
Пример #7
0
# -*- coding: utf-8 -*-

# Standard library imports
# Third party imports
from django.db.models import F
from django.db.models import Q
from django.dispatch import receiver

# Local application / specific library imports
from machina.core.loading import get_class
from machina.core.loading import get_classes

ForumReadTrack, TopicReadTrack = get_classes("forum_tracking.models", ["ForumReadTrack", "TopicReadTrack"])

topic_viewed = get_class("forum_conversation.signals", "topic_viewed")


@receiver(topic_viewed)
def update_user_trackers(sender, topic, user, request, response, **kwargs):
    """
    Receiver to mark a topic being viewed as read. This can result in marking
    the related forum tracker as read.
    """
    if not user.is_authenticated():
        return

    forum = topic.forum
    try:
        forum_track = ForumReadTrack.objects.get(forum=forum, user=user)
    except ForumReadTrack.DoesNotExist:
        forum_track = None