Refactored querying related forms, templates, views etc.. Added an error issuing def. "issue_error" in views.py.

This commit is contained in:
Mustafa Arıcı 2010-08-07 13:42:02 +00:00
parent 1ea02d2cc8
commit 68b324096f
4 changed files with 64 additions and 55 deletions

View File

@ -19,6 +19,6 @@ class QueryForm(forms.Form):
q_author_name = forms.CharField(max_length=25, required = False, label = 'Adı') q_author_name = forms.CharField(max_length=25, required = False, label = 'Adı')
q_author_surname = forms.CharField(max_length=25, required = False, label = 'Soyadı') q_author_surname = forms.CharField(max_length=25, required = False, label = 'Soyadı')
q_text = forms.CharField(required = False, label = 'Aradığınız metin', widget = forms.widgets.Textarea() ) q_text = forms.CharField(required = False, label = 'Aradığınız metin', widget = forms.widgets.Textarea() )
q_date_year = forms.DateField(input_formats = '%y',required = False, label = 'Blog girdisine ait yıl(Örn:2010)', widget=forms.widgets.DateTimeInput()) q_date_year = forms.IntegerField(required = False, label = 'Blog girdisine ait yıl(Örn:2010)', widget=forms.widgets.DateTimeInput())
q_date_month = forms.DateField(input_formats = '%m',required = False, label = 'Blog girdisine ait ay(Örn:03)', widget=forms.widgets.DateTimeInput()) q_date_month = forms.IntegerField(required = False, label = 'Blog girdisine ait ay(Örn:03)', widget=forms.widgets.DateTimeInput())
q_date_day = forms.DateField(input_formats = '%d',required = False, label = 'Blog girdisine ait gün (Örn:27)', widget=forms.widgets.DateTimeInput()) q_date_day = forms.IntegerField(required = False, label = 'Blog girdisine ait gün (Örn:27)', widget=forms.widgets.DateTimeInput())

View File

@ -114,47 +114,51 @@ def list_members(request):
authors = Authors.objects.all() authors = Authors.objects.all()
return render_response(request, 'main/members.html', {'members': authors, 'BASE_URL': BASE_URL,'info_area' : info_area }) return render_response(request, 'main/members.html', {'members': authors, 'BASE_URL': BASE_URL,'info_area' : info_area })
#############################Under Construction######################
def query(request): def query(request):
return (HttpResponse("query page")) # Determine if method is POST.
# if(request.method == 'GET'): if (request.method == 'POST'):
# form = QueryForm(request.GET) ## If Yes:
# if form.is_valid(): form = QueryForm(request.POST)
# if(('q_author_name' in request.GET) or
# ('q_author_surname' in request.GET) or # Determine if all of them were valid.
# ('q_text' in request.GET) or if (form.is_valid()):
# ('q_date_year' in request.GET) or
# ('q_date_month' in request.GET) or ## If Yes:
# ('q_date_day' in request.GET)):
# redirect_url = BASE_URL + "/archive" q_author_name = request.POST['q_author_name']
# if ('q_date_year' in request.GET and request.GET['q_date_year']): q_author_surname = request.POST['q_author_surname']
# redirect_url += "/" + request.GET['q_date_year'] q_text = request.POST['q_text']
# if ('q_date_month' in request.GET and request.GET['q_date_month']): q_date_year = request.POST['q_date_year']
# redirect_url += "/" + request.GET['q_date_month'] q_date_month = request.POST['q_date_month']
# if('q_date_day' in request.GET and request.GET['q_date_day']): q_date_day = request.POST['q_date_day']
# redirect_url += "/"+str(request.GET['q_date_day']) # Redirect or call /archive/ view with the existing GET arguments.
# return HttpResponseRedirect(redirect_url) #++ Complex string operations in order to form needed url.
# else: args_part = "?q_author_name=%s&q_author_surname=%s&q_text=%s" % (q_author_name,q_author_surname,q_text)
# q_form = QueryForm() date_part = ''
# return render_response(request,'main/query.html',{ if (q_date_year):
# 'BASE_URL' : BASE_URL, date_part = q_date_year
# 'q_form':q_form, if(q_date_month):
# }) date_part += "/" + q_date_month
# else: if(q_date_day):
# q_form = QueryForm() date_part += "/" + q_date_day + "/"
# return render_response(request,'main/query.html',{ target_url = BASE_URL+"/archive/" + date_part + args_part
# 'BASE_URL' : BASE_URL, #--
# 'q_form':q_form, return HttpResponseRedirect(target_url)
# }) else:
# # Issue an error message and show the form again.
# form = QueryForm()
# else: info_area = "query"
#
# q_form = QueryForm() return render_to_response('main/query.html', {'q_form': form, 'BASE_URL': BASE_URL,'info_area':info_area})
# return render_response(request,'main/query.html',{ else:
# 'BASE_URL' : BASE_URL, # Show the form.
# 'q_form':q_form,
# }) form = QueryForm()
info_area = "query"
return render_to_response('main/query.html', {'q_form': form, 'BASE_URL': BASE_URL,'info_area':info_area})
def archive(request,archive_year=None,archive_month=None,archive_day=None): def archive(request,archive_year=None,archive_month=None,archive_day=None):
info_area = 'query' info_area = 'query'
@ -170,28 +174,28 @@ def archive(request,archive_year=None,archive_month=None,archive_day=None):
if ('q_author_name' in request.GET and request.GET['q_author_name']): #If that exists and not empty if ('q_author_name' in request.GET and request.GET['q_author_name']): #If that exists and not empty
q_author_name = request.GET['q_author_name'] q_author_name = request.GET['q_author_name']
else: else:
q_author_name = None q_author_name = ""
if ('q_author_surname' in request.GET and request.GET['q_author_surname']): #If that exists and not empty if ('q_author_surname' in request.GET and request.GET['q_author_surname']): #If that exists and not empty
q_author_surname = request.GET['q_author_surname'] q_author_surname = request.GET['q_author_surname']
else: else:
q_author_surname = None q_author_surname = ""
if ('q_text' in request.GET and request.GET['q_text']): #If that exists and not empty if ('q_text' in request.GET and request.GET['q_text']): #If that exists and not empty
q_text = request.GET['q_text'] q_text = request.GET['q_text']
else: else:
q_text = None q_text = ""
if ('q_label_personal' in request.GET and request.GET['q_label_personal'] == '1'): #If that exists and not empty if ('q_label_personal' in request.GET and request.GET['q_label_personal'] == '1'): #If that exists and not empty
q_label_personal = request.GET['q_label_personal'] q_label_personal = request.GET['q_label_personal']
else: else:
q_label_personal = None q_label_personal = ""
if ('q_label_community' in request.GET and request.GET['q_label_community'] == '1'): if ('q_label_community' in request.GET and request.GET['q_label_community'] == '1'):
q_label_community = request.GET['q_label_community'] q_label_community = request.GET['q_label_community']
else: else:
q_label_community = None q_label_community = ""
if ('q_label_lkd' in request.GET and request.GET['q_label_lkd']=='1'): if ('q_label_lkd' in request.GET and request.GET['q_label_lkd']=='1'):
q_label_lkd = request.GET['q_label_lkd'] q_label_lkd = request.GET['q_label_lkd']
else: else:
q_label_lkd = None q_label_lkd = ""
#-- #--
#-- #--
@ -206,7 +210,7 @@ def archive(request,archive_year=None,archive_month=None,archive_day=None):
elif(q_author_surname): elif(q_author_surname):
entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname) entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname)
# Label based queries.
if(q_label_personal): if(q_label_personal):
entries_list = entries_list.filter(entry_id__label_personal = 1) entries_list = entries_list.filter(entry_id__label_personal = 1)
if(q_label_community): if(q_label_community):
@ -215,10 +219,10 @@ def archive(request,archive_year=None,archive_month=None,archive_day=None):
entries_list = entries_list.filter(entry_id__label_lkd = 1) entries_list = entries_list.filter(entry_id__label_lkd = 1)
# Text search.
if(q_text): if(q_text):
entries_list = entries.list.filter(content_text__icontains = q_text) entries_list = entries_list.filter(content_text__icontains = q_text)
# Date based queries.
if(archive_year): if(archive_year):
entries_list = entries_list.filter(date__year = archive_year) entries_list = entries_list.filter(date__year = archive_year)
if(archive_month): if(archive_month):
@ -257,3 +261,8 @@ def archive(request,archive_year=None,archive_month=None,archive_day=None):
'BASE_URL':BASE_URL, 'BASE_URL':BASE_URL,
}) })
def issue_error(request,error_msg=None):
info_area = 'error'
if not(error_msg):
error_msg = 'Bilinmeyen bir hata oluştu!'
return render_response(request, 'main/error.html', {'error_msg': error_msg,'info_area' : info_area })

View File

@ -11,7 +11,7 @@
</form> </form>
{% endcomment %} {% endcomment %}
<form action="{{ BASE_URL }}/query" method="GET" enctype="multipart/form-data"> <form action="{{ BASE_URL }}/query/" method="POST" enctype="multipart/form-data">
{% for field in q_form %} {% for field in q_form %}
<div class="fieldWrapper"> <div class="fieldWrapper">
{% if field.errors %} {% if field.errors %}

View File

@ -22,7 +22,7 @@ urlpatterns = patterns('',
(r'^archive/$',archive), (r'^archive/$',archive),
(r'^archive/(?P<archive_year>\d{4})/$', archive), (r'^archive/(?P<archive_year>\d{4})/$', archive),
(r'^archive/(?P<archive_year>\d{4})/(?P<archive_month>\d{1,2})/$', archive), (r'^archive/(?P<archive_year>\d{4})/(?P<archive_month>\d{1,2})/$', archive),
(r'^archive/(?P<archive_year>\d{4})/(?P<archive_month>\d{1,2})/(?P<archive_day>\d{1,2})$', archive), (r'^archive/(?P<archive_year>\d{4})/(?P<archive_month>\d{1,2})/(?P<archive_day>\d{1,2})/$', archive),
(r'^djagen/$',main), (r'^djagen/$',main),
(r'^query/$',query), (r'^query/$',query),
) )