From e7580fe66093181ed74270fb25879e3dec229983 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 15 Aug 2011 19:24:24 +0530 Subject: [PATCH] added stuff --- mofca/__init__.py | 0 mofca/manage.py | 11 ++++ mofca/recipes/__init__.py | 0 mofca/recipes/admin.py | 101 +++++++++++++++++++++++++++++++++++ mofca/recipes/models.py | 106 ++++++++++++++++++++++++++++++++++++ mofca/recipes/tests.py | 23 ++++++++ mofca/recipes/views.py | 5 ++ mofca/settings.py | 109 ++++++++++++++++++++++++++++++++++++++ mofca/urls.py | 16 ++++++ 9 files changed, 371 insertions(+) create mode 100644 mofca/__init__.py create mode 100644 mofca/manage.py create mode 100644 mofca/recipes/__init__.py create mode 100755 mofca/recipes/admin.py create mode 100644 mofca/recipes/models.py create mode 100644 mofca/recipes/tests.py create mode 100644 mofca/recipes/views.py create mode 100644 mofca/settings.py create mode 100644 mofca/urls.py diff --git a/mofca/__init__.py b/mofca/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mofca/manage.py b/mofca/manage.py new file mode 100644 index 0000000..5e78ea9 --- /dev/null +++ b/mofca/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) diff --git a/mofca/recipes/__init__.py b/mofca/recipes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mofca/recipes/admin.py b/mofca/recipes/admin.py new file mode 100755 index 0000000..eee3604 --- /dev/null +++ b/mofca/recipes/admin.py @@ -0,0 +1,101 @@ +from django.contrib import admin +from models import * + +class OtherIngredientInline(admin.StackedInline): + model = OtherIngredient + extra = 5 + +class AlternativeNameInline(admin.StackedInline): + model = AlternativeName + extra = 3 + +class TokriImageInline(admin.StackedInline): + model = TokriImage + extra = 3 + +class VegetableLinkInline(admin.StackedInline): + model = VegetableLink + extra = 2 + +class RecipeTokriInline(admin.TabularInline): + model = Recipe.tokri_ingredients.through + +class RecipeAdmin(admin.ModelAdmin): + inlines = [RecipeTokriInline, OtherIngredientInline] + prepopulated_fields = {'slug': ('title',)} + +class TokriAdmin(admin.ModelAdmin): + inlines = [AlternativeNameInline, TokriImageInline, VegetableLinkInline] + prepopulated_fields = {'slug': ('name',)} + +admin.site.register(Recipe, RecipeAdmin) +admin.site.register(TokriVegetable, TokriAdmin) +admin.site.register(Season) +admin.site.register(Language) +admin.site.register(VegetableType) + + +''' +#class NicknameInline(admin.StackedInline): +# model = Nickname +# extra = 3 + +#class LinkInlineModelAdmin(admin.InlineModelAdmin): +# pass + +#class LinkInline(LinkInlineModelAdmin): +# model = Link +# extra = 3 + +class ProfileInline(admin.StackedInline): + model = Person + extra = 1 + +class PerformanceAdmin(admin.ModelAdmin): + filter_horizontal = ('links', 'images') + +class EventAdmin(admin.ModelAdmin): + filter_horizontal = ('links',) + +class ProfileAdmin(admin.ModelAdmin): + filter_horizontal = ('links', 'files', 'images',) +# inlines = [NicknameInline] +# inlines = [LinkInline] + +class VenueAdmin(admin.ModelAdmin): + ordering = ('name',) + prepopulated_fields = {'slug': ('name',)} + filter_horizontal = ('links', 'images') + +class TheatreGroupAdmin(admin.ModelAdmin): + prepopulated_fields = {'slug': ('name',)} + filter_horizontal = ('links', 'files', 'images') + +class ProductionAdmin(admin.ModelAdmin): + prepopulated_fields = {'slug': ('title',)} + filter_horizontal = ('links', 'files', 'images',) + inlines = [ProfileInline] + +class ScriptAdmin(admin.ModelAdmin): + filter_horizontal = ('links', 'downloads') + + +#admin.site.register(Nickname3) +#admin.site.register(Nickname2) +admin.site.register(Performance, PerformanceAdmin) +admin.site.register(Event, EventAdmin) +admin.site.register(Location) +admin.site.register(ProfileProfile) +admin.site.register(ProfileGroup) +admin.site.register(Script, ScriptAdmin) +admin.site.register(Production, ProductionAdmin) +admin.site.register(Image) +admin.site.register(File) +admin.site.register(Link) +admin.site.register(RandomQuote) +admin.site.register(ProfileProduction) +admin.site.register(Nickname) +admin.site.register(TheatreGroup, TheatreGroupAdmin) +admin.site.register(Venue, VenueAdmin) +admin.site.register(Profile, ProfileAdmin) +''' diff --git a/mofca/recipes/models.py b/mofca/recipes/models.py new file mode 100644 index 0000000..e3b37ba --- /dev/null +++ b/mofca/recipes/models.py @@ -0,0 +1,106 @@ +from django.db import models + +class Recipe(models.Model): + title = models.CharField(max_length=255) + slug = models.SlugField() + description = models.TextField(blank=True) + tokri_ingredients = models.ManyToManyField("TokriVegetable", through='RecipeTokri') + preparation = models.TextField(blank=True) + serves = models.IntegerField(null=True, help_text="Serves approximately how many people?", blank=True) + preparation_time = models.IntegerField(null=True, help_text="Approximate time to make, in minutes", blank=True) + + + def __unicode__(self): + return self.title + + +class TokriVegetable(models.Model): + name = models.CharField(max_length=255) + types = models.ManyToManyField("VegetableType", blank=True) + slug = models.SlugField() + description = models.TextField(blank=True) + main_image = models.ImageField(upload_to='veggie_main_images', null=True) + season = models.ForeignKey("Season", null=True) + + def __unicode__(self): + return self.name + +class VegetableType(models.Model): + name = models.CharField(max_length=255) + description = models.TextField(blank=True) + + def __unicode__(self): + return self.name + + +class VegetableLink(models.Model): + url = models.URLField() + caption = models.CharField(max_length=512, blank=True) + vegetable = models.ForeignKey(TokriVegetable) + + def __unicode__(self): + return self.url + +MONTH_CHOICES = ( + ('Jan', 'January'), + ('Feb', 'February'), + ('Mar', 'March'), + ('Apr', 'April'), + ('May', 'May'), + ('Jun', 'June'), + ('Jul', 'July'), + ('Aug', 'August'), + ('Sep', 'September'), + ('Oct', 'October'), + ('Nov', 'November'), + ('Dec', 'December'), +) + +class Season(models.Model): + name = models.CharField(max_length=255) + start_month = models.CharField(max_length=5, choices=MONTH_CHOICES) + end_month = models.CharField(max_length=5, choices=MONTH_CHOICES) + + def __unicode__(self): + return self.name + +class RecipeTokri(models.Model): + recipe = models.ForeignKey(Recipe) + tokri_ingredient = models.ForeignKey(TokriVegetable) + amount = models.CharField(max_length=255, blank=True) + + +class AlternativeName(models.Model): + ingredient = models.ForeignKey(TokriVegetable) + name_roman = models.CharField(max_length=255) + name_unicode = models.CharField(max_length=255) + language = models.ForeignKey("Language", null=True) + + def __unicode__(self): + return self.name_roman + + +class Language(models.Model): + name = models.CharField(max_length=255) + lang_code = models.CharField(max_length=4) + + def __unicode__(self): + return self.name + + +class OtherIngredient(models.Model): + name = models.CharField(max_length=255) + amount = models.CharField(max_length=255) + recipe = models.ForeignKey(Recipe) + + def __unicode__(self): + return self.name + +class TokriImage(models.Model): + ingredient = models.ForeignKey(TokriVegetable) + image = models.ImageField(upload_to='veggie_images') + caption = models.CharField(max_length=512, blank=True) + + def __unicode__(self): + return self.caption +# Create your models here. diff --git a/mofca/recipes/tests.py b/mofca/recipes/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/mofca/recipes/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 +"""} + diff --git a/mofca/recipes/views.py b/mofca/recipes/views.py new file mode 100644 index 0000000..79e8101 --- /dev/null +++ b/mofca/recipes/views.py @@ -0,0 +1,5 @@ +# Create your views here. +from django.http import HttpResponseRedirect + +def index(request): + return HttpResponseRedirect("http://blog.mofca.in") diff --git a/mofca/settings.py b/mofca/settings.py new file mode 100644 index 0000000..8291b5f --- /dev/null +++ b/mofca/settings.py @@ -0,0 +1,109 @@ +# Django settings for mofca project. +import os +from os.path import join + +PROJECT_ROOT = os.path.dirname(__file__) + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'mofca', # Or path to database file if using sqlite3. + 'USER': 'root', # 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 filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = join(PROJECT_ROOT, 'static') + +# 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 = '/static/' + +# 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 = 'asdkhfoq839861874scvliayw3o87623rv' + + +# 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 = 'mofca.urls' + +TEMPLATE_DIRS = ( + join(PROJECT_ROOT, "templates"), + # 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', + 'django_extensions', + 'recipes', + # Uncomment the next line to enable the admin: + 'django.contrib.admin', + # Uncomment the next line to enable admin documentation: + 'django.contrib.admindocs', +) + +try: + from local_settings import * +except: + pass diff --git a/mofca/urls.py b/mofca/urls.py new file mode 100644 index 0000000..0250880 --- /dev/null +++ b/mofca/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls.defaults import * + +# Uncomment the next two lines to enable the admin: +from django.contrib import admin +admin.autodiscover() + +urlpatterns = patterns('', + # Example: + # (r'^mofca/', include('mofca.foo.urls')), + (r'^$', 'recipes.views.index'), + # Uncomment the admin/doc line below 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)), +)