Пример #1
0
            msg = _('Created {count} entries')
            msg = msg.format(count=count)
            messages.add_message(self.request, messages.SUCCESS, msg)
        else:
            msg = _('No entry created.')
            messages.add_message(self.request, messages.WARNING, msg)
        return super(EntryView, self).form_valid(form)

    def get_context_data(self, **kwargs):
        context = super(EntryView, self).get_context_data(**kwargs)
        context['entries'] = Entry.objects.all()[:50]
        context['export_form'] = ExportEntryForm()
        context['MONITORING_ENTRY_EXPORT_FIELDS'] = settings.MONITORING_ENTRY_EXPORT_FIELDS  # noqa
        return context

entry = staff_member_required(EntryView.as_view())


class ExportEntry(CSVExportMixin, View):
    prefix = 'entry'

    def get(self, *args, **kwargs):
        self.form = ExportEntryForm(self.request.GET)
        if self.form.is_valid():
            return self.render_to_csv()
        else:
            msg = _('Error while processing entries export')
            messages.add_message(self.request, messages.ERROR, msg)
            messages.add_message()
            return HttpResponseRedirect(reverse_lazy('monitoring:entry'))
Пример #2
0
    paginate_by = 50

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['USERS_LIST_EXTRA_FIELDS'] = settings.USERS_LIST_EXTRA_FIELDS
        context['q'] = self.request.GET.get('q', '')
        return context

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            return self.model.objects.search(query)
        else:
            return super().get_queryset()

user_list = staff_member_required(UserList.as_view())


class UserDetail(DetailView):
    model = user_model
    template_name = 'ideascube/user_detail.html'
    context_object_name = 'user_obj'
user_detail = staff_member_required(UserDetail.as_view())


class UserFormMixin(object):

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        context['USER_FORM_FIELDS'] = settings.USER_FORM_FIELDS
        return context
Пример #3
0
        context = super().get_context_data(**kwargs)
        self._set_available_langs(context)
        self._set_available_tags(context)
        return context

index = Index.as_view()


class ContentDetail(DetailView):
    model = Content

    def get_queryset(self):
        if self.request.user.is_authenticated() and self.request.user.is_staff:
            return Content.objects.all()
        else:
            return Content.objects.published()

content_detail = ContentDetail.as_view()


class ContentUpdate(UpdateView):
    model = Content
    form_class = ContentForm
content_update = staff_member_required(ContentUpdate.as_view())


class ContentCreate(CreateView):
    model = Content
    form_class = ContentForm
content_create = staff_member_required(ContentCreate.as_view())
Пример #4
0
    model = Book

    def get(self, request, *args, **kwargs):
        ret = super().get(request, *args, **kwargs)
        user = request.user
        if user.is_staff and not self.object.specimens.count():
            messages.warning(request, _("Please add a specimen, or the book "
                                        "won't be available for the users"))
        return ret
book_detail = BookDetail.as_view()


class BookUpdate(UpdateView):
    model = Book
    form_class = BookForm
book_update = staff_member_required(BookUpdate.as_view())


class BookCreate(CreateView):
    model = Book
    form_class = BookForm
    initial = {
        'lang': get_language()
    }
book_create = staff_member_required(BookCreate.as_view())


class BookDelete(DeleteView):
    model = Book
    success_url = reverse_lazy('library:index')
book_delete = staff_member_required(BookDelete.as_view())
Пример #5
0
            messages.add_message(self.request, messages.SUCCESS, msg)
        else:
            msg = _('No entry created.')
            messages.add_message(self.request, messages.WARNING, msg)
        return super(EntryView, self).form_valid(form)

    def get_context_data(self, **kwargs):
        context = super(EntryView, self).get_context_data(**kwargs)
        context['entries'] = Entry.objects.all()[:50]
        context['export_form'] = ExportEntryForm()
        context[
            'MONITORING_ENTRY_EXPORT_FIELDS'] = settings.MONITORING_ENTRY_EXPORT_FIELDS  # noqa
        return context


entry = staff_member_required(EntryView.as_view())


class ExportEntry(CSVExportMixin, View):
    prefix = 'entry'

    def get(self, *args, **kwargs):
        self.form = ExportEntryForm(self.request.GET)
        if self.form.is_valid():
            return self.render_to_csv()
        else:
            msg = _('Error while processing entries export')
            messages.add_message(self.request, messages.ERROR, msg)
            messages.add_message()
            return HttpResponseRedirect(reverse_lazy('monitoring:entry'))
Пример #6
0
by_tag = ByTag.as_view()


class DocumentDetail(DetailView):
    model = Document


document_detail = DocumentDetail.as_view()


class DocumentUpdate(UpdateView):
    model = Document
    form_class = DocumentForm


document_update = staff_member_required(DocumentUpdate.as_view())


class DocumentCreate(CreateView):
    model = Document
    form_class = DocumentForm
    initial = {
        'lang': settings.LANGUAGE_CODE,
    }


document_create = staff_member_required(DocumentCreate.as_view())


class DocumentDelete(DeleteView):
    model = Document
Пример #7
0
    paginate_by = 50

    def get_context_data(self, **kwargs):
        context = super(UserList, self).get_context_data(**kwargs)
        context['USERS_LIST_EXTRA_FIELDS'] = settings.USERS_LIST_EXTRA_FIELDS
        context['q'] = self.request.GET.get('q', '')
        return context

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            return self.model.objects.search(query)
        else:
            return super(UserList, self).get_queryset()

user_list = staff_member_required(UserList.as_view())


class UserDetail(DetailView):
    model = user_model
    template_name = 'ideascube/user_detail.html'
    context_object_name = 'user_obj'
user_detail = staff_member_required(UserDetail.as_view())


class UserFormMixin(object):

    def get_context_data(self, *args, **kwargs):
        context = super(UserFormMixin, self).get_context_data(*args, **kwargs)
        context['USER_FORM_FIELDS'] = settings.USER_FORM_FIELDS
        return context
Пример #8
0
by_tag = ByTag.as_view()


class BookDetail(DetailView):
    model = Book


book_detail = BookDetail.as_view()


class BookUpdate(UpdateView):
    model = Book
    form_class = BookForm


book_update = staff_member_required(BookUpdate.as_view())


class BookCreate(CreateView):
    model = Book
    form_class = BookForm
    initial = {'lang': settings.LANGUAGE_CODE}


book_create = staff_member_required(BookCreate.as_view())


class BookDelete(DeleteView):
    model = Book
    success_url = reverse_lazy('library:index')
Пример #9
0
class ByTag(KindMixin, ByTagListView):
    model = Document
    template_name = 'mediacenter/by_tag.html'
    paginate_by = 10
by_tag = ByTag.as_view()


class DocumentDetail(DetailView):
    model = Document
document_detail = DocumentDetail.as_view()


class DocumentUpdate(UpdateView):
    model = Document
    form_class = DocumentForm
document_update = staff_member_required(DocumentUpdate.as_view())


class DocumentCreate(CreateView):
    model = Document
    form_class = DocumentForm
    initial = {
        'lang': settings.LANGUAGE_CODE,
    }
document_create = staff_member_required(DocumentCreate.as_view())


class DocumentDelete(DeleteView):
    model = Document
    success_url = reverse_lazy('mediacenter:index')
document_delete = staff_member_required(DocumentDelete.as_view())
Пример #10
0
    model = Content
    queryset = Content.objects.published()
    template_name = 'blog/by_tag.html'
    paginate_by = 10

by_tag = ByTag.as_view()


class ContentDetail(DetailView):
    model = Content

    def get_queryset(self):
        if self.request.user.is_authenticated() and self.request.user.is_staff:
            return Content.objects.all()
        else:
            return Content.objects.published()

content_detail = ContentDetail.as_view()


class ContentUpdate(UpdateView):
    model = Content
    form_class = ContentForm
content_update = staff_member_required(ContentUpdate.as_view())


class ContentCreate(CreateView):
    model = Content
    form_class = ContentForm
content_create = staff_member_required(ContentCreate.as_view())