Giter Club home page Giter Club logo

django-components's Introduction

django-components

An encapsulated thing that is meant to be reused across the site in many
different views. Product reviews box, little stats widgets, etc. It's meant to
be like a mini-version of a view that you can embed in another page.

Benefits: easy to reuse code, change things in only one place to change
them everywhere, cache components automatically, turn caching on and off
without changing the template. All client side code (js, css, html) for one
component is in one place. No mucking around with manual cache key
generating.

In your template, add:

    {% components_maker %}
    {% reviewscomponent subscriber %}

Ta da.

To build a new component, simply inherit Component and:
    - Override fetch_data to return the context for your component template
    - Override options to pass in any variables you need, like user ids.
    This is in Classytags format.
    - Declare name as the template file to use.
    - Optionally override any other (cache key, rendering) function for
    more complex behavior

Overridables:
    - cached=True: enable / disable cache.
    - cache_duration=60*60*24: cache time in seconds.
    - tag_name=classname.lower(): name of the template tag
    - template_name: Name of the template to use
    - cache_vary_on: List of attribute names to get the value of when
    generating a cache key. Defaults to detecting the template tag
    arguments and using those.
    - sekizai_blocks: Dictionary of blockname -> content to inject js /
    css / etc into the template.

TODO: maybe have post_render also cache subcontext data
TODO: look into disabling offline compression to get compression to play
nice with components/sekizai https://github.com/ojii/django-sekizai/issues/4

django-components's People

Contributors

haughwout avatar malicustommade avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.