GithubHelp home page GithubHelp logo

showmenu's Introduction

showmenu

An app to preview how the show_menu template tag in django CMS would render a given page tree. Not for the faint of heart!

Installing

Clone project, make virtualenv, install requirements.txt, run foreman start.

How it works

app.py is the public facing HTTP/WS interface. On startup, it loads all static files into memory as well as the index page. It then serves these over HTTP to users.

When a user visits the site (at /), they connect to the app via a websocket.

Once a websocket connection is established, the app starts a long running Django management command for that websocket with which it communicates over stdin/stdout.

When the app sends a command to the management command, it sends the command name, followed by a colon, followed by the length of the payload, followed by a newline character, followed by the payload (encoded as UTF-8). For example to select to_level to 2, it would send: set_attribute:1\n2.

The management command responds with the length of the payload, followed by a newline, followed by the actual data (encoded as UTF-8). A simple tree with a single page with title Home would look something like this: 40\n[{"title": "Home", "url": "/", "id": 2}]

The management command supports two commands: set_tree and set_attribute.

set_tree is followed by a page tree in an angular-ui-tree compatible format. On the first call, it simply creates the tree in the in-memory Sqlite database. On subsequent calls, it diffs the trees with the last tree it got and modifies the database accordingly. It then returns the menu tree. Both the input and the output trees are UTF-8 encoded JSON objects.

set_attribute sets one of the four arguments to show_menu ( from_level, to_level, extra_inactive, extra_active) and returns the menu tree.

To generate the menu tree to return, the management command uses a custom Django template that calls show_menu with a custom template, which directly generates JSON.

showmenu's People

Contributors

ojii avatar

Watchers

 avatar James Cloos avatar  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.