Django: CBV based navigation

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
dbrgn
June 05, 2012

Django: CBV based navigation

A lightning talk about django-tabination (http://github.com/dbrgn/django-tabination) at Djangocon Zürich, 2012.

Nested tabs have since been implemented and released in v0.2.0.

dbrgn

June 05, 2012

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

19 slides
  1. Creating views from tabination . views import TabView class SpamTab(TabView

    ) : _is_tab = True tab_id = ’spam’ tab_group = ’mainnav ’ tab_label = ’Spam’ template_name = ’spam. html ’
  2. Another view class HamTab(TabView ) : _is_tab = True tab_id

    = ’ham’ tab_group = ’mainnav ’ tab_label = ’Ham’ template_name = ’ham. html ’
  3. urls.py urlpatterns = patterns ( ’ ’ , url (

    r ’^spam/$ ’ , views .SpamTab. as_view ( ) ) , url ( r ’^ ham/$ ’ , views .HamTab. as_view ( ) ) , )
  4. DRY? class SpamTab(TabView ) : _is_tab = True tab_id =

    ’spam’ tab_group = ’mainnav ’ tab_label = ’Spam’ template_name = ’spam. html ’ class HamTab(TabView ) : _is_tab = True tab_id = ’ham’ tab_group = ’mainnav ’ tab_label = ’Ham’ template_name = ’ham. html ’
  5. DRY! class BaseTab(TabView ) : tab_group = ’mainnav ’ class

    SpamTab(BaseTab) : _is_tab = True tab_id = ’spam’ tab_label = ’Spam’ template_name = ’spam. html ’ class HamTab(BaseTab) : _is_tab = True tab_id = ’ham’ tab_label = ’Ham’ template_name = ’ham. html ’
  6. Extending BaseTab class BaseTab(TabView ) : tab_group = ’mainnav ’

    tab_classes = [ ’main−navigation−tab ’ ] def get_context_data ( self , **kwargs ) : context = super(BaseTab, self ) . get_context_data (**kwargs) context [ ’spam’ ] = "SPAM −EVERYWHERE! " return context
  7. Visibility control class HiddenTab(BaseTab) : _is_tab = True tab_id =

    ’hidden ’ template_name = ’hidden . html ’ # look mah, no tab_label !
  8. Visibility control class SecretTab(BaseTab) : _is_tab = True . .

    . @property def tab_visible ( self ) : current_tab = self . current_tab user = current_tab . request . user return user . is_authenticated ()
  9. Not so nice things Metaclass magic CBVs, Complexity Other tab

    classes are instantiated but not dispatched Currently no support for nested tabs

More Decks by dbrgn

Other Decks in Programming