basic templates for objects / edit form working
This commit is contained in:
parent
03a74f4da5
commit
c4616f1ad9
|
@ -77,11 +77,19 @@ class ItfModel(models.Model):
|
|||
d['text'] = d['text'][:150] + "..."
|
||||
return d
|
||||
|
||||
#This should return all the context for the object that will get passed to the sub-template for this object.
|
||||
|
||||
def info_dict(self):
|
||||
'''
|
||||
Ideally you should not over-ride this - over-ride .get_dict() to pass custom data.
|
||||
'''
|
||||
d = self.get_dict()
|
||||
# d['add_form'] = self.__class__.get_add_form()
|
||||
d['forms'] = self.__class__.get_forms()
|
||||
try:
|
||||
edit_url = self.get_edit_url()
|
||||
d['edit_url'] = edit_url
|
||||
except:
|
||||
pass
|
||||
return d
|
||||
|
||||
|
||||
|
@ -152,6 +160,12 @@ class ItfModel(models.Model):
|
|||
def get_absolute_url(self):
|
||||
return "%s/?tab=%s&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().slug, self.id)
|
||||
|
||||
|
||||
def get_edit_url(self):
|
||||
'''
|
||||
Get the Edit URL for this object
|
||||
'''
|
||||
return "%s/%s/%d/edit" % (self.get_module().get_absolute_url(), self.get_tab().slug, self.id)
|
||||
|
||||
'''
|
||||
Get insidepages.models.Module instance for this object
|
||||
|
|
|
@ -7,6 +7,6 @@ urlpatterns = patterns('',
|
|||
# (r'^get_tab$', views.get_tab),
|
||||
#(r'^static/(?P<module_slug>.*)/$', views.render_object),
|
||||
(r'^(?P<module_slug>.*?)/(?P<tab_slug>.*?)/add', views.add_object),
|
||||
(r'^(?P<module_slug>.*?)/(?P<tab_slug>.*?)/(?P<object_id>d+)/edit', views.edit_object),
|
||||
(r'^(?P<module_slug>.*?)/(?P<tab_slug>.*?)/(?P<object_id>[0-9]+)/edit', views.edit_object),
|
||||
(r'^(?P<module_slug>.*)/$', views.render_object),
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.shortcuts import render_to_response, get_object_or_404
|
|||
from django.template import RequestContext
|
||||
from ox.django.shortcuts import render_to_json_response
|
||||
import re
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
||||
|
||||
def add_object(request, module_slug, tab_slug):
|
||||
|
@ -56,7 +56,7 @@ def edit_object(request, module_slug, tab_slug, object_id):
|
|||
|
||||
if request.POST:
|
||||
f = form(request.POST, request.FILES, instance=obj)
|
||||
inlines = [inline(request.POST, request.FILES, instance=person) for inline in f.inlines]
|
||||
inlines = [inline(request.POST, request.FILES, instance=obj) for inline in f.inlines]
|
||||
if f.is_valid():
|
||||
instance = f.save()
|
||||
all_valid = True
|
||||
|
@ -67,9 +67,9 @@ def edit_object(request, module_slug, tab_slug, object_id):
|
|||
all_valid = False
|
||||
if all_valid:
|
||||
return HttpResponseRedirect(instance.get_absolute_url())
|
||||
else:
|
||||
f = form(instance=obj)
|
||||
inlines = [inline(instance=obj) for inline in f.inlines]
|
||||
#else:
|
||||
#f = form(instance=obj)
|
||||
#inlines = [inline(instance=obj) for inline in f.inlines]
|
||||
else:
|
||||
f = form(instance=obj)
|
||||
inlines = [inline(instance=obj) for inline in f.inlines]
|
||||
|
|
|
@ -66,6 +66,12 @@ class Person(ItfModel):
|
|||
def get_title(self):
|
||||
return self.__unicode__()
|
||||
|
||||
def get_dict(self):
|
||||
return {
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'about': self.about
|
||||
}
|
||||
|
||||
OCCUPATION_TYPES = (
|
||||
('practitioner', 'Practitioner'),
|
||||
|
@ -222,7 +228,14 @@ class Production(ItfModel):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
def get_dict(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'anecdotes': self.anecdotes,
|
||||
'group': self.group,
|
||||
'director': self.director,
|
||||
'playwright': self.playwright
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<span class="orange">Name: </span>{{ first_name }} {{ last_name }} <br />
|
||||
|
||||
<div class="orange">About: </div>
|
||||
<p>
|
||||
{{ about }}
|
||||
|
||||
</p>
|
|
@ -0,0 +1,21 @@
|
|||
<span class="orange">Production name: </span> {{ name }}
|
||||
|
||||
{% if anecdotes %}
|
||||
<div class="orange">Anecdotes</div>
|
||||
<p>{{ anecdotes }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if group %}
|
||||
<span class="orange">Group: </span> <a href="{{ group.get_absolute_url }}">{{ group.name }}</a> <br />
|
||||
{% endif %}
|
||||
|
||||
{% if director %}
|
||||
<span class="orange">Director: </span><a href="{{ director.get_absolute_url }}">{{ director.get_title }}</a><br />
|
||||
{% endif %}
|
||||
|
||||
{% if playwright %}
|
||||
<span class="orange">Playwright: </span><a href="{{ playwright.get_absolute_url }}">{{ playwright.get_title }}</a>
|
||||
{% endif %}
|
||||
|
||||
<br />
|
||||
<a href="{{ edit_url }}">Edit</a>
|
Loading…
Reference in New Issue
Block a user