GithubHelp home page GithubHelp logo

oriflamme's Introduction

oriflamme

Django class-based views with flags.

How to install

From GitHub

Run the command:

pip install git+git://github.com/jleeothon/oriflamme.git

Packaging yourself

  1. Download the oriflamme folder.
  2. Run python setup.py sdist. This will generate a .tar.gz file inside a dist folder.
  3. install by running pip install path/to/your/dist/oriflamme-0.1.tar.gz

Use case

Sometimes you want to set certain flags (i.e. boolean objects) to exist and probably be True in some of your templates. Maybe for one or two templates, you don't really need to install an app. Nonetheless, let's say you have types of templates or views; the easiest example could be creating views, updating views, etc.

When using class based views, adding a couple of variables to the context dictionary can be a bit of a fuss:

# views.py

class CreateCookieView(CreateView):

    model = Cookie

    def get_context_data(self, **kwargs):
        context = super(CreateCookieView, self).get_context_data(**kwargs)
        context['is_creating'] = True
        context['should_show_red_button'] = True
        return context

Now, let's say you also need those variables to be set in the CreateIceCreamView and CreateBubbleTeaView.

Instead of repeating the forementioned lines, you can add the flags in a single line using the FlagMixin:

# views.py

from oriflamme import FlagMixin

class CreateCookieView(FlagMixin, CreateView):

    template_flags = ('is_creating', 'should_show_red_button')
You can use this in custom parent class-based views, or individual class-based views as needed.

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.