Example #1
0
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            self.user = request.user
        else:
            if defaults.PYBB_ENABLE_ANONYMOUS_POST:
                self.user, new = User.objects.get_or_create(**{username_field: defaults.PYBB_ANONYMOUS_USERNAME})
            else:
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(request.get_full_path())

        self.notice = None
        self.course = None
        if 'notice_id' in kwargs:
            self.notice = get_object_or_404(perms.filter_notices(request.user, Notice.objects.all()), pk=kwargs['notice_id'])
            if not perms.may_create_course(self.user, self.notice):
                raise PermissionDenied
        elif 'course_id' in kwargs:
            self.course = get_object_or_404(perms.filter_courses(request.user, Course.objects.all()), pk=kwargs['course_id'])
            if not perms.may_create_post(self.user, self.course):
                raise PermissionDenied

            self.quote = ''
            if 'quote_id' in request.GET:
                try:
                    quote_id = int(request.GET.get('quote_id'))
                except TypeError:
                    raise Http404
                else:
                    post = get_object_or_404(Post, pk=quote_id)
                    self.quote = defaults.PYBB_QUOTE_ENGINES[defaults.PYBB_MARKUP](post.body, getattr(post.user, username_field))

                if self.quote and request.is_ajax():
                    return HttpResponse(self.quote)
        return super(AddPostView, self).dispatch(request, *args, **kwargs)
Example #2
0
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            self.user = request.user
        else:
            if defaults.PYBB_ENABLE_ANONYMOUS_POST:
                self.user, new = User.objects.get_or_create(
                    **{username_field: defaults.PYBB_ANONYMOUS_USERNAME})
            else:
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(request.get_full_path())

        self.notice = None
        self.course = None
        if 'notice_id' in kwargs:
            self.notice = get_object_or_404(perms.filter_notices(
                request.user, Notice.objects.all()),
                                            pk=kwargs['notice_id'])
            if not perms.may_create_course(self.user, self.notice):
                raise PermissionDenied
        elif 'course_id' in kwargs:
            self.course = get_object_or_404(perms.filter_courses(
                request.user, Course.objects.all()),
                                            pk=kwargs['course_id'])
            if not perms.may_create_post(self.user, self.course):
                raise PermissionDenied

            self.quote = ''
            if 'quote_id' in request.GET:
                try:
                    quote_id = int(request.GET.get('quote_id'))
                except TypeError:
                    raise Http404
                else:
                    post = get_object_or_404(Post, pk=quote_id)
                    self.quote = defaults.PYBB_QUOTE_ENGINES[
                        defaults.PYBB_MARKUP](post.body,
                                              getattr(post.user,
                                                      username_field))

                if self.quote and request.is_ajax():
                    return HttpResponse(self.quote)
        return super(AddPostView, self).dispatch(request, *args, **kwargs)
Example #3
0
 def items(self, user):
     return perms.filter_courses(user, Course.objects.all()).order_by(
         '-created', '-id')[:15]
Example #4
0
def add_subscription(request, course_id):
    course = get_object_or_404(perms.filter_courses(request.user,
                                                    Course.objects.all()),
                               pk=course_id)
    course.subscribers.add(request.user)
    return HttpResponseRedirect(course.get_absolute_url())
Example #5
0
 def get_queryset(self):
     qs = Course.objects.all().select_related()
     qs = perms.filter_courses(self.request.user, qs)
     return qs.order_by('-updated', '-id')
Example #6
0
 def items(self, user):
     return perms.filter_courses(user, Course.objects.all()).order_by('-created', '-id')[:15]
Example #7
0
def noticeapp_get_latest_courses(context, cnt=5, user=None):
    qs = Course.objects.all().order_by('-updated', '-created', '-id')
    if not user:
        user = context['user']
    qs = perms.filter_courses(user, qs)
    return qs[:cnt]
Example #8
0
def noticeapp_get_latest_courses(context, cnt=5, user=None):
    qs = Course.objects.all().order_by('-updated', '-created', '-id')
    if not user:
        user = context['user']
    qs = perms.filter_courses(user, qs)
    return qs[:cnt]
Example #9
0
def add_subscription(request, course_id):
    course = get_object_or_404(perms.filter_courses(request.user, Course.objects.all()), pk=course_id)
    course.subscribers.add(request.user)
    return HttpResponseRedirect(course.get_absolute_url())
Example #10
0
 def get_queryset(self):
     qs = Course.objects.all().select_related()
     qs = perms.filter_courses(self.request.user, qs)
     return qs.order_by('-updated', '-id')