Media main parts complete

svn: r19656
This commit is contained in:
Doug Blank 2012-05-26 04:32:48 +00:00
parent c2e5e1741b
commit 6919546a0f
5 changed files with 155 additions and 108 deletions

View File

@ -10,20 +10,42 @@
});
</script>
<div class="content" id="IndividualDetail">
{% include "detail_breadcrumb.html" %}
<table>
<div id="summaryarea">
<table class="infolist" style="width:90%;">
<tbody>
{% if mediaform.errors %}
<hr>
<p id="error">The following fields have errors. Please correct and try again.</p>
<div id="error">{{mediaform.errors}}</div>
<hr>
{% endif %}
<form method="post">{% csrf_token %}
<tr>
<td>Event type:</td><td> {{event.event_type|escape}}</td><td>Date:</td><td></td>
<td class="ColumnAttribute">{{mediaform.desc.label}}:</td>
<td class="ColumnValue" id="data" colspan="3">{% render mediaform.desc user action %}</td>
</tr>
<tr>
<td>Description:</td><td spancols="2">{{event.description|escape}}</td>
<td class="ColumnAttribute">{{mediaform.gramps_id.label}}:</td>
<td class="ColumnValue" id="data">{% render mediaform.gramps_id user action %}</td>
<td class="ColumnAttribute">{{mediaform.private.label}}:</td>
<td class="ColumnValue" id="data">{% render mediaform.private user action %}</td>
</tr>
<tr>
<td>ID:</td><td spancols="2">{{event.gramps_id|escape}}</td>
<td class="ColumnAttribute">{{mediaform.text.label}}:</td>
<td class="ColumnValue" id="data" colspan="3">{% render mediaform.text user action %}</td>
</tr>
<tr>
<td>Place:</td><td spancols="2">{{event.place.title|escape}}</td>
<td class="ColumnAttribute">{{mediaform.path.label}}:</td>
<td class="ColumnValue" id="data" colspan="3">{% render mediaform.path user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{mediaform.tags.label}}:</td>
<td class="ColumnValue" id="data" colspan="3">{% render mediaform.tags user action %}</td>
</tr>
</table>
@ -37,12 +59,34 @@
<li class="ui-corner-top ui-state-default"><a href="#tabs-3">Attributes</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-3">References</a></li>
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-1">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-1">
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-2">Phasellus mattis tincidunt nibh. Cras orci urna, blandit id, pretium vel, aliquet ornare, felis. Maecenas scelerisque sem non nisl. Fusce sed lorem in enim dictum bibendum.</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-3">Nam dui erat, auctor a, dignissim quis, sollicitudin eu, felis. Pellentesque nisi urna, interdum eget, sagittis et, consequat vestibulum, lacus. Mauris porttitor ullamcorper augue.</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tabs-2">
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tabs-3">
</div>
</div>
{% if user.is_superuser %}
{% if action == "edit" %}
{% make_button "Back to Media" "/media/%s" media.handle %}
<input type="hidden" name="action" value="save"/>
<input type="submit" value="Save"/>
{% else %}
{% ifequal action "add" %}
{% make_button "Cancel" "/media/" %}
<input type="hidden" name="action" value="create"/>
<input type="submit" value="Create"/>
{% else %}
{% make_button "Back to Media" "/media" %}
{% make_button "Add Media" "/media/add" %}
{% make_button "Edit Media" "/media/%s/edit" media.handle %}
{% make_button "Delete Media" "/media/%s/delete" media.handle %}
{% endifequal %}
{% endif %}
{% else %}
{% endif %}
</form>
{% endblock %}

View File

@ -25,22 +25,22 @@
{% endif %}
<form method="post">{% csrf_token %}
<tr>
<td class="ColumnAttribute">{{noteform.gramps_id.label}}:</td>
<td class="ColumnValue" id="data"> {% render noteform.gramps_id user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.note_type.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.note_type user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.text.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.text user action %}</td>
<td class="ColumnValue" id="data" colspan="3">{% render noteform.text user action %}</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="ColumnAttribute">{{noteform.preformatted.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.preformatted user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.gramps_id.label}}:</td>
<td class="ColumnValue" id="data"> {% render noteform.gramps_id user action %}</td>
<td class="ColumnAttribute">{{noteform.note_type.label}}:</td>
<td class="ColumnValue" id="data">{% render noteform.note_type user action %}</td>
</tr>
<tr>
<td class="ColumnAttribute">{{noteform.tags.label}}:</td>
<td class="ColumnValue" id="data" colspan="4">{% render noteform.tags user action %}</td>
</tr>

View File

@ -163,3 +163,39 @@ class NoteForm(forms.ModelForm):
model = Note
exclude = ["handle"]
class MediaForm(forms.ModelForm):
class Meta:
model = Media
exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality"]
def clean(self):
from webapp.utils import dp
data = super(MediaForm, 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(MediaForm, 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'}))
desc = forms.CharField(label="Title",
required=False,
widget=TextInput(attrs={'size':'70'}))
path = forms.CharField(label="Path",
required=False,
widget=TextInput(attrs={'size':'70'}))

View File

@ -413,7 +413,7 @@ class PrimaryObject(models.Model):
## Fields:
id = models.AutoField(primary_key=True)
handle = models.CharField(max_length=19, unique=True)
gramps_id = models.CharField('gramps id', max_length=25, blank=True)
gramps_id = models.CharField('ID', max_length=25, blank=True)
last_saved = models.DateTimeField('last changed', auto_now=True)
last_changed = models.DateTimeField('last changed', null=True,
blank=True) # user edits
@ -431,7 +431,7 @@ class Person(PrimaryObject):
"""
The model for the person object
"""
gender_type = models.ForeignKey('GenderType')
gender_type = models.ForeignKey('GenderType', verbose_name="Gender")
probably_alive = models.BooleanField("Probably alive")
families = models.ManyToManyField('Family', blank=True, null=True)
parent_families = models.ManyToManyField('Family',
@ -475,7 +475,7 @@ class Family(PrimaryObject):
null=True, blank=True)
mother = models.ForeignKey('Person', related_name="mother_ref",
null=True, blank=True)
family_rel_type = models.ForeignKey('FamilyRelType')
family_rel_type = models.ForeignKey('FamilyRelType', verbose_name="Type")
tags = models.ManyToManyField('Tag', blank=True, null=True)
def make_tag_list(self):
@ -515,7 +515,7 @@ class Source(PrimaryObject):
# .datamap_set
class Event(DateObject, PrimaryObject):
event_type = models.ForeignKey('EventType')
event_type = models.ForeignKey('EventType', verbose_name="Type")
description = models.CharField('description', max_length=50, blank=True)
place = models.ForeignKey('Place', null=True, blank=True)
references = generic.GenericRelation('EventRef', related_name="refs",
@ -549,7 +549,7 @@ class Place(PrimaryObject):
class Media(DateObject, PrimaryObject):
path = models.TextField(blank=True)
mime = models.TextField(blank=True, null=True)
desc = models.TextField(blank=True)
desc = models.TextField("Title", blank=True)
references = generic.GenericRelation('MediaRef', related_name="refs",
content_type_field="object_type",
object_id_field="object_id")
@ -559,7 +559,7 @@ class Media(DateObject, PrimaryObject):
return tuple()
class Note(PrimaryObject):
note_type = models.ForeignKey('NoteType')
note_type = models.ForeignKey('NoteType', verbose_name="Type")
text = models.TextField(blank=True)
preformatted = models.BooleanField('preformatted')
references = generic.GenericRelation('NoteRef', related_name="refs",
@ -595,6 +595,7 @@ class Surname(models.Model):
Surname table, which links to name.
"""
name_origin_type = models.ForeignKey('NameOriginType',
verbose_name="Origin",
related_name="name_origin_code",
default=2)
surname = models.TextField(blank=True)
@ -608,7 +609,7 @@ class Surname(models.Model):
return "%s" % self.surname
class Name(DateObject, SecondaryObject):
name_type = models.ForeignKey('NameType',
name_type = models.ForeignKey('NameType', verbose_name="Type",
related_name="name_code",
default=2)
preferred = models.BooleanField('Preferred name?')

View File

@ -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 Media
from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
@ -41,88 +41,54 @@ def process_media(request, context, handle, action): # view, edit, save
context["tview"] = _("Media")
context["tviews"] = _("Media")
context["action"] = "view"
context["object"] = Media()
view_template = "view_media_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":
media = Media()
mediaform = MediaForm(instance=media)
mediaform.model = media
elif action in ["view", "edit"]:
media = Media.objects.get(handle=handle)
mediaform = MediaForm(instance=media)
mediaform.model = media
elif action == "save":
media = Media.objects.get(handle=handle)
mediaform = MediaForm(request.POST, instance=media)
mediaform.model = media
if mediaform.is_valid():
update_last_changed(media, request.user.username)
media = mediaform.save()
dji.rebuild_cache(media)
action = "view"
else:
action = "edit"
elif action == "create":
media = Media(handle=create_id())
mediaform = MediaForm(request.POST, instance=media)
mediaform.model = media
if mediaform.is_valid():
update_last_changed(media, request.user.username)
media = mediaform.save()
dji.rebuild_cache(media)
action = "view"
else:
action = "add"
elif action == "delete":
media = Media.objects.get(handle=handle)
media.delete()
return redirect("/media/")
else:
raise Exception("Unhandled action: '%s'" % action)
context["mediaform"] = mediaform
context["object"] = media
context["media"] = media
context["action"] = action
return render_to_response(view_template, context)