Working on query builder when not logged in
svn: r19786
This commit is contained in:
parent
1d6a4e60c4
commit
6bd01cdff1
@ -112,6 +112,11 @@
|
|||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<font color="red">{{message}}</font>
|
<font color="red">{{message}}</font>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if message %}
|
||||||
|
<div id="system_message" class="{{ message_type }}">
|
||||||
|
<font color="red">{{message}}</font>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
31
src/webapp/context.py
Normal file
31
src/webapp/context.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012 Douglas S. Blank <doug.blank@gmail.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
# $Id: $
|
||||||
|
#
|
||||||
|
|
||||||
|
def messages(request):
|
||||||
|
messages = {}
|
||||||
|
if 'message' in request.session:
|
||||||
|
message_type = request.session.get('message_type', 'error')
|
||||||
|
messages = {'message': request.session['message'],
|
||||||
|
'message_type': message_type}
|
||||||
|
del request.session['message']
|
||||||
|
if 'message_type' in request.session:
|
||||||
|
del request.session['message_type']
|
||||||
|
return messages
|
@ -129,6 +129,12 @@ def logout_page(request):
|
|||||||
logout(request)
|
logout(request)
|
||||||
return HttpResponseRedirect('/')
|
return HttpResponseRedirect('/')
|
||||||
|
|
||||||
|
def make_message(request, message):
|
||||||
|
if request.user.is_authenticated():
|
||||||
|
request.user.message_set.create(message = message)
|
||||||
|
else:
|
||||||
|
request.session['message'] = message
|
||||||
|
|
||||||
def browse_page(request):
|
def browse_page(request):
|
||||||
"""
|
"""
|
||||||
Show the main list under 'Browse' on the main menu.
|
Show the main list under 'Browse' on the main menu.
|
||||||
@ -218,32 +224,26 @@ def process_report_run(request, handle):
|
|||||||
try:
|
try:
|
||||||
import_file(db, filename, cli.user.User()) # callback
|
import_file(db, filename, cli.user.User()) # callback
|
||||||
except:
|
except:
|
||||||
message = "import_file failed: " + traceback.format_exc()
|
make_message(request, "import_file failed: " + traceback.format_exc())
|
||||||
request.user.message_set.create(message = message)
|
|
||||||
threading.Thread(target=background).start()
|
threading.Thread(target=background).start()
|
||||||
message = "Your data is now being imported..."
|
make_message(request, "Your data is now being imported...")
|
||||||
request.user.message_set.create(message = message)
|
|
||||||
return redirect("/report/")
|
return redirect("/report/")
|
||||||
else:
|
else:
|
||||||
success = import_file(db, filename, cli.user.User()) # callback
|
success = import_file(db, filename, cli.user.User()) # callback
|
||||||
if not success:
|
if not success:
|
||||||
message = "Failed to load imported."
|
make_message(request, "Failed to load imported.")
|
||||||
request.user.message_set.create(message = message)
|
|
||||||
return redirect("/report/")
|
return redirect("/report/")
|
||||||
else:
|
else:
|
||||||
message = "No filename was provided or found."
|
make_message(request, "No filename was provided or found.")
|
||||||
request.user.message_set.create(message = message)
|
|
||||||
return redirect("/report/")
|
return redirect("/report/")
|
||||||
else:
|
else:
|
||||||
message = "Invalid report type '%s'" % report.report_type
|
make_message(request, "Invalid report type '%s'" % report.report_type)
|
||||||
request.user.message_set.create(message = message)
|
|
||||||
return redirect("/report/")
|
return redirect("/report/")
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
return send_file(request, filename, mimetype)
|
return send_file(request, filename, mimetype)
|
||||||
else:
|
else:
|
||||||
context = RequestContext(request)
|
context = RequestContext(request)
|
||||||
message = "Failed: '%s' is not found" % filename
|
make_message(request, "Failed: '%s' is not found" % filename)
|
||||||
request.user.message_set.create(message=message)
|
|
||||||
return redirect("/report/")
|
return redirect("/report/")
|
||||||
# If failure, just fail for now:
|
# If failure, just fail for now:
|
||||||
context = RequestContext(request)
|
context = RequestContext(request)
|
||||||
@ -667,21 +667,29 @@ def build_person_query(request, search):
|
|||||||
elif field == "surname":
|
elif field == "surname":
|
||||||
query &= Q(surname__surname__istartswith=value)
|
query &= Q(surname__surname__istartswith=value)
|
||||||
elif field == "given":
|
elif field == "given":
|
||||||
if not protect:
|
if protect:
|
||||||
|
query &= Q(first_name__istartswith=value) & Q(person__probably_alive=False)
|
||||||
|
else:
|
||||||
query &= Q(first_name__istartswith=value)
|
query &= Q(first_name__istartswith=value)
|
||||||
elif field == "private":
|
elif field == "private":
|
||||||
if not protect:
|
if not protect:
|
||||||
query &= Q(person__private=boolean(value))
|
query &= Q(person__private=boolean(value))
|
||||||
elif field == "birth" and not protect:
|
elif field == "birth":
|
||||||
query &= Q(person__birth__year1=safe_int(value))
|
if protect:
|
||||||
elif field == "death" and not protect:
|
query &= Q(person__birth__year1=safe_int(value)) & Q(person__probably_alive=False)
|
||||||
query &= Q(person__death__year1=safe_int(value))
|
else:
|
||||||
|
query &= Q(person__birth__year1=safe_int(value))
|
||||||
|
elif field == "death":
|
||||||
|
if protect:
|
||||||
|
query &= Q(person__death__year1=safe_int(value)) & Q(person__probably_alive=False)
|
||||||
|
else:
|
||||||
|
query &= Q(person__death__year1=safe_int(value))
|
||||||
elif field == "id":
|
elif field == "id":
|
||||||
query &= Q(person__gramps_id__icontains=value)
|
query &= Q(person__gramps_id__icontains=value)
|
||||||
elif field == "gender":
|
elif field == "gender":
|
||||||
query &= Q(person__gender_type__name=value.title())
|
query &= Q(person__gender_type__name=value.title())
|
||||||
else:
|
else:
|
||||||
request.user.message_set.create(message="Invalid query field '%s'" % field)
|
make_message(request, "Invalid query field '%s'" % field)
|
||||||
else: # no search fields, just raw search
|
else: # no search fields, just raw search
|
||||||
if protect:
|
if protect:
|
||||||
query &= (Q(surname__surname__icontains=search) |
|
query &= (Q(surname__surname__icontains=search) |
|
||||||
@ -704,7 +712,6 @@ def build_family_query(request, search):
|
|||||||
table.
|
table.
|
||||||
"""
|
"""
|
||||||
protect = not request.user.is_authenticated()
|
protect = not request.user.is_authenticated()
|
||||||
terms = ["father", "mother"]
|
|
||||||
if protect:
|
if protect:
|
||||||
query = (Q(private=False) & Q(father__private=False) &
|
query = (Q(private=False) & Q(father__private=False) &
|
||||||
Q(mother__private=False))
|
Q(mother__private=False))
|
||||||
@ -722,9 +729,10 @@ def build_family_query(request, search):
|
|||||||
"mother__name__first_name")
|
"mother__name__first_name")
|
||||||
if search:
|
if search:
|
||||||
if "," in search or "=" in search:
|
if "," in search or "=" in search:
|
||||||
if protect:
|
if "," not in search:
|
||||||
query &= (Q(father__private=False) & Q(mother__private=False) &
|
terms = ["surnames"]
|
||||||
Q(private=False))
|
else:
|
||||||
|
terms = ["father", "mother"]
|
||||||
for term in [term.strip() for term in search.split(",")]:
|
for term in [term.strip() for term in search.split(",")]:
|
||||||
if "=" in term:
|
if "=" in term:
|
||||||
field, value = [s.strip() for s in term.split("=")]
|
field, value = [s.strip() for s in term.split("=")]
|
||||||
@ -733,15 +741,19 @@ def build_family_query(request, search):
|
|||||||
field = terms.pop(0)
|
field = terms.pop(0)
|
||||||
value = term
|
value = term
|
||||||
else:
|
else:
|
||||||
|
make_message("Ignoring value without specified field")
|
||||||
continue
|
continue
|
||||||
if "." in field and not protect:
|
if "." in field and not protect:
|
||||||
query &= Q(**{field.replace(".", "__"): value})
|
query &= Q(**{field.replace(".", "__"): value})
|
||||||
|
elif field == "surnames":
|
||||||
|
query &= (Q(father__name__surname__surname__istartswith=value) |
|
||||||
|
Q(mother__name__surname__surname__istartswith=value))
|
||||||
elif field == "father":
|
elif field == "father":
|
||||||
query &= Q(father__name__surname__surname__istartswith=value)
|
query &= Q(father__name__surname__surname__istartswith=value)
|
||||||
elif field == "mother":
|
elif field == "mother":
|
||||||
query &= Q(mother__name__surname__surname__istartswith=value)
|
query &= Q(mother__name__surname__surname__istartswith=value)
|
||||||
else:
|
else:
|
||||||
request.user.message_set.create(message="Invalid query field '%s'" % field)
|
make_message(request, message="Invalid query field '%s'" % field)
|
||||||
else: # no search fields, just raw search
|
else: # no search fields, just raw search
|
||||||
if protect:
|
if protect:
|
||||||
query &= (Q(gramps_id__icontains=search) |
|
query &= (Q(gramps_id__icontains=search) |
|
||||||
@ -755,6 +767,7 @@ def build_family_query(request, search):
|
|||||||
Q(mother__name__surname__surname__icontains=search))
|
Q(mother__name__surname__surname__icontains=search))
|
||||||
else: # no search
|
else: # no search
|
||||||
pass # nothing left to do
|
pass # nothing left to do
|
||||||
|
#make_message(request, query)
|
||||||
return query, order
|
return query, order
|
||||||
|
|
||||||
def safe_int(num):
|
def safe_int(num):
|
||||||
|
@ -84,6 +84,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||||||
"django.core.context_processors.i18n",
|
"django.core.context_processors.i18n",
|
||||||
"django.core.context_processors.media",
|
"django.core.context_processors.media",
|
||||||
"webapp.grampsdb.views.context_processor",
|
"webapp.grampsdb.views.context_processor",
|
||||||
|
"webapp.context.messages",
|
||||||
)
|
)
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
|
Loading…
Reference in New Issue
Block a user