diff --git a/src/data/templates/view_citation_detail.html b/src/data/templates/view_citation_detail.html index 9c01ae72a..aaf931509 100644 --- a/src/data/templates/view_citation_detail.html +++ b/src/data/templates/view_citation_detail.html @@ -15,55 +15,140 @@ {% include "detail_breadcrumb.html" %} -

{{source.title|escape}}

-
- {% comment %} 2 cols {% endcomment %} - - - - - - - - - - - - - - - - - - - - - - -
Title:{{source.title|escape}}
Author:{{source.author|escape}}
ID:{{source.gramps_id|escape}}
Abbreviation:{{source.abbrev|escape}}
Public information:{{source.pubinfo|escape}}
-
- + {% if citationform.errors or sourceform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{citationform.errors}}
+
{{sourceform.errors}}
+
+ {% endif %} +
{% csrf_token %} +

Citation information

-
+
+ + + + + + + + + + + + + + + + + + + + +
{{citationform.text.label}}: {% render citationform.text user action %}
{{citationform.gramps_id.label}}: {% render citationform.gramps_id user action %}{{citationform.private.label}}: {% render citationform.private user action %}
{{citationform.page.label}}: {% render citationform.page user action %}
{{citationform.confidence.label}}: {% render citationform.confidence user action %}
+ +
+
+ {% note_table citation user action "/note/add/citation/%s" citation.handle %}
-
-
+

Note: Any changes in the shared citation information will be reflected + in the citation itself, for all items that reference the citation. +

+ +
+ +

Shared source information

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
{{sourceform.title.label}}: {% render sourceform.title user action %}
{{sourceform.author.label}}: {% render sourceform.author user action %}
{{sourceform.gramps_id.label}}: {% render sourceform.gramps_id user action %}{{sourceform.private.label}}: {% render sourceform.private user action %}
{{sourceform.abbrev.label}}: {% render sourceform.abbrev user action %}
{{sourceform.pubinfo.label}}: {% render sourceform.pubinfo user action %}
+ +
+
+
+ +
+
+
+
+
+
+
+ +

Note: Any changes in the shared source information will be reflected + in the source itself, for all items that reference the source. +

+ +
+ +{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Citation" "/citation/%s" citation.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/citation/" %} + + + {% else %} + {% make_button "Back to Citations" "/citation" %} + {% make_button "Add Citation" "/citation/add" %} + {% make_button "Edit Citation" "/citation/%s/edit" citation.handle %} + {% make_button "Delete Citation" "/citation/%s/delete" citation.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/data/templates/view_person_detail.html b/src/data/templates/view_person_detail.html index c3bb570e0..8e9afbcb1 100644 --- a/src/data/templates/view_person_detail.html +++ b/src/data/templates/view_person_detail.html @@ -93,26 +93,26 @@
- {% event_table person user action "/person/%s/event" person.handle %} + {% event_table person user action "/event/add/person/%s" person.handle %}
{% name_table person user action "/person/%s/name" person.handle %}
- {% citation_table person user action "/person/%s/citation" person.handle %} + {% citation_table person user action "/citation/add/person/%s" person.handle %}
{% attribute_table person user action "/person/%s/attribute" person.handle %}
- {% address_table person user action "/person/%s/address" person.handle %} + {% address_table person user action "/place/add/person/%s" person.handle %}
- {% note_table person user action "/person/%s/note" person.handle %} + {% note_table person user action "/note/add/person/%s" person.handle %}
{% internet_table person user action "/person/%s/internet" person.handle %} @@ -124,7 +124,7 @@ {% lds_table person user action "/person/%s/lds" person.handle %}
- {% reference_table person user action "/person/%s/reference" person.handle %} + {% reference_table person user action "/reference/add/person/%s" person.handle %}
diff --git a/src/data/templates/view_place_detail.html b/src/data/templates/view_place_detail.html index 5deb334e9..63a5260fa 100644 --- a/src/data/templates/view_place_detail.html +++ b/src/data/templates/view_place_detail.html @@ -17,21 +17,29 @@
+ + {% if placeform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{placeform.errors}}
+
+ {% endif %} +
{% csrf_token %}
- - + + - - - - + + + + - - - - + + +
Place Name: {{place.title|escape}}{{placeform.title.label}}: {% render placeform.title user action %}
Latitude:{{place.latitude|escape}}Longitude:{{place.longitude|escape}}{{placeform.lat.label}}:{% render placeform.lat user action %}{{placeform.long.label}}:{% render placeform.long user action %}
ID:{{place.gramps_id|escape}}Private:{{place.private}} +{{placeform.gramps_id.label}}:{% render placeform.gramps_id user action %}{{placeform.private.label}}:{% render placeform.private user action %}
@@ -64,5 +72,26 @@
+ +{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Place" "/place/%s" place.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/place/" %} + + + {% else %} + {% make_button "Back to Places" "/place" %} + {% make_button "Add Place" "/place/add" %} + {% make_button "Edit Place" "/place/%s/edit" place.handle %} + {% make_button "Delete Place" "/place/%s/delete" place.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/data/templates/view_repository_detail.html b/src/data/templates/view_repository_detail.html index cbfdec2e2..32c605625 100644 --- a/src/data/templates/view_repository_detail.html +++ b/src/data/templates/view_repository_detail.html @@ -17,17 +17,27 @@
+ + {% if repositoryform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{repositoryform.errors}}
+
+ {% endif %} +
{% csrf_token %}
- - + + - - - - - - + + + + + + + +
Name:{{repository.name}} {{repositoryform.name.label}}:{% render repositoryform.name user action %}
Type:{{repository.repository_type}}ID:{{repository.gramps_id}}Private:{{repository.private}}{{repositoryform.repository_type.label}}:{% render repositoryform.repository_type user action %}
{{repositoryform.gramps_id.label}}:{% render repositoryform.gramps_id user action %}{{repositoryform.private.label}}:{% render repositoryform.private user action %}
@@ -50,6 +60,25 @@
- +{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Repository" "/repository/%s" repository.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/repository/" %} + + + {% else %} + {% make_button "Back to Repositories" "/repository" %} + {% make_button "Add Repository" "/repository/add" %} + {% make_button "Edit Repository" "/repository/%s/edit" repository.handle %} + {% make_button "Delete Repository" "/repository/%s/delete" repository.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/data/templates/view_source_detail.html b/src/data/templates/view_source_detail.html index 9c01ae72a..6a3ef242d 100644 --- a/src/data/templates/view_source_detail.html +++ b/src/data/templates/view_source_detail.html @@ -19,25 +19,28 @@
{% comment %} 2 cols {% endcomment %} + {% if sourceform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{sourceform.errors}}
+
+ {% endif %} +{% csrf_token %} - - + + - - + + - - + + - - - - - - + +
Title:{{source.title|escape}}{{sourceform.title.label}}:{% render sourceform.title user action %}
Author:{{source.author|escape}}{{sourceform.gramps_id.label}}:{% render sourceform.gramps_id user action %}
ID:{{source.gramps_id|escape}}{{sourceform.abbrev.label}}:{% render sourceform.abbrev user action %}
Abbreviation:{{source.abbrev|escape}}
Public information:{{source.pubinfo|escape}}{{sourceform.pubinfo.label}}:{% render sourceform.pubinfo user action %}
@@ -66,4 +69,24 @@
+{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Source" "/source/%s" source.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/source/" %} + + + {% else %} + {% make_button "Back to Sources" "/source" %} + {% make_button "Add Source" "/source/add" %} + {% make_button "Edit Source" "/source/%s/edit" source.handle %} + {% make_button "Delete Source" "/source/%s/delete" source.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/data/templates/view_tag_detail.html b/src/data/templates/view_tag_detail.html index 402730f25..7cba84c23 100644 --- a/src/data/templates/view_tag_detail.html +++ b/src/data/templates/view_tag_detail.html @@ -17,19 +17,25 @@
+ + {% if tagform.errors %} +
+

The following fields have errors. Please correct and try again.

+
{{tagform.errors}}
+
+ {% endif %} +
{% csrf_token %}
- - + + - - - - - - - - + + + + + +
Name:{{tag.name}} {{tagform.name.label}}:{% render tagform.name user action %}
Type:{{tag.repository_type}}Color:{{tag.color}}Private:{{tag.private}}Priority:{{tag.priority}}{{tagform.color.label}}:{% render tagform.color user action %}
{{tagform.priority.label}}:{% render tagform.priority user action %}
@@ -52,6 +58,25 @@
- +{% if user.is_superuser %} + {% if action == "edit" %} + {% make_button "Back to Tag" "/tag/%s" tag.handle %} + + + {% else %} + {% ifequal action "add" %} + {% make_button "Cancel" "/tag/" %} + + + {% else %} + {% make_button "Back to Tags" "/tag" %} + {% make_button "Add Tag" "/tag/add" %} + {% make_button "Edit Tag" "/tag/%s/edit" tag.handle %} + {% make_button "Delete Tag" "/tag/%s/delete" tag.handle %} + {% endifequal %} + {% endif %} +{% else %} +{% endif %} + {% endblock %} diff --git a/src/webapp/empty.sql b/src/webapp/empty.sql index e9dcb98fb..087479441 100644 --- a/src/webapp/empty.sql +++ b/src/webapp/empty.sql @@ -219,8 +219,7 @@ CREATE TABLE "auth_user" ( "last_login" datetime NOT NULL, "date_joined" datetime NOT NULL ); -INSERT INTO "auth_user" VALUES(1,'admin','','','bugs@gramps-project.org','sha1$27271$3bf37b85204e28ce39a5ab19505306cf2925e997',1,1,1,'2012-05-24 18:13:26.243285','2012-05-24 18:11:18.576187'); -INSERT INTO "auth_user" VALUES(2,'admin1','','','','sha1$a1880$d61d1cb0467158d6ee8c765af6c5d897b518aeca',0,1,0,'2012-05-24 18:13:52','2012-05-24 18:13:52'); +INSERT INTO "auth_user" VALUES(1,'admin','','','bugs@gramps-project.org','sha1$61e84$9f92d64496a8785f9a398a1e1a2e9bc9bdc6f3b0',1,1,1,'2012-05-26 14:00:59.964988','2012-05-26 14:00:59.964988'); CREATE TABLE "auth_message" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL REFERENCES "auth_user" ("id"), @@ -297,10 +296,6 @@ CREATE TABLE "django_session" ( "session_data" text NOT NULL, "expire_date" datetime NOT NULL ); -INSERT INTO "django_session" VALUES('8928553c90d43632f58fcff353176faa','MmU1MjliMDM2NzcyODdjNmJlOTgzMGFiYzc2MjFkMmViYWFiOTIzMjqAAn1xAShVEl9hdXRoX3Vz -ZXJfYmFja2VuZHECVSlkamFuZ28uY29udHJpYi5hdXRoLmJhY2tlbmRzLk1vZGVsQmFja2VuZHED -VQ1fYXV0aF91c2VyX2lkcQRLAXUu -','2012-06-07 18:13:26.602244'); CREATE TABLE "django_site" ( "id" integer NOT NULL PRIMARY KEY, "domain" varchar(100) NOT NULL, @@ -317,15 +312,12 @@ CREATE TABLE "django_admin_log" ( "action_flag" smallint unsigned NOT NULL, "change_message" text NOT NULL ); -INSERT INTO "django_admin_log" VALUES(1,'2012-05-24 18:13:52.236486',1,3,'2','admin1',1,''); -INSERT INTO "django_admin_log" VALUES(2,'2012-05-24 18:14:06.532544',1,3,'2','admin1',2,'No fields changed.'); CREATE TABLE "grampsdb_profile" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id"), "css_theme" varchar(40) NOT NULL ); INSERT INTO "grampsdb_profile" VALUES(1,1,'Web_Mainz.css'); -INSERT INTO "grampsdb_profile" VALUES(2,2,'Web_Mainz.css'); CREATE TABLE "grampsdb_nametype" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(40) NOT NULL, @@ -624,7 +616,7 @@ CREATE TABLE "grampsdb_config" ( ); INSERT INTO "grampsdb_config" VALUES(1,'sitename','site name of family tree','str','Gramps-Connect'); INSERT INTO "grampsdb_config" VALUES(2,'db_version','database scheme version','str','0.5.1'); -INSERT INTO "grampsdb_config" VALUES(3,'db_created','database creation date/time','str','2012-05-24 18:10'); +INSERT INTO "grampsdb_config" VALUES(3,'db_created','database creation date/time','str','2012-05-26 14:00'); CREATE TABLE "grampsdb_tag" ( "id" integer NOT NULL PRIMARY KEY, "handle" varchar(19) NOT NULL UNIQUE, @@ -633,8 +625,8 @@ CREATE TABLE "grampsdb_tag" ( "last_changed" datetime, "last_changed_by" text, "name" text NOT NULL, - "color" varchar(13) NOT NULL, - "priority" integer NOT NULL + "color" varchar(13), + "priority" integer ); CREATE TABLE "grampsdb_person_families" ( "id" integer NOT NULL PRIMARY KEY, @@ -712,8 +704,8 @@ CREATE TABLE "grampsdb_citation" ( "last_changed_by" text, "private" bool NOT NULL, "cache" text, - "confidence" integer NOT NULL, - "page" varchar(50) NOT NULL, + "confidence" integer, + "page" varchar(50), "source_id" integer ); CREATE TABLE "grampsdb_source" ( @@ -725,10 +717,10 @@ CREATE TABLE "grampsdb_source" ( "last_changed_by" text, "private" bool NOT NULL, "cache" text, - "title" varchar(50) NOT NULL, - "author" varchar(50) NOT NULL, - "pubinfo" varchar(50) NOT NULL, - "abbrev" varchar(50) NOT NULL + "title" varchar(50), + "author" varchar(50), + "pubinfo" varchar(50), + "abbrev" varchar(50) ); CREATE TABLE "grampsdb_event" ( "calendar" integer NOT NULL, diff --git a/src/webapp/grampsdb/forms.py b/src/webapp/grampsdb/forms.py index 3171a816b..1957a5206 100644 --- a/src/webapp/grampsdb/forms.py +++ b/src/webapp/grampsdb/forms.py @@ -199,3 +199,73 @@ class MediaForm(forms.ModelForm): path = forms.CharField(label="Path", required=False, widget=TextInput(attrs={'size':'70'})) + +class CitationForm(forms.ModelForm): + class Meta: + model = Citation + exclude = ["handle", "sortval", "month1", "year1", "day1", + "newyear", "calendar", "modifier", "quality"] + + def clean(self): + from webapp.utils import dp + data = super(CitationForm, self).clean() + dobj = dp(data.get('text')) + if not dobj.is_valid(): + msg = u"Invalid date format" + self._errors["date"] = self.error_class([msg]) + del data["text"] + return data + + def save(self, commit=True): + from webapp.utils import dp + from webapp.libdjango import DjangoInterface + dji = DjangoInterface() + model = super(CitationForm, self).save(commit=False) + dobj = dp(self.cleaned_data['text']) + dji.add_date(model, dobj.serialize()) + if commit: + model.save() + return model + + text = forms.CharField(label="Date", + required=False, + widget=TextInput(attrs={'size':'70'})) + +class SourceForm(forms.ModelForm): + class Meta: + model = Source + exclude = ["handle"] + +class PlaceForm(forms.ModelForm): + class Meta: + model = Place + exclude = ["handle"] + + title = forms.CharField(label="Title", + required=False, + widget=TextInput(attrs={'size':'70'})) + long = forms.CharField(label="Longitude", + required=False, + widget=TextInput(attrs={'size':'70'})) + lat = forms.CharField(label="Latitude", + required=False, + widget=TextInput(attrs={'size':'70'})) + +class RepositoryForm(forms.ModelForm): + class Meta: + model = Repository + exclude = ["handle"] + + name = forms.CharField(label="Name", + required=False, + widget=TextInput(attrs={'size':'70'})) + +class TagForm(forms.ModelForm): + class Meta: + model = Tag + exclude = ["handle"] + + name = forms.CharField(label="Name", + required=False, + widget=TextInput(attrs={'size':'70'})) + diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index 44e725f7d..f4a2dc573 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -391,8 +391,8 @@ class Tag(models.Model): last_changed_by = models.TextField(blank=True, null=True) name = models.TextField('name') - color = models.CharField(max_length=13) # "#000000000000" # Black - priority = models.IntegerField('priority', blank=False) + color = models.CharField(max_length=13, blank=True, null=True) # "#000000000000" # Black + priority = models.IntegerField('priority', blank=True, null=True) def __unicode__(self): return str(self.name) @@ -492,8 +492,8 @@ class Family(PrimaryObject): return str("%s and %s" % (father, mother)) class Citation(DateObject, PrimaryObject): - confidence = models.IntegerField(blank=True) - page = models.CharField(max_length=50, blank=True) + confidence = models.IntegerField(blank=True, null=True) + page = models.CharField("Volume/Page", max_length=50, blank=True, null=True) source = models.ForeignKey('Source', null=True, blank=True) references = generic.GenericRelation('CitationRef', related_name="refs", content_type_field="object_type", @@ -506,10 +506,10 @@ class Citation(DateObject, PrimaryObject): # .datamap_set class Source(PrimaryObject): - title = models.CharField(max_length=50, blank=True) - author = models.CharField(max_length=50, blank=True) - pubinfo = models.CharField(max_length=50, blank=True) - abbrev = models.CharField(max_length=50, blank=True) + title = models.CharField(max_length=50, blank=True, null=True) + author = models.CharField(max_length=50, blank=True, null=True) + pubinfo = models.CharField("Pub. info.", max_length=50, blank=True, null=True) + abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True) # Other keys here: # .datamap_set @@ -523,7 +523,7 @@ class Event(DateObject, PrimaryObject): object_id_field="object_id") class Repository(PrimaryObject): - repository_type = models.ForeignKey('RepositoryType') + repository_type = models.ForeignKey('RepositoryType', verbose_name="Type") name = models.TextField(blank=True) #addresses = models.ManyToManyField('Address', null=True, blank=True) references = generic.GenericRelation('RepositoryRef', related_name="refs", diff --git a/src/webapp/grampsdb/view/citation.py b/src/webapp/grampsdb/view/citation.py index 9dcb3e35e..9477a4c28 100644 --- a/src/webapp/grampsdb/view/citation.py +++ b/src/webapp/grampsdb/view/citation.py @@ -22,7 +22,7 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean +from webapp.utils import _, boolean, update_last_changed from webapp.grampsdb.models import Citation from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -34,95 +34,82 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_citation(request, context, handle, action): # view, edit, save +def process_citation(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ context["tview"] = _("Citation") context["tviews"] = _("Citations") context["action"] = "view" - context["object"] = Citation() view_template = "view_citation_detail.html" - return render_to_response(view_template, context) - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = True # FIXME: why is this False? - check_preferred(name, person) - name.save() - # Process data: - surname.name = name - surname = sf.save(commit=False) - # Manually set any data: - surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname.primary = True # FIXME: why is this False? - surname.save() - # FIXME: last_saved, last_changed, last_changed_by - dji.rebuild_cache(person) - # FIXME: update probably_alive - return redirect("/person/%s" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS - context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle + if handle == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + # Handle: edit, view, add, create, save, delete + if action == "add": + source = Source() + sourceform = SourceForm(instance=source) + sourceform.model = source + citation = Citation(source=source) + citationform = CitationForm(instance=citation) + citationform.model = citation + elif action in ["view", "edit"]: + citation = Citation.objects.get(handle=handle) + citationform = CitationForm(instance=citation) + citationform.model = citation + source = citation.source + sourceform = SourceForm(instance=source) + sourceform.model = source + elif action == "save": + citation = Citation.objects.get(handle=handle) + citationform = CitationForm(request.POST, instance=citation) + citationform.model = citation + if citationform.is_valid(): + update_last_changed(citation, request.user.username) + citation = citationform.save() + dji.rebuild_cache(citation) + action = "view" + else: + action = "edit" + elif action == "create": + source = Source(handle=create_id()) + sourceform = SourceForm(request.POST, instance=source) + sourceform.model = source + citation = Citation(handle=create_id(), source=source) + citationform = CitationForm(request.POST, instance=citation) + citationform.model = citation + if citationform.is_valid() and sourceform.is_valid(): + update_last_changed(source, request.user.username) + source = sourceform.save() + citation.source = source + update_last_changed(citation, request.user.username) + citation = citationform.save() + dji.rebuild_cache(source) + dji.rebuild_cache(citation) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_citation_ref(obj, citation.handle) + return redirect("/%s/%s" % (item, handle)) + action = "view" + else: + action = "add" + elif action == "delete": + citation = Citation.objects.get(handle=handle) + citation.delete() + return redirect("/citation/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["citationform"] = citationform + context["sourceform"] = sourceform + context["object"] = citation + context["citation"] = citation + context["source"] = source + context["action"] = action + + return render_to_response(view_template, context) diff --git a/src/webapp/grampsdb/view/event.py b/src/webapp/grampsdb/view/event.py index f24475f80..9ae79559d 100644 --- a/src/webapp/grampsdb/view/event.py +++ b/src/webapp/grampsdb/view/event.py @@ -37,7 +37,7 @@ dji = DjangoInterface() dd = displayer.display dp = parser.parse -def process_event(request, context, handle, action): # view, edit, save +def process_event(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ @@ -79,6 +79,12 @@ def process_event(request, context, handle, action): # view, edit, save update_last_changed(event, request.user.username) event = eventform.save() dji.rebuild_cache(event) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_event_ref_default(obj, event) + return redirect("/%s/%s" % (item, handle)) action = "view" else: action = "add" diff --git a/src/webapp/grampsdb/view/family.py b/src/webapp/grampsdb/view/family.py index d43bb899b..2e5ce5b8c 100644 --- a/src/webapp/grampsdb/view/family.py +++ b/src/webapp/grampsdb/view/family.py @@ -35,7 +35,7 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_family(request, context, handle, action): # view, edit, save +def process_family(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ @@ -79,6 +79,12 @@ def process_family(request, context, handle, action): # view, edit, save update_last_changed(family, request.user.username) family = familyform.save() dji.rebuild_cache(family) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_family_ref(obj, family.handle) + return redirect("/%s/%s" % (item, handle)) action = "view" else: action = "add" diff --git a/src/webapp/grampsdb/view/media.py b/src/webapp/grampsdb/view/media.py index 3937ebd53..8678ce89a 100644 --- a/src/webapp/grampsdb/view/media.py +++ b/src/webapp/grampsdb/view/media.py @@ -34,7 +34,7 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_media(request, context, handle, action): # view, edit, save +def process_media(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ @@ -76,6 +76,12 @@ def process_media(request, context, handle, action): # view, edit, save update_last_changed(media, request.user.username) media = mediaform.save() dji.rebuild_cache(media) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_media_ref_default(obj, media) + return redirect("/%s/%s" % (item, handle)) action = "view" else: action = "add" diff --git a/src/webapp/grampsdb/view/note.py b/src/webapp/grampsdb/view/note.py index bc2b1e877..ff30a4dd6 100644 --- a/src/webapp/grampsdb/view/note.py +++ b/src/webapp/grampsdb/view/note.py @@ -34,7 +34,7 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_note(request, context, handle, action): # view, edit, save +def process_note(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ @@ -76,6 +76,12 @@ def process_note(request, context, handle, action): # view, edit, save update_last_changed(note, request.user.username) note = noteform.save() dji.rebuild_cache(note) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_note_ref(obj, note) + return redirect("/%s/%s" % (item, handle)) action = "view" else: action = "add" diff --git a/src/webapp/grampsdb/view/person.py b/src/webapp/grampsdb/view/person.py index 7000465bf..86a26c709 100644 --- a/src/webapp/grampsdb/view/person.py +++ b/src/webapp/grampsdb/view/person.py @@ -151,8 +151,6 @@ def process_surname(request, handle, order, sorder, action="view"): name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) surname.prefix = make_empty(True, surname.prefix, " prefix ") elif action == "create": - import pdb; pdb.set_trace() - surnames = name.surname_set.all().order_by("order") sorder = 1 for surname in surnames: @@ -333,7 +331,7 @@ def process_name(request, handle, order, action="view"): view_template = "view_name_detail.html" return render_to_response(view_template, context) -def process_person(request, context, handle, action): # view, edit, save +def process_person(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ @@ -392,6 +390,12 @@ def process_person(request, context, handle, action): # view, edit, save # FIXME: last_saved, last_changed, last_changed_by dji.rebuild_cache(person) # FIXME: update probably_alive + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_person_ref_default(obj, person) + return redirect("/%s/%s" % (item, handle)) return redirect("/person/%s" % person.handle) else: # need to edit again diff --git a/src/webapp/grampsdb/view/place.py b/src/webapp/grampsdb/view/place.py index 1cec2f3a3..57346644d 100644 --- a/src/webapp/grampsdb/view/place.py +++ b/src/webapp/grampsdb/view/place.py @@ -22,7 +22,7 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean +from webapp.utils import _, boolean, update_last_changed from webapp.grampsdb.models import Place from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -34,95 +34,67 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_place(request, context, handle, action): # view, edit, save +def process_place(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ context["tview"] = _("Place") context["tviews"] = _("Places") context["action"] = "view" - context["object"] = Place() view_template = "view_place_detail.html" + + if handle == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + + # Handle: edit, view, add, create, save, delete + if action == "add": + place = Place() + placeform = PlaceForm(instance=place) + placeform.model = place + elif action in ["view", "edit"]: + place = Place.objects.get(handle=handle) + placeform = PlaceForm(instance=place) + placeform.model = place + elif action == "save": + place = Place.objects.get(handle=handle) + placeform = PlaceForm(request.POST, instance=place) + placeform.model = place + if placeform.is_valid(): + update_last_changed(place, request.user.username) + place = placeform.save() + dji.rebuild_cache(place) + action = "view" + else: + action = "edit" + elif action == "create": + place = Place(handle=create_id()) + placeform = PlaceForm(request.POST, instance=place) + placeform.model = place + if placeform.is_valid(): + update_last_changed(place, request.user.username) + place = placeform.save() + dji.rebuild_cache(place) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_place_ref(obj, place.handle) + return redirect("/%s/%s" % (item, handle)) + action = "view" + else: + action = "add" + elif action == "delete": + place = Place.objects.get(handle=handle) + place.delete() + return redirect("/place/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["placeform"] = placeform + context["object"] = place + context["place"] = place + context["action"] = action return render_to_response(view_template, context) - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = True # FIXME: why is this False? - check_preferred(name, person) - name.save() - # Process data: - surname.name = name - surname = sf.save(commit=False) - # Manually set any data: - surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname.primary = True # FIXME: why is this False? - surname.save() - # FIXME: last_saved, last_changed, last_changed_by - dji.rebuild_cache(person) - # FIXME: update probably_alive - return redirect("/person/%s" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS - context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle - diff --git a/src/webapp/grampsdb/view/repository.py b/src/webapp/grampsdb/view/repository.py index f783c4c9c..1d71c93cf 100644 --- a/src/webapp/grampsdb/view/repository.py +++ b/src/webapp/grampsdb/view/repository.py @@ -22,7 +22,7 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean +from webapp.utils import _, boolean, update_last_changed from webapp.grampsdb.models import Repository from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -34,95 +34,68 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_repository(request, context, handle, action): # view, edit, save +def process_repository(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ context["tview"] = _("Repository") context["tviews"] = _("Repositories") context["action"] = "view" - context["object"] = Repository() view_template = "view_repository_detail.html" - return render_to_response(view_template, context) - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = True # FIXME: why is this False? - check_preferred(name, person) - name.save() - # Process data: - surname.name = name - surname = sf.save(commit=False) - # Manually set any data: - surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname.primary = True # FIXME: why is this False? - surname.save() - # FIXME: last_saved, last_changed, last_changed_by - dji.rebuild_cache(person) - # FIXME: update probably_alive - return redirect("/person/%s" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS - context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle + if handle == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + + # Handle: edit, view, add, create, save, delete + if action == "add": + repository = Repository() + repositoryform = RepositoryForm(instance=repository) + repositoryform.model = repository + elif action in ["view", "edit"]: + repository = Repository.objects.get(handle=handle) + repositoryform = RepositoryForm(instance=repository) + repositoryform.model = repository + elif action == "save": + repository = Repository.objects.get(handle=handle) + repositoryform = RepositoryForm(request.POST, instance=repository) + repositoryform.model = repository + if repositoryform.is_valid(): + update_last_changed(repository, request.user.username) + repository = repositoryform.save() + dji.rebuild_cache(repository) + action = "view" + else: + action = "edit" + elif action == "create": + repository = Repository(handle=create_id()) + repositoryform = RepositoryForm(request.POST, instance=repository) + repositoryform.model = repository + if repositoryform.is_valid(): + update_last_changed(repository, request.user.username) + repository = repositoryform.save() + dji.rebuild_cache(repository) + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_repository_ref(obj, repository) + return redirect("/%s/%s" % (item, handle)) + action = "view" + else: + action = "add" + elif action == "delete": + repository = Repository.objects.get(handle=handle) + repository.delete() + return redirect("/repository/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["repositoryform"] = repositoryform + context["object"] = repository + context["repository"] = repository + context["action"] = action + + return render_to_response(view_template, context) diff --git a/src/webapp/grampsdb/view/source.py b/src/webapp/grampsdb/view/source.py index 91d96774a..091043358 100644 --- a/src/webapp/grampsdb/view/source.py +++ b/src/webapp/grampsdb/view/source.py @@ -22,7 +22,7 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean +from webapp.utils import _, boolean, update_last_changed from webapp.grampsdb.models import Source from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -34,96 +34,66 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_source(request, context, handle, action): # view, edit, save +def process_source(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ context["tview"] = _("Source") context["tviews"] = _("Sources") context["action"] = "view" - context["object"] = Source() view_template = "view_source_detail.html" + if handle == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") + + # Handle: edit, view, add, create, save, delete + if action == "add": + source = Source() + sourceform = SourceForm(instance=source) + sourceform.model = source + elif action in ["view", "edit"]: + source = Source.objects.get(handle=handle) + sourceform = SourceForm(instance=source) + sourceform.model = source + elif action == "save": + source = Source.objects.get(handle=handle) + sourceform = SourceForm(request.POST, instance=source) + sourceform.model = source + if sourceform.is_valid(): + update_last_changed(source, request.user.username) + source = sourceform.save() + dji.rebuild_cache(source) + action = "view" + else: + action = "edit" + elif action == "create": + source = Source(handle=create_id()) + sourceform = SourceForm(request.POST, instance=source) + sourceform.model = source + if sourceform.is_valid(): + update_last_changed(source, request.user.username) + source = sourceform.save() + dji.rebuild_cache(source) + if add_to: + raise Exception("Cannot add reference") + action = "view" + else: + action = "add" + elif action == "delete": + source = Source.objects.get(handle=handle) + source.delete() + return redirect("/source/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["sourceform"] = sourceform + context["object"] = source + context["source"] = source + context["action"] = action + return render_to_response(view_template, context) - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = True # FIXME: why is this False? - check_preferred(name, person) - name.save() - # Process data: - surname.name = name - surname = sf.save(commit=False) - # Manually set any data: - surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname.primary = True # FIXME: why is this False? - surname.save() - # FIXME: last_saved, last_changed, last_changed_by - dji.rebuild_cache(person) - # FIXME: update probably_alive - return redirect("/person/%s" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS - context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle + diff --git a/src/webapp/grampsdb/view/tag.py b/src/webapp/grampsdb/view/tag.py index 13e3f3515..66de628c3 100644 --- a/src/webapp/grampsdb/view/tag.py +++ b/src/webapp/grampsdb/view/tag.py @@ -22,7 +22,7 @@ """ Views for Person, Name, and Surname """ ## Gramps Modules -from webapp.utils import _, boolean +from webapp.utils import _, boolean, update_last_changed from webapp.grampsdb.models import Tag from webapp.grampsdb.forms import * from webapp.libdjango import DjangoInterface @@ -34,96 +34,65 @@ from django.template import Context, RequestContext ## Globals dji = DjangoInterface() -def process_tag(request, context, handle, action): # view, edit, save +def process_tag(request, context, handle, action, add_to=None): # view, edit, save """ Process action on person. Can return a redirect. """ context["tview"] = _("Tag") context["tviews"] = _("Tags") context["action"] = "view" - context["object"] = Tag() view_template = "view_tag_detail.html" - return render_to_response(view_template, context) + if handle == "add": + action = "add" + if request.POST.has_key("action"): + action = request.POST.get("action") - if request.user.is_authenticated(): - if action in ["edit", "view"]: - pf, nf, sf, person = get_person_forms(handle, empty=False) - elif action == "add": - pf, nf, sf, person = get_person_forms(handle=None, protect=False, empty=True) - elif action == "delete": - pf, nf, sf, person = get_person_forms(handle, protect=False, empty=True) - person.delete() - return redirect("/person/") - elif action in ["save", "create"]: # could be create a new person - # look up old data, if any: - if handle: - person = Person.objects.get(handle=handle) - name = person.name_set.get(preferred=True) - surname = name.surname_set.get(primary=True) - else: # create new item - person = Person(handle=create_id()) - name = Name(person=person, preferred=True) - surname = Surname(name=name, primary=True, order=1) - surname = Surname(name=name, - primary=True, - order=1, - name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0])) - # combine with user data: - pf = PersonForm(request.POST, instance=person) - pf.model = person - nf = NameFormFromPerson(request.POST, instance=name) - nf.model = name - sf = SurnameForm(request.POST, instance=surname) - # check if valid: - if nf.is_valid() and pf.is_valid() and sf.is_valid(): - # name.preferred and surname.primary get set False in the above is_valid() - person = pf.save() - # Process data: - name.person = person - name = nf.save(commit=False) - # Manually set any data: - name.suffix = nf.cleaned_data["suffix"] if nf.cleaned_data["suffix"] != " suffix " else "" - name.preferred = True # FIXME: why is this False? - check_preferred(name, person) - name.save() - # Process data: - surname.name = name - surname = sf.save(commit=False) - # Manually set any data: - surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else "" - surname.primary = True # FIXME: why is this False? - surname.save() - # FIXME: last_saved, last_changed, last_changed_by - dji.rebuild_cache(person) - # FIXME: update probably_alive - return redirect("/person/%s" % person.handle) - else: - # need to edit again - if handle: - action = "edit" - else: - action = "add" - else: # error? - raise Http404(_("Requested %s does not exist.") % "person") - else: # not authenticated - # BEGIN NON-AUTHENTICATED ACCESS - try: - person = Person.objects.get(handle=handle) - except: - raise Http404(_("Requested %s does not exist.") % "person") - if person.private: - raise Http404(_("Requested %s does not exist.") % "person") - pf, nf, sf, person = get_person_forms(handle, protect=True) - # END NON-AUTHENTICATED ACCESS + # Handle: edit, view, add, create, save, delete + if action == "add": + tag = Tag() + tagform = TagForm(instance=tag) + tagform.model = tag + elif action in ["view", "edit"]: + tag = Tag.objects.get(handle=handle) + tagform = TagForm(instance=tag) + tagform.model = tag + elif action == "save": + tag = Tag.objects.get(handle=handle) + tagform = TagForm(request.POST, instance=tag) + tagform.model = tag + if tagform.is_valid(): + update_last_changed(tag, request.user.username) + tag = tagform.save() + action = "view" + else: + action = "edit" + elif action == "create": + tag = Tag(handle=create_id()) + tagform = TagForm(request.POST, instance=tag) + tagform.model = tag + if tagform.is_valid(): + update_last_changed(tag, request.user.username) + tag = tagform.save() + if add_to: + item, handle = add_to + model = dji.get_model(item) + obj = model.objects.get(handle=handle) + dji.add_tag_ref_default(obj, tag) + return redirect("/%s/%s" % (item, handle)) + action = "view" + else: + action = "add" + elif action == "delete": + tag = Tag.objects.get(handle=handle) + tag.delete() + return redirect("/tag/") + else: + raise Exception("Unhandled action: '%s'" % action) + + context["tagform"] = tagform + context["object"] = tag + context["tag"] = tag context["action"] = action - context["view"] = "person" - context["tview"] = _("Person") - context["tviews"] = _("People") - context["personform"] = pf - context["nameform"] = nf - context["surnameform"] = sf - context["person"] = person - context["object"] = person - context["next"] = "/person/%s" % person.handle - + + return render_to_response(view_template, context) diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index 693063551..00c90cc8c 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -536,7 +536,14 @@ def check_access(request, context, obj, action): else: # outside viewer return not obj.private -def action(request, view, handle, action): +def add_to(request, view, item, handle): + """ + Add a new referenced from . + """ + # /view/add/person/handle + return action(request, view, handle, "add", (item, handle)) + +def action(request, view, handle, action, add_to=None): """ View a particular object given /object/handle (implied view), /object/handle/action, or /object/add. @@ -559,7 +566,7 @@ def action(request, view, handle, action): if not check_access(request, context, obj, action): raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_event_detail.html' - rd = process_event(request, context, handle, action) + rd = process_event(request, context, handle, action, add_to) elif view == "family": if action not in ["add", "create"]: try: @@ -567,7 +574,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_family_detail.html' - rd = process_family(request, context, handle, action) + rd = process_family(request, context, handle, action, add_to) elif view == "media": if action not in ["add", "create"]: try: @@ -575,7 +582,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_media_detail.html' - rd = process_media(request, context, handle, action) + rd = process_media(request, context, handle, action, add_to) elif view == "note": if action not in ["add", "create"]: try: @@ -583,7 +590,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_note_detail.html' - rd = process_note(request, context, handle, action) + rd = process_note(request, context, handle, action, add_to) elif view == "person": if action not in ["add", "create"]: try: @@ -591,7 +598,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_person_detail.html' - rd = process_person(request, context, handle, action) + rd = process_person(request, context, handle, action, add_to) elif view == "place": if action not in ["add", "create"]: try: @@ -599,7 +606,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_place_detail.html' - rd = process_place(request, context, handle, action) + rd = process_place(request, context, handle, action, add_to) elif view == "repository": if action not in ["add", "create"]: try: @@ -607,7 +614,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_repository_detail.html' - rd = process_repository(request, context, handle, action) + rd = process_repository(request, context, handle, action, add_to) elif view == "citation": if action not in ["add", "create"]: try: @@ -615,7 +622,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_citation_detail.html' - rd = process_citation(request, context, handle, action) + rd = process_citation(request, context, handle, action, add_to) elif view == "source": if action not in ["add", "create"]: try: @@ -623,7 +630,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_source_detail.html' - rd = process_source(request, context, handle, action) + rd = process_source(request, context, handle, action, add_to) elif view == "tag": if action not in ["add", "create"]: try: @@ -631,7 +638,7 @@ def action(request, view, handle, action): except: raise Http404(_("Requested %s does not exist.") % view) view_template = 'view_tag_detail.html' - rd = process_tag(request, context, handle, action) + rd = process_tag(request, context, handle, action, add_to) elif view == "report": if action not in ["add", "create"]: try: diff --git a/src/webapp/libdjango.py b/src/webapp/libdjango.py index 735625f63..e3de6dcca 100644 --- a/src/webapp/libdjango.py +++ b/src/webapp/libdjango.py @@ -146,10 +146,10 @@ class DjangoInterface(object): raise AttributeError("no such model: '%s'" % name) def get_model(self, name): - if hasattr(models, name): - return getattr(models, name) + if hasattr(models, name.title()): + return getattr(models, name.title()) else: - raise AttributeError("no such model: '%s'" % name) + raise AttributeError("no such model: '%s'" % name.title()) # ----------------------------------------------- # Get methods to retrieve list data from the tables @@ -714,6 +714,15 @@ class DjangoInterface(object): ## Export reference objects: + def add_person_ref_default(self, obj, person, private=False, desc=None): + count = person.references.count() + person_ref = models.PersonRef(referenced_by=obj, + ref_object=person, + private=private, + order=count + 1, + description=desc) + person_ref.save() + def add_person_ref(self, obj, person_ref_data): (private, citation_list, @@ -745,6 +754,20 @@ class DjangoInterface(object): order=count + 1) note_ref.save() + def add_media_ref_default(self, obj, media, private=False, role=None): + count = media.references.count() + if not role: + role = (0,0,0,0) + media_ref = models.MediaRef(referenced_by=obj, + ref_object=media, + x1=role[0], + y1=role[1], + x2=role[2], + y2=role[3], + private=private, + order=count + 1) + media_ref.save() + def add_media_ref(self, obj, media_ref_data): (private, citation_list, note_list, attribute_list, ref, role) = media_ref_data @@ -838,6 +861,15 @@ class DjangoInterface(object): self.add_citation_list(child_ref, citation_list) self.add_note_list(child_ref, note_list) + def add_event_ref_default(self, obj, event, private=False, role=models.EventRoleType._DEFAULT): + count = models.EventRef.objects.filter(object_id=obj.id,object_type=obj).count() + event_ref = models.EventRef(private=private, + referenced_by=obj, + ref_object=event, + order=count + 1, + role_type = models.get_type(models.EventRoleType, role)) + event_ref.save() + def add_event_ref(self, obj, event_data): (private, note_list, attribute_list, ref, role) = event_data try: diff --git a/src/webapp/urls.py b/src/webapp/urls.py index 9ef8bccd4..f382bd7f6 100644 --- a/src/webapp/urls.py +++ b/src/webapp/urls.py @@ -68,13 +68,15 @@ urlpatterns += patterns('', (r'^browse/$', browse_page), (r'^login/$', 'django.contrib.auth.views.login'), (r'^logout/$', logout_page), - (r'^(?P(\w+))/$', view_list), # /object/ + (r'^(?P(\w+))/$', view_list), # /view/ (r'^(?P(\w+))/add$', action, - {"handle": None, "action": "add"}), # /object/add + {"handle": None, "action": "add"}), # /view/add + (r'^(?P(\w+))/add/(?P(\w+))/(?P(\w+))$', + add_to), # /view/add/item/handle (r'^(?P(\w+))/(?P(\w+))/$', action, - {"action": "view"}), # /object/handle/ + {"action": "view"}), # /view/handle/ (r'^(?P(\w+))/(?P(\w+))/(?P(\w+))$', - action), # /object/handle/action + action), # /view/handle/action (r'^person/(?P(\w+))/name/(?P(\w+))$', process_name), (r'^person/(?P(\w+))/name/(?P(\w+))/(?P(\w+))$', process_name), (r'^person/(?P(\w+))/name/(?P(\w+))/surname/(?P(\w+))$', process_surname), diff --git a/src/webapp/utils.py b/src/webapp/utils.py index 641d65b11..65516c5c3 100644 --- a/src/webapp/utils.py +++ b/src/webapp/utils.py @@ -385,7 +385,7 @@ def note_table(obj, user, action, url=None, *args): note_ref.ref_object.text[:50]) retval += table.get_html() if user.is_superuser and url and action == "view": - retval += make_button(_("Add note"), (url + "/add") % args) + retval += make_button(_("Add note"), (url % args)) else: retval += nbsp("") # to keep tabs same height return retval