Search on gender, id, with safe_int(); citation_table refiniement

svn: r19777
This commit is contained in:
Doug Blank 2012-06-06 20:19:52 +00:00
parent 32b61fc60f
commit 5f8b823159
2 changed files with 22 additions and 9 deletions

View File

@ -368,7 +368,7 @@ def view_list(request, view):
if request.user.is_authenticated():
if request.GET.has_key("search"):
search = request.GET.get("search")
query = build_person_query(search, protect=False)
query = build_person_query(request, search, protect=False)
object_list = Name.objects \
.filter(query) \
.order_by("surname__surname", "first_name")
@ -378,7 +378,7 @@ def view_list(request, view):
# BEGIN NON-AUTHENTICATED users
if request.GET.has_key("search"):
search = request.GET.get("search")
query = build_person_query(search, protect=True)
query = build_person_query(request, search, protect=True)
object_list = Name.objects \
.filter(query) \
.order_by("surname__surname", "first_name")
@ -681,7 +681,7 @@ def process_report(request, context, handle, action):
context["tview"] = _("Report")
context["tviews"] = _("Reports")
def build_person_query(search, protect):
def build_person_query(request, search, protect):
if "," in search or "=" in search:
query = Q()
terms = ["surname", "given"]
@ -700,21 +700,34 @@ def build_person_query(search, protect):
elif field == "private":
query &= Q(person__private=boolean(value))
elif field == "birth":
query &= Q(person__birth__year1=value)
query &= Q(person__birth__year1=safe_int(value))
elif field == "death":
query &= Q(person__death__year1=value)
query &= Q(person__death__year1=safe_int(value))
elif field == "id":
query &= Q(person__gramps_id__icontains=value)
elif field == "gender":
query &= Q(person__gender_type__name=value.title())
else:
request.user.message_set.create(message="Invalid query field '%s'" % field)
else:
query = (Q(surname__surname__icontains=search) |
Q(first_name__icontains=search) |
Q(suffix__icontains=search) |
Q(surname__prefix__icontains=search) |
Q(person__gender_type__name=search.title()) |
Q(person__birth__year1=safe_int(search)) |
Q(person__death__year1=safe_int(search)) |
Q(title__icontains=search) |
Q(person__gramps_id__icontains=search))
if protect:
query &= (Q(private=False) & Q(person__private=False))
return query
def safe_int(num):
try:
return int(num)
except:
return -1
def process_reference(request, ref_by, handle, ref_to, order):
# FIXME: can I make this work for all?

View File

@ -712,15 +712,15 @@ def citation_reference_table(obj, user, action):
table.columns(
_("Type"),
_("Reference"),
_("ID"))
# _("ID")
)
if user.is_authenticated() and action != "add":
for reference in models.CitationRef.objects.filter(citation=obj):
ref_from_class = reference.object_type.model_class()
item = ref_from_class.objects.get(id=reference.object_id)
table.row(
item.__class__.__name__,
item,
item.gramps_id)
item)
retval += table.get_html()
retval += nbsp("") # to keep tabs same height
return retval