All primary objects can edit, view, create, add, save, add_to, and delete
svn: r19663
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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'}))
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 <view> referenced from <item>.
|
||||
"""
|
||||
# /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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -68,13 +68,15 @@ urlpatterns += patterns('',
|
||||
(r'^browse/$', browse_page),
|
||||
(r'^login/$', 'django.contrib.auth.views.login'),
|
||||
(r'^logout/$', logout_page),
|
||||
(r'^(?P<view>(\w+))/$', view_list), # /object/
|
||||
(r'^(?P<view>(\w+))/$', view_list), # /view/
|
||||
(r'^(?P<view>(\w+))/add$', action,
|
||||
{"handle": None, "action": "add"}), # /object/add
|
||||
{"handle": None, "action": "add"}), # /view/add
|
||||
(r'^(?P<view>(\w+))/add/(?P<item>(\w+))/(?P<handle>(\w+))$',
|
||||
add_to), # /view/add/item/handle
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/$', action,
|
||||
{"action": "view"}), # /object/handle/
|
||||
{"action": "view"}), # /view/handle/
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
|
||||
action), # /object/handle/action
|
||||
action), # /view/handle/action
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', process_name),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', process_name),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$', process_surname),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user