From c4616f1ad972e0e1b4709dfe0736a71ea057f7cc Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 31 Jul 2012 00:53:01 +0530 Subject: [PATCH] basic templates for objects / edit form working --- itf/app/models.py | 16 +++++++++++++- itf/insidepages/urls.py | 2 +- itf/insidepages/views.py | 10 ++++----- itf/itfprofiles/models.py | 15 ++++++++++++- itf/templates/modules/itfprofiles/person.html | 7 +++++++ .../modules/itfprofiles/production.html | 21 +++++++++++++++++++ 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 83dd724..fad234b 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -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 diff --git a/itf/insidepages/urls.py b/itf/insidepages/urls.py index a2c356e..5fe1255 100755 --- a/itf/insidepages/urls.py +++ b/itf/insidepages/urls.py @@ -7,6 +7,6 @@ urlpatterns = patterns('', # (r'^get_tab$', views.get_tab), #(r'^static/(?P.*)/$', views.render_object), (r'^(?P.*?)/(?P.*?)/add', views.add_object), - (r'^(?P.*?)/(?P.*?)/(?Pd+)/edit', views.edit_object), + (r'^(?P.*?)/(?P.*?)/(?P[0-9]+)/edit', views.edit_object), (r'^(?P.*)/$', views.render_object), ) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index f939992..7a7108c 100755 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -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] diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index d3af108..0bbe7d9 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -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 + } diff --git a/itf/templates/modules/itfprofiles/person.html b/itf/templates/modules/itfprofiles/person.html index e69de29..a9a7d1f 100644 --- a/itf/templates/modules/itfprofiles/person.html +++ b/itf/templates/modules/itfprofiles/person.html @@ -0,0 +1,7 @@ +Name: {{ first_name }} {{ last_name }}
+ +
About:
+

+ {{ about }} + +

diff --git a/itf/templates/modules/itfprofiles/production.html b/itf/templates/modules/itfprofiles/production.html index e69de29..208cd0d 100644 --- a/itf/templates/modules/itfprofiles/production.html +++ b/itf/templates/modules/itfprofiles/production.html @@ -0,0 +1,21 @@ +Production name: {{ name }} + +{% if anecdotes %} +
Anecdotes
+

{{ anecdotes }}

+{% endif %} + +{% if group %} + Group: {{ group.name }}
+{% endif %} + +{% if director %} + Director: {{ director.get_title }}
+{% endif %} + +{% if playwright %} + Playwright: {{ playwright.get_title }} +{% endif %} + +
+Edit