yourlabs / django-xcbv

UNUSABLE heavy research around cbv for the lulz, see crudlfap for usable code

Home Page:https://club.yourlabs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image

image

image

image

image

What it is

  • remove need of urls.py in favor of nested views,
  • nested security checking support,
  • take DRY to another level with nested views.
  • django can you generate a menu is: yes,
  • modern pattern for creating your own admin-like CRUD,

Extracted from CRUDLFA+, re DDD'd, under TDD.

# yourapp.views
urlpatterns = xcbv.View(
    menus=('global', 'footer'),
    views=(
        xcbv.ModelView.factory(
            model=YourModel,
            # updates views.list, views.update
            children=xcbv.ModelView.views.update(
                YourListView.factory(
                    # by default only staff sees new views, this opens for all
                    allows=lambda self: True
                ),
                YourUpdateView.factory(
                    # could be set here or inside the view
                    path='specialupdate/<slug0>/<slug1>',
                ),
                YourDetailView.factory(
                    # just adding a sub object list view inside URL and
                    # permission tree like a Poney, is this going to be a
                    # list of child models from the above ModelView model ?
                    views=xcbv.ModelListView(
                        model=YourChildModel,
                    )
                )
            ),
            icon="fa-love",
        ),
        YourOtherView,
    ),
    # some default overrides
    namespace='yourapp',
    prefix='you/',
).as_urlpatterns()

# yourproject.urls
urlpatterns += path('yourmodel/', yourapp.views.router.as_urlpatterns())

# in templates
# menu for navigation
{% for view in |views_in_menu:''|views_allowing:request %}
  <a
    href={{ view.absolute_url }}
    title={{ view.title }}
  ><span class="fa-icon {{ view.fa_icon }}"></span>
{% endfor %}

# menu for model
{% for view in self|views_in_menu:'model'|views_allowing:request %}
  <a
    href={{ view.absolute_url }}
    title={{ view.title }}
  ><span class="fa-icon {{ view.fa_icon }}"></span>
{% endfor %}

# menu for object
{% for view in self|views_in_menu:'object'|views_allowing:request %}
  <a
    href={{ view.absolute_url }}
    title={{ view.title }}
  ><span class="fa-icon {{ view.fa_icon }}"></span>
{% endfor %}

Demo

Run the demo which uses Django server side:

pip install --user xcbv[demo]
~/.local/bin/xcbv runserver

Resources

About

UNUSABLE heavy research around cbv for the lulz, see crudlfap for usable code

https://club.yourlabs.org


Languages

Language:Python 100.0%