Git Product home page Git Product logo

django-purr's Introduction

Django Purr

......................................
........../\............./\...........
........./..\.........../..\..........
.......././\.\__-----__/./\.\.........
......./.....................\........
......|.....(.o.).__.(.o.)....|.......
.....~~~~~~...../.ºº.\.....~~~~~~.....
...~~~~~~....(.../--\...)....~~~~~~...
........\\.......PURR.......//........
............\\\/\/||\/\///............
..................\/..................
......................................

Testing a solution to read unlimited categories from a URI.


ABOUT

The Category model was taken from Satchmo Project, I've only added slight modifications.

Note: Tested using Django (1, 3, 0, 'final', 0).


DISCUSSION

Django categories, sub-categories and sub-sub-categories


INSTALLATION

Using PIP.

The repository will be checked out in a temporary folder, installed, and cleaned up:

$ pip install git+https://github.com/mhulse/django-purr.git

This can be combined with the -e flag, and Pip will perform the checkout in ./src/. You need to supply a name for the checkout folder by appending a hash to the repository URL:

$ pip install -e git+https://github.com/mhulse/django-purr.git#egg=django-purr

More info here.

Next, add purr to your INSTALLED_APP in your app's settings.py:

INSTALLED_APPS = (
    # ...
    'purr',
    # ...
)

Finally, add this to your app's urls.py tuple:

urlpatterns = patterns('',
    # ...
    (r'^purr/', include('purr.urls')),
    # ...
)

Upgrade using:

$ pip install --upgrade git+https://github.com/mhulse/django-purr.git

… and migrate your schema accordingly.

Uninstall using:

$ pip uninstall django-purr

EXAMPLES

Given this URI:

http://site.com/purr/business/delivery-only/italian/pizza/

… the output will simply be:

{
    "category": "Pizza"
}

The code itterates over each sequential category slug and and will throw a Page not found (404) if the category structure doesn't exist; for example:

http://testprojects.registerguard.com/purr/business/delivery-only/ddd/pizza/

… won't work because category slug ddd doesn't exist as a child to /business/delivery-only/.

There's a tester script, found in the scripts folder, that you can run like so:

$ python manage.py runscript purr_tests

… the output will be (it will help if you've installed the initial_data.json fixture):

[<Category: Business>,
 <Category: BUSINESS | Sports>,
 <Category: BUSINESS | SPORTS | Eating contest>,
 <Category: BUSINESS | SPORTS | EATING CONTEST | Pizza>]

LEGAL

Copyright © 2012 Micky Hulse

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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.