basic app working
This commit is contained in:
parent
e5467af2e2
commit
84becd7537
73
printaform/formaprint/admin.py
Executable file
73
printaform/formaprint/admin.py
Executable file
|
@ -0,0 +1,73 @@
|
|||
from django.contrib import admin
|
||||
from models import *
|
||||
|
||||
|
||||
admin.site.register(Item)
|
||||
admin.site.register(ItemType)
|
||||
admin.site.register(ItemField)
|
||||
|
||||
|
||||
'''
|
||||
#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)
|
||||
'''
|
9
printaform/formaprint/forms.py
Normal file
9
printaform/formaprint/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from models import Item
|
||||
from django.forms import ModelForm
|
||||
|
||||
class ItemForm(ModelForm):
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
exclude = ('user', 'date_created', 'json',)
|
74
printaform/formaprint/models.py
Normal file
74
printaform/formaprint/models.py
Normal file
|
@ -0,0 +1,74 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
import datetime
|
||||
try:
|
||||
import json
|
||||
except:
|
||||
import simplejson as json
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context
|
||||
|
||||
class Item(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
title = models.CharField(max_length=255)
|
||||
date = models.DateField(null=True, blank=True)
|
||||
date_created = models.DateTimeField(default=datetime.datetime.now)
|
||||
json = models.TextField(blank=True)
|
||||
typ = models.ForeignKey('ItemType')
|
||||
is_private = models.BooleanField(default=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
obj.user = request.user
|
||||
obj.save()
|
||||
|
||||
def get_fields(self):
|
||||
fields = self.typ.fields.values()
|
||||
d = json.loads(self.json)
|
||||
for f in fields:
|
||||
short_name = f['short_name']
|
||||
f['value'] = d[short_name]
|
||||
return fields
|
||||
|
||||
def render(self):
|
||||
template_name = self.typ.template_name
|
||||
t = get_template("types/%s" % template_name)
|
||||
context = Context(json.loads(self.json))
|
||||
return t.render(context)
|
||||
|
||||
class ItemType(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
template_name = models.CharField(max_length=100)
|
||||
fields = models.ManyToManyField("ItemField")
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
FIELD_TYPES = (
|
||||
('short_text', 'Short Text Field'),
|
||||
('large_text', 'Large Text Field'),
|
||||
)
|
||||
|
||||
class ItemField(models.Model):
|
||||
short_name = models.CharField(max_length=20)
|
||||
description = models.CharField(max_length=255, blank=True)
|
||||
typ = models.CharField(choices=FIELD_TYPES, max_length=100)
|
||||
default_value = models.TextField(blank=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s: %s" % (self.short_name, self.description,)
|
||||
|
||||
|
||||
class AutoValue(models.Model):
|
||||
text = models.TextField()
|
||||
field = models.ForeignKey(ItemField)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
# Create your models here.
|
23
printaform/formaprint/tests.py
Normal file
23
printaform/formaprint/tests.py
Normal file
|
@ -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
|
||||
"""}
|
||||
|
78
printaform/formaprint/views.py
Normal file
78
printaform/formaprint/views.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Create your views here.
|
||||
from forms import ItemForm
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import get_object_or_404
|
||||
from models import *
|
||||
try:
|
||||
import json
|
||||
except:
|
||||
import simplejson as json
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from ox.django.shortcuts import render_to_json_response
|
||||
|
||||
def new_item(request):
|
||||
if request.POST:
|
||||
form = ItemForm(request.POST)
|
||||
if form.is_valid():
|
||||
new_item = form.save(commit=False)
|
||||
new_item.user = request.user
|
||||
fields = new_item.typ.fields.values()
|
||||
d = {}
|
||||
for f in fields:
|
||||
field_name = f['short_name']
|
||||
value = f['default_value']
|
||||
d[field_name] = value
|
||||
j = json.dumps(d)
|
||||
new_item.json = j
|
||||
new_item.save()
|
||||
id = new_item.id
|
||||
return HttpResponseRedirect('/edit_item/?id=%d' % id)
|
||||
else:
|
||||
form = ItemForm()
|
||||
context = RequestContext(request, {'form': form})
|
||||
return render_to_response("new_item.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_item(request):
|
||||
id = request.GET.get("id", 0)
|
||||
item = get_object_or_404(Item, pk=id)
|
||||
fields = item.get_fields()
|
||||
textinputs = []
|
||||
textareas = []
|
||||
for f in fields:
|
||||
if f['typ'] == 'short_text':
|
||||
textinputs.append(f)
|
||||
if f['typ'] == 'long_text':
|
||||
textareas.append(f)
|
||||
context = RequestContext(request, {
|
||||
'item': item,
|
||||
'textinputs': textinputs,
|
||||
'textareas': textareas
|
||||
})
|
||||
return render_to_response("edit_item.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def save_item(request):
|
||||
if not request.POST:
|
||||
return render_to_json_response('error')
|
||||
id = request.POST['item_id']
|
||||
item = get_object_or_404(Item, pk=id)
|
||||
d = {}
|
||||
for k in request.POST.keys():
|
||||
if k != 'item_id':
|
||||
d[k] = request.POST[k]
|
||||
j = json.dumps(d)
|
||||
item.json = j
|
||||
item.save()
|
||||
return render_to_json_response('ok')
|
||||
|
||||
|
||||
def render_item(request):
|
||||
id = request.GET.get("id", 0)
|
||||
item = get_object_or_404(Item, pk=id)
|
||||
return HttpResponse(item.render())
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
# Django settings for printaform project.
|
||||
import os
|
||||
from os.path import join
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(__file__)
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@domain.com'),
|
||||
)
|
||||
|
||||
LOCAL_DEVELOPMENT = True
|
||||
JSON_DEBUG = True
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASES = {
|
||||
|
@ -45,12 +50,12 @@ USE_L10N = True
|
|||
|
||||
# Absolute path to the directory that holds media.
|
||||
# Example: "/home/media/media.lawrence.com/"
|
||||
MEDIA_ROOT = ''
|
||||
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 = ''
|
||||
MEDIA_URL = '/static/'
|
||||
|
||||
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||
# trailing slash.
|
||||
|
@ -78,6 +83,7 @@ MIDDLEWARE_CLASSES = (
|
|||
ROOT_URLCONF = 'printaform.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.
|
||||
|
@ -90,7 +96,10 @@ INSTALLED_APPS = (
|
|||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
# Uncomment the next line to enable the admin:
|
||||
# 'django.contrib.admin',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.markup',
|
||||
'django_extensions',
|
||||
'formaprint',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
# 'django.contrib.admindocs',
|
||||
)
|
||||
|
|
8936
printaform/static/js/jquery.js
vendored
Normal file
8936
printaform/static/js/jquery.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
43
printaform/templates/edit_item.html
Normal file
43
printaform/templates/edit_item.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/static/js/jquery.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('#editForm').submit(function(e) {
|
||||
e.preventDefault();
|
||||
var postData = $(this).serializeArray();
|
||||
$.post("/save_item/", postData, function(response) {
|
||||
alert(response);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form action="." method="POST" id="editForm">
|
||||
{% csrf_token %}
|
||||
<input name="item_id" type="hidden" value="{{ item.id }}" />
|
||||
{% for i in textinputs %}
|
||||
<p>
|
||||
{{ i.description }}: <input type="text" name="{{ i.short_name }}" id="id_{{ i.short_name }}" value="{{ i.value }}" />
|
||||
</p>
|
||||
{% endfor %}
|
||||
|
||||
{% for t in textareas %}
|
||||
<p>
|
||||
<textarea name="{{ t.short_name }}" id="id_{{ t.short_name }}">{{ t.value }}</textarea>
|
||||
</p>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
<p>
|
||||
<input type="submit" />
|
||||
</p>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
8
printaform/templates/new_item.html
Normal file
8
printaform/templates/new_item.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
<form action="." method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
|
||||
<p><input type="submit" /></p>
|
||||
</form>
|
||||
|
1
printaform/templates/types/test.html
Normal file
1
printaform/templates/types/test.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ test_to }}: {{ test_from }}
|
|
@ -1,16 +1,28 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
import settings
|
||||
from os.path import join
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
# from django.contrib import admin
|
||||
# admin.autodiscover()
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Example:
|
||||
# (r'^printaform/', include('printaform.foo.urls')),
|
||||
|
||||
(r'^new_item/$', 'formaprint.views.new_item'),
|
||||
(r'^edit_item/$', 'formaprint.views.edit_item'),
|
||||
(r'^save_item/$', 'formaprint.views.save_item'),
|
||||
(r'^render_item/$', 'formaprint.views.render_item'),
|
||||
# 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)),
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
||||
if settings.LOCAL_DEVELOPMENT:
|
||||
#
|
||||
urlpatterns += patterns('',
|
||||
#
|
||||
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': join(settings.PROJECT_ROOT, "static")}),
|
||||
#
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user