Ejemplo n.º 1
0
class QuestionViewList(ListView):
    template_name = 'questions/list.html'
    context_object_name = 'questions'
    paginate_by = settings.get_config()['PAGINATE_BY']

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        return super(QuestionViewList, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 2
0
def delete(request, slug=None):
    question_id = slug2id(slug)

    question = get_object_or_404(Question,
                                 answerid=request.user,
                                 id=question_id)

    if settings.get_config()['SOFT_DELETE']:
        question.deleted = True
        question.save()
    else:
        question.delete()

    _next = request.GET.get('next')

    if _next:
        return redirect(_next)

    return redirect('questions:all')
Ejemplo n.º 3
0
def live_unread_question_list(request):
    ''' Return a json with a unread question list '''
    try:
        user_is_authenticated = request.user.is_authenticated()
    except TypeError:  # Django >= 1.11
        user_is_authenticated = request.user.is_authenticated

    if not user_is_authenticated:
        data = {'unread_count': 0, 'unread_list': []}
        return JsonResponse(data)

    default_num_to_fetch = get_config()['NUM_TO_FETCH']
    try:
        # If they don't specify, make it 5.
        num_to_fetch = request.GET.get('max', default_num_to_fetch)
        num_to_fetch = int(num_to_fetch)
        if not (1 <= num_to_fetch <= 100):
            num_to_fetch = default_num_to_fetch
    except ValueError:  # If casting to an int fails.
        num_to_fetch = default_num_to_fetch

    unread_list = []

    for question in request.user.questions.unread()[0:num_to_fetch]:
        struct = model_to_dict(question)
        struct['slug'] = id2slug(question.id)
        if question.actor:
            struct['actor'] = str(question.actor)
        if question.target:
            struct['target'] = str(question.target)
        if question.action:
            struct['action'] = str(question.action)
        if question.data:
            struct['data'] = question.data
        unread_list.append(struct)
        if request.GET.get('mark_as_read'):
            question.mark_as_read()
    data = {
        'unread_count': request.user.questions.unread().count(),
        'unread_list': unread_list
    }
    return JsonResponse(data)
Ejemplo n.º 4
0
def is_soft_delete():

    return questions_settings.get_config()['SOFT_DELETE']
Ejemplo n.º 5
0
from django.core.exceptions import ImproperlyConfigured
from django.db import models

from django.utils import timezone

from django.contrib.postgres.fields import JSONField

from questions import settings as questions_settings

from questions.utils import id2slug
from django.contrib.auth import get_user_model

from django.contrib.contenttypes.fields import GenericForeignKey  # noqa

EXTRA_DATA = questions_settings.get_config()['USE_JSONFIELD']


def is_soft_delete():

    return questions_settings.get_config()['SOFT_DELETE']


def assert_soft_delete():
    if not is_soft_delete():
        msg = """To use 'deleted' field, please set 'SOFT_DELETE'=True in settings.
        Otherwise QuestionQuerySet.unread and QuestionQuerySet.read do NOT filter by 'deleted' field.
        """
        raise ImproperlyConfigured(msg)

Ejemplo n.º 6
0
 def get_queryset(self):
     if settings.get_config()['SOFT_DELETE']:
         qset = self.request.user.questions.active()
     else:
         qset = self.request.user.questions.all()
     return qset