Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit fb75e81d1f0e134b022807199a4b69b98d0eb4cc @revolunet committed Oct 27, 2011
Showing with 269 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +11 −0 README.md
  3. 0 __init__.py
  4. BIN data.db
  5. 0 example/__init__.py
  6. +20 −0 example/api.py
  7. +17 −0 example/models.py
  8. +23 −0 example/tests.py
  9. +1 −0 example/views.py
  10. +1 −0 fixture.json
  11. +61 −0 gendata.py
  12. +11 −0 manage.py
  13. +95 −0 settings.py
  14. +27 −0 urls.py
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+*.pyc
11 README.md
@@ -0,0 +1,11 @@
+django-tasty
+===
+
+Simple project for experimenting with django-tastypie
+
+Exposes some models through REST
+
+Requirements :
+
+ - django
+ - django-tastypie
0 __init__.py
No changes.
BIN data.db
Binary file not shown.
0 example/__init__.py
No changes.
20 example/api.py
@@ -0,0 +1,20 @@
+from tastypie import fields
+from tastypie.resources import ModelResource
+
+import models
+
+
+class CompanyResource(ModelResource):
+ employees = fields.ToManyField('example.api.EmployeeResource', 'employee_set', related_name='company')
+
+ class Meta:
+ default_format = 'json'
+ queryset = models.Company.objects.all()
+
+
+class EmployeeResource(ModelResource):
+ company = fields.ToOneField(CompanyResource, 'company', full = True)
+
+ class Meta:
+ default_format = 'json'
+ queryset = models.Employee.objects.all()
17 example/models.py
@@ -0,0 +1,17 @@
+# -*- encoding: UTF-8 -*-
+
+from django.db import models
+
+# Create your models here.
+
+
+class Company(models.Model):
+ name = models.CharField(max_length=255)
+
+
+class Employee(models.Model):
+ first_name = models.CharField(max_length=255)
+ last_name = models.CharField(max_length=255)
+ birthdate = models.DateField(null=True, blank=True)
+ salary = models.IntegerField(default=0)
+ company = models.ForeignKey(Company)
23 example/tests.py
@@ -0,0 +1,23 @@
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+
1 example/views.py
@@ -0,0 +1 @@
+# Create your views here.
1 fixture.json
1 addition, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
61 gendata.py
@@ -0,0 +1,61 @@
+# -*- encoding: UTF-8 -*-
+
+import datetime
+import random
+from example import models
+
+compagnies = ["20th Century Fox Animation", "A. Film", "A Squared Entertainment", "Aardman Animations", "Ace&Son", "Act3animation", "Adelaide Productions", "AKOM", "Anima Studios", "Animafilm", "Animal Logic", "Animation Collective", "Animax Entertainment", "Anzovin Studio", "Arc Productions", "Atomic Cartoons", "Augenblick Studios", "Bagdasarian Productions", "Bee Train", "Bent Image Lab", "Big Idea Productions", "Blue Sky Studios", "Blue-Zoo", "bolexbrothers", "BONES", "BRB International", "Brown Bag Films", "Buzzco Associates", "Bullwinkle Studios", "Cartoon Pizza/Jumbo Pictures", "Cartoon Network Studios", "Cartoon Saloon", "CinéGroupe", "Clockwork Zoo Animation", "Collingwood O'Hare Entertainment", "Cookie Jar Group", "Cosgrove Hall Films", "Cosmic Toast Studios", "Creative Capers Entertainment", "Crest Animation Studios", "Cuckoo's Nest Studio", "Cuppa Coffee Studio", "The Curiosity Company", "Curious Pictures", "Def2shoot", "DisneyToon Studios", "Don Bluth Films, Inc.", "DreamWorks Animation", "DR Movie", "Dong Woo Animation", "Eiken", "EMation", "Fatkat", "Felix the Cat Productions", "Film Roman, Inc.", "Fine Arts Films", "Folimage", "Fox Animation Studios", "Fred Wolf Films Dublin", "Frederator Studios", "Future Thought Productions", "Gainax", "Global Mechanic", "Gonzo", "Group TAC", "Guru Studios", "H5", "Hanho Heung-Up", "Head-Gear Animation", "Hong Ying Animation", "House of Cool", "Ilion Animation Studios", "Illumination Entertainment", "Imagi Animation Studios", "Industrial Light & Magic", "J.C.Staff", "Jetix Animation Concepts", "JibJab", "John Lemmon Films", "Kandor Graphics", "Klasky Csupo", "Koko Enterprises", "Kyoto Animation", "LAIKA", "Lambie-Nairn", "Les' Copaque Production", "Littlenobody", "Lucasfilm Animation", "Mac Guff", "Madhouse", "March Entertainment", "Marvel Animation", "Marwah Films & Video Studios", "Melnitsa Animation Studio", "Metro-Goldwyn-Mayer Animation", "Mike Young Productions", "Mirari Films", "Mondo Mini Shows", "MoonScoop Group", "National Film Board of Canada", "Nelvana", "Nickelodeon Animation Studios", "Nippon Animation", "O Entertainment/Omation Animation Studio", "Pacific Data Images", "PannóniaFilm", "Paramount Animation", "Pentamedia Graphics", "The People's Republic of Animation", "Pixar", "Pipeline Studios Inc.", "Plus One Animation", "Post Amazers", "Powerhouse Animation Studios, Inc.", "Premavision/Clokey Productions", "Production I.G", "Production Reed", "Radicial Axis", "Rainmaker Digital Effects", "Renegade Animation", "Richard Williams Animation", "RingTales", "Rubicon Group Holding", "Rhythm and Hues Studios", "Rough Draft Studios", "Sae Rom", "Savage Studios Ltd.", "Se-ma-for", "Six Point Harness", "Skycron", "Smallfilms", "ŠAF", "Shademaker Productions", "SHAFT", "Sony Pictures Animation", "Soup2Nuts", "Soyuzmultfilm", "Sparx*", "Spectrum Animation", "Spümcø", "Spy Pictures", "Start Anima", "Stretch Films", "Studio 4°C", "Studio B", "Studio DEEN", "Studio Comet", "Studio Gallop", "Studio Ghibli", "Studio Pierrot", "Sumo Dojo", "Sunrise", "Sunwoo Entertainment", "Tatsunoko Productions", "Tim Burton Animation Co.", "Titmouse", "Toei Animation", "Teletoon Canada", "TMS", "Toon City", "Toondra", "Toonz", "Universal Animation Studios", "Varga Studio", "Vanguard Animation", "Walt Disney Animation Studios", "Walt Disney Television Animation", "Wang Film Productions", "Warner Bros. Animation", "W!LDBRAIN", "Williams Street Studios", "Xebec", "Xilam", "Xyzoo Animation", "Yowza! Animation", "Zagreb school of animated films"]
+
+noms = ["Martin", "Legrand", "Bernard", "Garnier", "Dubois", "Faure", "Thomas", "Rousseau", "Robert", "Blanc", "Richard", "Guerin", "Petit", "Muller", "Durand", "Henry", "Leroy", "Roussel", "Moreau", "Nicolas", "Simon", "Perrin", "Laurent", "Morin", "Lefebvre", "Mathieu", "Michel", "Clement", "Garcia", "Gauthier", "David", "Dumont", "Bertrand", "Lopez", "Roux", "Fontaine", "Vincent", "Chevalier", "Fournier", "Robin", "Morel", "Masson", "Girard", "Sanchez", "Andre", "Gerard", "Lefevre", "Nguyen", "Mercier", "Boyer", "Dupont", "Denis", "Lambert", "Lemaire", "Bonnet", "Duval", "Francois", "Joly", "Martinez", "Gautier", "Roger", "Bourgeois", "Roche", "Renaud", "Roy", "Lemoine", "Noel", "Picard", "Meyer", "Gaillard", "Lucas", "Philippe", "Meunier", "Leclercq", "Jean", "Lacroix", "Perez", "Fabre", "Marchand", "Dupuis", "Dufour", "Olivier", "Blanchard", "Rodriguez", "Marie", "Da", "Barbier", "Hubert", "Brun", "Louis", "Dumas", "Charles", "Brunet", "Guillot", "Schmitt", "Riviere", "Leroux", "Le", "Colin", "Guillaume", "Fernandez", "Adam", "Pierre", "Rey", "Renard", "Moulin", "Arnaud", "Gonzalez", "Rolland", "Berger", "Caron", "Lecomte", "Aubert", "Menard", "Giraud", "Fleury", "Leclerc", "Deschamps", "Vidal", "Carpentier"]
+
+prenoms = ["Léa", "Manon", "Chloé", "Camille", "Emma", "Océane", "Sarah",
+ "Marie", "Laura", "Julie", "Mathilde", "Clara", "Lucie", "Ines", "Pauline",
+ "Marine", "Anaïs", "Lisa", "Maeva", "Justine", "Juliette", "Charlotte",
+ "Eva", "Emilie", "Morgane", "Louise", "Marion", "Jade", "Clémence",
+ "Margaux", "Célia", "Elisa", "Mélissa", "Noémie", "Jeanne", "Amandine",
+ "Alice", "Amélie", "Romane", "Elise", "Zoe", "Elodie", "Margot", "Lola",
+ "Mélanie", "Lena", "Carla", "Laurine", "Alicia", "Audrey", "Fanny",
+ "Agathe", "Solène", "Claire", "Kenza", "Alizée", "Maelle", "Ambre",
+ "Lou", "Valentine", "Elsa", "Anna", "Laurie", "Cassandra", "Alexia",
+ "Axelle", "Salomé", "Andréa", "Coralie", "Eloïse", "Emeline", "Flavie",
+ "Estelle", "Julia", "Caroline", "Sophie", "Nina", "Victoria", "Alexandra",
+ "Clarisse", "Laure", "Myriam", "Aurélie", "Marina", "Coline", "Lise",
+ "Céline", "Maëlys", "Ophélie", "Laetitia", "Cloé", "Ilona", "Clémentine",
+ "Anaëlle", "Lina", "Yasmine", "Jessica", "Héloïse", "Léonie", "Charline",
+ "Thomas", "Lucas", "Théo", "Hugo", "Maxime", "Antoine", "Quentin",
+ "Clément", "Alexandre", "Nicolas", "Alexis", "Enzo", "Valentin", "Julien",
+ "Paul", "Louis", "Léo", "Florian", "Romain", "Benjamin", "Tom", "Baptiste",
+ "Pierre", "Arthur", "Adrien", "Anthony", "Dylan", "Nathan", "Kevin",
+ "Corentin", "Mathieu", "Guillaume", "Mathis", "Axel", "Victor", "Jules",
+ "Vincent", "Mattéo", "Simon", "Maxence", "Jérémy", "Bastien", "Samuel",
+ "Loïc", "Tristan", "Damien", "Rémi", "Yanis", "Raphaël", "Thibault",
+ "Dorian", "Gabriel", "Martin", "Killian", "Jordan", "Matthieu", "Mohamed",
+ "Mathéo", "Aurélien", "William", "Robin", "Yann", "David", "Mehdi",
+ "Antonin", "Bryan", "Tanguy", "Arnaud", "Thibaut", "Mael", "Erwan", "Alex",
+ "Jonathan", "Charles", "Sébastien", "Steven", "Mathias", "Gaëtan", "Matéo",
+ "Tony", "Evan", "Benoît", "Jean", "Rémy", "Ryan", "Adam", "Mickaël",
+ "Lilian", "Rayan", "Christopher", "François", "Sofiane", "Alan", "Fabien",
+ "Sacha", "Esteban", "Jason", "Florent", "Kylian", "Etienne"]
+
+
+def generate():
+ # reset
+ models.Company.objects.all().delete()
+ models.Employee.objects.all().delete()
+ # generate
+ nbemployees = 0
+ for comp in compagnies:
+ c = models.Company(name=comp)
+ c.save()
+ for i in range(random.randint(1,50)):
+ nbemployees += 1
+ ddn = datetime.date(random.choice(range(1950, 1990)),
+ random.choice(range(1, 13)), random.choice(range(1, 29)))
+ p = models.Employee(first_name=random.choice(prenoms),
+ last_name=random.choice(noms), company=c,
+ birthdate=ddn, salary=random.choice(range(1000, 5000, 500)))
+ p.save()
+ print "generated %s companies and %s employees" % (len(compagnies), nbemployees)
+
+if __name__ == '__main__':
+ generate()
11 manage.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
95 settings.py
@@ -0,0 +1,95 @@
+# Django settings for project project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'data.db', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '=e9hth)1o7yjnegrm@%ypv)6t0@i=xze@tx_(1etnbj7e)5s*1'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'project.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'example'
+ # Uncomment the next line to enable the admin:
+ # 'django.contrib.admin',
+)
27 urls.py
@@ -0,0 +1,27 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+from tastypie.api import Api
+from example import api
+
+v1_api = Api(api_name='v1')
+v1_api.register(api.CompanyResource())
+v1_api.register(api.EmployeeResource())
+
+urlpatterns = patterns('',
+ # Example:
+ # (r'^project/', include('project.foo.urls')),
+
+ # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
+ # to INSTALLED_APPS to enable admin documentation:
+ # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ # Uncomment the next line to enable the admin:
+ # (r'^admin/', include(admin.site.urls)),
+
+ (r'^api/', include(v1_api.urls)),
+
+)

0 comments on commit fb75e81

Please sign in to comment.
Something went wrong with that request. Please try again.