Complete - task : Refactoring and improvements on archive view.
This commit is contained in:
parent
03eb214fa6
commit
1ea02d2cc8
|
@ -19,3 +19,6 @@ class QueryForm(forms.Form):
|
|||
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_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_month = forms.DateField(input_formats = '%m',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())
|
||||
|
|
|
@ -35,7 +35,7 @@ def main(request):
|
|||
last_entry_date = Entries.objects.all()[0].date
|
||||
day = datetime.timedelta(days=1)
|
||||
last_date_li = []
|
||||
for x in xrange(6):
|
||||
for x in xrange(5):
|
||||
last_entry_date -= day
|
||||
last_date_li.append(last_entry_date)
|
||||
|
||||
|
@ -114,18 +114,50 @@ def list_members(request):
|
|||
authors = Authors.objects.all()
|
||||
|
||||
return render_response(request, 'main/members.html', {'members': authors, 'BASE_URL': BASE_URL,'info_area' : info_area })
|
||||
|
||||
#############################Under Construction######################
|
||||
def query(request):
|
||||
return (HttpResponse("query page"))
|
||||
# if(request.method == 'GET'):
|
||||
# form = QueryForm(request.GET)
|
||||
# if form.is_valid():
|
||||
# if(('q_author_name' in request.GET) or
|
||||
# ('q_author_surname' in request.GET) or
|
||||
# ('q_text' in request.GET) or
|
||||
# ('q_date_year' in request.GET) or
|
||||
# ('q_date_month' in request.GET) or
|
||||
# ('q_date_day' in request.GET)):
|
||||
# redirect_url = BASE_URL + "/archive"
|
||||
# if ('q_date_year' in request.GET and request.GET['q_date_year']):
|
||||
# redirect_url += "/" + request.GET['q_date_year']
|
||||
# if ('q_date_month' in request.GET and request.GET['q_date_month']):
|
||||
# redirect_url += "/" + request.GET['q_date_month']
|
||||
# if('q_date_day' in request.GET and request.GET['q_date_day']):
|
||||
# redirect_url += "/"+str(request.GET['q_date_day'])
|
||||
# return HttpResponseRedirect(redirect_url)
|
||||
# else:
|
||||
# q_form = QueryForm()
|
||||
# return render_response(request,'main/query.html',{
|
||||
# 'BASE_URL' : BASE_URL,
|
||||
# 'q_form':q_form,
|
||||
# })
|
||||
# else:
|
||||
# q_form = QueryForm()
|
||||
# return render_response(request,'main/query.html',{
|
||||
# 'BASE_URL' : BASE_URL,
|
||||
# 'q_form':q_form,
|
||||
# })
|
||||
#
|
||||
#
|
||||
# else:
|
||||
#
|
||||
# q_form = QueryForm()
|
||||
# return render_response(request,'main/query.html',{
|
||||
# 'BASE_URL' : BASE_URL,
|
||||
# 'q_form':q_form,
|
||||
# })
|
||||
|
||||
q_form = QueryForm()
|
||||
|
||||
return render_response(request,'main/query.html',{
|
||||
'BASE_URL' : BASE_URL,
|
||||
'q_form':q_form,
|
||||
})
|
||||
|
||||
def archive(request,archive_year='',archive_month='',archive_day=''):
|
||||
|
||||
def archive(request,archive_year=None,archive_month=None,archive_day=None):
|
||||
info_area = 'query'
|
||||
# This setting gets the content truncated which contains more than <truncate_words> words.
|
||||
truncate_words = 250
|
||||
items_per_page = 25
|
||||
|
@ -133,140 +165,95 @@ def archive(request,archive_year='',archive_month='',archive_day=''):
|
|||
#get the last run time
|
||||
run_time = RunTime.objects.all()[0]
|
||||
|
||||
|
||||
### Determine if the request object includes any querying input or not. ###
|
||||
|
||||
if ( (request.GET) and ('q_author_name' in request.GET or 'q_author_surname' in request.GET or 'q_text' in request.GET ) ):
|
||||
# Switch to 'return the result of query' mode.
|
||||
info_area = 'query'
|
||||
|
||||
#Querying
|
||||
#TODO: We should improve querying method implemented here.
|
||||
q_author_name,q_author_surname,q_text = '','',''
|
||||
authors = Authors.objects.all()
|
||||
if ( ('q_author_name' in request.GET) and (request.GET['q_author_name'] )):
|
||||
q_author_name = request.GET['q_author_name']
|
||||
authors = authors.filter(author_name__iexact = q_author_name)
|
||||
|
||||
|
||||
if (('q_author_surname' in request.GET) and (request.GET['q_author_surname'])):
|
||||
q_author_surname = request.GET['q_author_surname']
|
||||
authors = authors.filter(author_surname__iexact = q_author_surname)
|
||||
|
||||
|
||||
for item in authors:
|
||||
|
||||
try:
|
||||
entries_list |= item.entries_set.all()
|
||||
except:
|
||||
entries_list = item.entries_set.all()
|
||||
|
||||
if( ('q_text' in request.GET)and(request.GET['q_text'])):
|
||||
q_text = request.GET['q_text']
|
||||
if (q_author_name or q_author_surname):
|
||||
|
||||
entries_list = entries_list.filter(content_text__icontains = q_text)
|
||||
else:
|
||||
entries_list = Entries.objects.filter(content_text__icontains = q_text)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
if(not(entries_list)):
|
||||
return HttpResponseRedirect(BASE_URL+"/query")
|
||||
except:
|
||||
return HttpResponseRedirect(BASE_URL+ "/query")
|
||||
|
||||
#here is gonna be edited [X]
|
||||
# Pagination
|
||||
|
||||
elements_in_a_page = 25 # This determines, how many elements will be displayed in a paginator page.
|
||||
paginator = Paginator(entries_list,elements_in_a_page)
|
||||
# Validation for page number if it is not int return first page.
|
||||
try:
|
||||
page = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
# If page request is out of range, return last page .
|
||||
try:
|
||||
p_entries_list = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
p_entries_list = paginator.page(paginator.num_pages)
|
||||
|
||||
return render_to_response('main/archive.html' ,{
|
||||
'entries_list':entries_list,
|
||||
'p_entries_list':p_entries_list,
|
||||
'truncate_words':truncate_words,
|
||||
'items_per_page':repr(items_per_page),
|
||||
'run_time':run_time,
|
||||
'info_area':info_area,
|
||||
'q_author_name':q_author_name,
|
||||
'q_author_surname':q_author_surname,
|
||||
'q_text':q_text,
|
||||
'BASE_URL':BASE_URL,
|
||||
})
|
||||
### If not ###
|
||||
# Now we are creating few scenarios depending on the incoming variables.
|
||||
# This part is for validation.
|
||||
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']
|
||||
else:
|
||||
#Switch to return the result of arguments provided mode(archive viewing mode).
|
||||
info_area = 'archive' # \This variable is used for determining which infoarea text should be used in "contenttop" div in /main/base.html
|
||||
q_author_name = None
|
||||
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']
|
||||
else:
|
||||
q_author_surname = None
|
||||
if ('q_text' in request.GET and request.GET['q_text']): #If that exists and not empty
|
||||
q_text = request.GET['q_text']
|
||||
else:
|
||||
q_text = None
|
||||
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']
|
||||
else:
|
||||
q_label_personal = None
|
||||
if ('q_label_community' in request.GET and request.GET['q_label_community'] == '1'):
|
||||
q_label_community = request.GET['q_label_community']
|
||||
else:
|
||||
q_label_community = None
|
||||
|
||||
selected_entries = Entries.objects.select_related()
|
||||
if ('q_label_lkd' in request.GET and request.GET['q_label_lkd']=='1'):
|
||||
q_label_lkd = request.GET['q_label_lkd']
|
||||
else:
|
||||
q_label_lkd = None
|
||||
#--
|
||||
#--
|
||||
|
||||
# For entry categories
|
||||
entries_list1 = selected_entries.filter(entry_id__label_personal = 1)
|
||||
entries_list2 = selected_entries.filter(entry_id__label_lkd = 1)
|
||||
entries_list3 = selected_entries.filter(entry_id__label_community = 1)
|
||||
entries_list = entries_list1 | entries_list2 | entries_list3
|
||||
# Querying
|
||||
entries_list = Entries.objects.select_related()
|
||||
# Name - surname queries.
|
||||
|
||||
## Validating arguments provided by urls.py.
|
||||
# Check if archive_year is not empty and numeric.
|
||||
if((archive_year != '' ) and (str(archive_year).isalnum()) and (not(str(archive_year).isalpha()))):
|
||||
entries_list = entries_list.filter(date__year=archive_year)
|
||||
else:
|
||||
# Fall back to main view.
|
||||
return HttpResponseRedirect(BASE_URL+"/main")
|
||||
#pass
|
||||
|
||||
# Check if archive_month is not empty and numeric.
|
||||
if(archive_month != ''and (str(archive_month).isalnum()) and not(str(archive_month).isalpha())):
|
||||
entries_list = entries_list.filter(date__month=archive_month)
|
||||
|
||||
# Check if archive_day is not empty and numeric.
|
||||
if(archive_day != ''and (str(archive_day).isalnum()) and not(str(archive_day).isalpha())):
|
||||
entries_list = entries_list.filter(date__day=archive_day)
|
||||
##
|
||||
if(q_author_name):
|
||||
entries_list = entries_list.filter(entry_id__author_name__iexact = q_author_name)
|
||||
if(q_author_surname):
|
||||
entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname)
|
||||
elif(q_author_surname):
|
||||
entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname)
|
||||
|
||||
|
||||
# Pagination
|
||||
elements_in_a_page = 25 # This determines, how many elements will be displayed in a paginator page.
|
||||
paginator = Paginator(entries_list,elements_in_a_page)
|
||||
|
||||
# Validation for page number if it is not int return first page.
|
||||
try:
|
||||
page = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
# If page request is out of range, return last page .
|
||||
try:
|
||||
p_entries_list = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
p_entries_list = paginator.page(paginator.num_pages)
|
||||
if(q_label_personal):
|
||||
entries_list = entries_list.filter(entry_id__label_personal = 1)
|
||||
if(q_label_community):
|
||||
entries_list = entries_list.filter(entry_id__label_community = 1)
|
||||
if(q_label_lkd):
|
||||
entries_list = entries_list.filter(entry_id__label_lkd = 1)
|
||||
|
||||
|
||||
|
||||
if(q_text):
|
||||
entries_list = entries.list.filter(content_text__icontains = q_text)
|
||||
|
||||
if(archive_year):
|
||||
entries_list = entries_list.filter(date__year = archive_year)
|
||||
if(archive_month):
|
||||
entries_list = entries_list.filter(date__month = archive_month)
|
||||
if(archive_day):
|
||||
entries_list = entries_list.filter(date__day = archive_day)
|
||||
|
||||
#--
|
||||
|
||||
# Pagination
|
||||
elements_in_a_page = 25 # This determines, how many elements will be displayed in a paginator page.
|
||||
paginator = Paginator(entries_list,elements_in_a_page)
|
||||
# Validation for page number if it is not int return first page.
|
||||
try:
|
||||
page = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
# If page request is out of range, return last page .
|
||||
try:
|
||||
p_entries_list = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
p_entries_list = paginator.page(paginator.num_pages)
|
||||
#--
|
||||
|
||||
return render_to_response('main/archive.html' ,{
|
||||
'entries_list':entries_list,
|
||||
'p_entries_list':p_entries_list,
|
||||
'truncate_words':truncate_words,
|
||||
'items_per_page':repr(items_per_page),
|
||||
'run_time':run_time,
|
||||
'info_area':info_area,
|
||||
'q_author_name':q_author_name,
|
||||
'q_author_surname':q_author_surname,
|
||||
'q_text':q_text,
|
||||
'BASE_URL':BASE_URL,
|
||||
})
|
||||
|
||||
return render_to_response('main/archive.html' ,{
|
||||
'entries_list':entries_list,
|
||||
'p_entries_list':p_entries_list,
|
||||
'truncate_words':truncate_words,
|
||||
'items_per_page':repr(items_per_page),
|
||||
'run_time':run_time,
|
||||
'archive_year':archive_year,
|
||||
'archive_month':archive_month,
|
||||
'archive_day':archive_day,
|
||||
#'error':error,
|
||||
'BASE_URL':BASE_URL,
|
||||
'info_area':info_area,
|
||||
})
|
||||
|
|
|
@ -44,8 +44,7 @@ TEMPLATE_FILES = "examples/basic/planet.html.tmpl"
|
|||
import sys
|
||||
import os
|
||||
# In order to reduce integration issues, this path gets defined automatically.
|
||||
sys.path.append(os.path.abspath('../..'))
|
||||
|
||||
sys.path.append("/home/cad/Workspace/djagen_ws/gezegen/DJAGEN/branches/mustafa_branch/")
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'djagen.settings'
|
||||
from djagen.collector.models import *
|
||||
|
||||
|
@ -185,13 +184,12 @@ def main():
|
|||
for word in words: tmp_first_name += ' ' + word
|
||||
author_name = tmp_first_name[1:]
|
||||
### ###
|
||||
print channel.name
|
||||
#print channel.name
|
||||
#author_name = channel.name
|
||||
#author_surname = channel.surname
|
||||
|
||||
try:
|
||||
author_face = channel.face
|
||||
print channel.face
|
||||
except:
|
||||
author_face = None
|
||||
try:
|
||||
|
@ -214,7 +212,6 @@ def main():
|
|||
channel_urlstatus = channel.url_status
|
||||
except:
|
||||
channel_urlstatus = None
|
||||
print channel.label
|
||||
label = channel.label
|
||||
|
||||
label_personal = 0
|
||||
|
@ -229,7 +226,6 @@ def main():
|
|||
label_community = 1
|
||||
if label == "Eng":
|
||||
label_eng = 1
|
||||
print channel.id
|
||||
id = channel.id
|
||||
|
||||
try:
|
||||
|
@ -251,7 +247,7 @@ def main():
|
|||
author.label_eng = label_eng
|
||||
|
||||
except Exception, ex:
|
||||
print ex
|
||||
#print ex
|
||||
author = Authors(author_id=id, author_name=author_name, author_surname=author_surname, author_face=author_face, channel_subtitle=channel_subtitle, channel_title=channel_title, channel_url=channel_url, channel_link=channel_link, channel_urlstatus=channel_urlstatus, label_personal=label_personal, label_lkd=label_lkd, label_community=label_community, label_eng=label_eng)
|
||||
|
||||
|
||||
|
|
|
@ -257,7 +257,6 @@ body {
|
|||
}
|
||||
|
||||
.blogcontent img {
|
||||
float:right;
|
||||
margin:0 0 20px 10px;
|
||||
}
|
||||
|
||||
|
@ -266,7 +265,7 @@ body {
|
|||
color:#000;
|
||||
}
|
||||
|
||||
.blogcontent ul li {
|
||||
.blogcontent ul li{
|
||||
padding:0 0 4px 25px;
|
||||
background:url(img/bullet.png) left center no-repeat;
|
||||
}
|
||||
|
@ -282,6 +281,6 @@ body {
|
|||
|
||||
.footer p {
|
||||
line-height:45px;
|
||||
color:#FFF;
|
||||
color:white;
|
||||
padding:0 0 0 20px;
|
||||
}
|
|
@ -24,8 +24,8 @@
|
|||
<body onload="BrowserCompatible.check()">
|
||||
<div class="wrapper">
|
||||
<div class="icons">
|
||||
<a href="#"><img src="/djagenmedia/img/Newsfeed-RSS-icon.png" alt="RSS" width="16" height="16" /></a>
|
||||
<a href="#"><img src="/djagenmedia/img/Newsfeed-Atom-icon.png" alt="Atom" width="16" height="16" /></a>
|
||||
<a href="#"><img src="/djagenmedia/img/newsfeed-rss-icon.png" alt="RSS" width="16" height="16" /></a>
|
||||
<a href="#"><img src="/djagenmedia/img/newsfeed-atom-icon.png" alt="Atom" width="16" height="16" /></a>
|
||||
</div>
|
||||
<div class="hdr">
|
||||
<div class="logo"></div>
|
||||
|
@ -45,10 +45,12 @@
|
|||
{% blocktrans %}<li><a href="{{ BASE_URL }}/english">İngilizce Günlükler</a></li>{% endblocktrans %}
|
||||
<li><a href="#" id="arsiv">Arşiv</a>
|
||||
<ul class="navlist">
|
||||
<li><a href="{{ BASE_URL }}/query/">{% trans "Ara" %}</a></li>
|
||||
{% for dt in last_date_li %}
|
||||
<li><a href="{{ BASE_URL }}/archive/{{ dt|date:"Y/m/d"}}">{{ dt|date:"d.m.Y" }}</a>
|
||||
{% endfor %}
|
||||
<li><a href="{{ BASE_URL }}/main/">{% trans "Tümü" %}</a></li>
|
||||
|
||||
<li><a href="{{ BASE_URL }}/archive/">{% trans "Tümü" %}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -109,9 +111,7 @@
|
|||
|
||||
{% block footer%}
|
||||
<div id="footer">
|
||||
{% blocktrans %}<p>Bu sayfa içerisinde yazılanlar doğru veya yanlış herhangi bir biçimde <a href="http://www.lkd.org.tr/">Linux Kullanıcıları Derneği</a>'ni bağlamaz</p>{% endblocktrans %}
|
||||
{% blocktrans %}<p>LKD yalnızca Linux Gezegeni için teknik olanakları (sunucu, yazılım, bant genişliği) sağlar.</p>{% endblocktrans %}
|
||||
{% blocktrans %}<p>Ayrıca Gezegen istatistiklere <a href="http://gezegen.linux.org.tr/stats">buradan</a> ulaşabilirsiniz.</p>{% endblocktrans %}
|
||||
{% blocktrans %}<p>Bu sayfa içerisinde yazılanlar doğru veya yanlış herhangi bir biçimde LKD<http://www.lkd.org.tr/>'yi bağlamaz. Ayrıca Gezegen istatistiklere buradan<http://gezegen.linux.org.tr/stats> ulaşabilirsiniz.</p>{% endblocktrans %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "main/base.html" %}
|
||||
{% block body %}
|
||||
{% comment %}
|
||||
<form action='{{ BASE_URL }}/archive ' method='GET'>
|
||||
<form action="{{ BASE_URL }}/query" method='GET'>
|
||||
<b>Yazar<br> Adı:</b><input type="text" name="q_author_name">
|
||||
ve/veya
|
||||
<b>Soyadı:</b><input type="text" name="q_author_surname"><br>
|
||||
|
@ -11,7 +11,7 @@
|
|||
</form>
|
||||
{% endcomment %}
|
||||
|
||||
<form action="{{ BASE_URL }}/archive" method="GET" enctype="multipart/form-data">
|
||||
<form action="{{ BASE_URL }}/query" method="GET" enctype="multipart/form-data">
|
||||
{% for field in q_form %}
|
||||
<div class="fieldWrapper">
|
||||
{% if field.errors %}
|
||||
|
|
|
@ -19,7 +19,7 @@ urlpatterns = patterns('',
|
|||
(r'^main/', 'djagen.collector.views.main'),
|
||||
(r'^subscribe/', 'djagen.collector.views.member_subscribe'),
|
||||
(r'^members/', 'djagen.collector.views.list_members'),
|
||||
(r'^archive/$','djagen.collector.views.archive'),
|
||||
(r'^archive/$',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})/(?P<archive_day>\d{1,2})$', archive),
|
||||
|
|
Loading…
Reference in New Issue
Block a user