Beispiel #1
0
"""Extending CRUDLFAP features."""

from crudlfap import crudlfap
from .models import Post

crudlfap.Router(Post, views=[]).register()


class PostMixin:
    """Create mixin."""
    def get_exclude(self):
        if not self.request.user.is_staff:
            return ['owner']
        return super().get_exclude()


class PostCreateView(PostMixin, crudlfap.CreateView):
    """Override Post create view."""
    def form_valid(self):
        """Assigned currnet user."""
        self.form.instance.owner = self.request.user
        return super().form_valid()


crudlfap.Router(
    Post,
    material_icon='forum',
    # https://material.io/tools/icons/?style=baseline
    namespace='posts',
    views=[
        crudlfap.ListView.clone(
Beispiel #2
0
from crudlfap import crudlfap
from django_filters import filters
import django_tables2 as tables

from .models import Call, Caller, Cron

crudlfap.Router(
    Call,
    material_icon='assistant',
    views=[
        crudlfap.ListView.clone(table_fields=[
            'caller',
            'created',
            'started',
            'ended',
            'status',
        ], ),
        crudlfap.DetailView,
    ],
).register()

crudlfap.Router(
    Caller,
    material_icon='assignment_ind',
    views=[
        crudlfap.ListView.clone(
            filterset_extra_class_attributes=dict(status=filters.ChoiceFilter(
                choices=Caller.STATUS_CHOICES)),
            table_fields=[
                'id',
                'callback',
Beispiel #3
0
"""Extending CRUDLFAP features."""

from crudlfap import crudlfap
from .models import Post

crudlfap.Router(model=Post).register()
Beispiel #4
0
from crudlfap import crudlfap

from .models import Caisse, Email

crudlfap.Router(Caisse,
                material_icon='domain',
                views=[
                    crudlfap.CreateView,
                    crudlfap.DeleteView,
                    crudlfap.UpdateView,
                    crudlfap.DetailView,
                    crudlfap.FilterTables2ListView.clone(
                        table_sequence=('code', 'name', 'number', 'active',
                                        'score'),
                        search_fields=(
                            'code',
                            'name',
                            'number',
                        ),
                        filter_fields=('active', )),
                ]).register()

crudlfap.Router(Email,
                material_icon='contact_mail',
                views=[
                    crudlfap.FilterTables2ListView.clone(
                        table_sequence=('email', 'caisse'), ),
                ]).register()
Beispiel #5
0
from crudlfap import crudlfap

from .models import Artist


crudlfap.Router(
    Artist,
    fields='__all__',
    # Optionnal hack to allow unauthenticated access:
    allowed=lambda view: True
).register()
Beispiel #6
0
import django_tables2 as tables

from .models import EmailTemplate


class EmailTemplateListView(crudlfap.FilterTables2ListView):
    table_sequence = (
        'name',
        'subject',
        'requests',
        'active',
    )

    table_columns = dict(requests=tables.Column(
        accessor='requests',
        verbose_name='Demandes',
        order_by=['requests'],
    ))

    def get_queryset(self):
        return super().get_queryset().annotate(requests=Count('mrsrequest'))


crudlfap.Router(EmailTemplate,
                material_icon='mail',
                views=[
                    EmailTemplateListView,
                    crudlfap.CreateView,
                    crudlfap.UpdateView,
                ]).register()
Beispiel #7
0
"""Extending CRUDLFAP features."""

from crudlfap import crudlfap
from .models import Student

crudlfap.Router(model=Student).register()
from crudlfap import crudlfap

from django_filters import filters

from .models import Task

crudlfap.Router(
    Task,
    material_icon='sync',
    views=[
        crudlfap.ListView.clone(
            filterset_extra_class_attributes=dict(status=filters.ChoiceFilter(
                choices=Task.STATUS_CHOICES)),
            table_fields=[
                'id',
                'callback',
                'spooled',
                'status',
            ],
            search_fields=[
                'callback',
                'output',
            ],
        ),
        crudlfap.DetailView,
        crudlfap.DeleteObjectsView,
        crudlfap.DeleteView,
    ]).register()
Beispiel #9
0
from crudlfap import crudlfap

from .models import Institution

crudlfap.Router(Institution,
                material_icon='local_hospital',
                namespace='institutionrouter',
                views=[
                    crudlfap.FilterTables2ListView(table_sequence=('finess',
                                                                   'origin')),
                    crudlfap.CreateView,
                    crudlfap.UpdateView,
                    crudlfap.DeleteView,
                ]).register()
Beispiel #10
0
crudlfap.Router(
    User,
    views=[
        crudlfap.DeleteObjectsView,
        crudlfap.DeleteView,
        crudlfap.UpdateView.clone(body_class='modal-fixed-footer',
                                  fields=[
                                      'username',
                                      'email',
                                      'first_name',
                                      'last_name',
                                      'groups',
                                      'is_superuser',
                                      'is_staff',
                                      'is_active',
                                  ]),
        crudlfap.CreateView.clone(
            body_class='modal-fixed-footer',
            fields=['username', 'email', 'groups', 'is_staff', 'is_superuser'],
        ),
        views.PasswordView,
        views.BecomeUser,
        crudlfap.DetailView.clone(exclude=['password']),
        crudlfap.ListView.clone(
            search_fields=['username', 'email', 'first_name', 'last_name'],
            table_fields=[
                'username', 'email', 'first_name', 'last_name', 'is_staff',
                'is_superuser'
            ],
            filter_fields=['groups', 'is_superuser', 'is_staff'],
        ),
    ],
    allowed=lambda view: view.request.user.is_superuser,
    urlfield='username',
    material_icon='person',
).register()