Migrating changes done to my branch. Including completed archiving querying features and views and templates belong to them.

This commit is contained in:
Mustafa Arıcı 2010-08-11 11:42:16 +00:00
parent 4ccc5d5cd9
commit 159a65786c
7 changed files with 216 additions and 176 deletions

View File

@ -19,3 +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.IntegerField(required = False, label = 'Blog girdisine ait yıl(Örn:2010)', 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.IntegerField(required = False, label = 'Blog girdisine ait gün (Örn:27)', widget=forms.widgets.DateTimeInput())

View File

@ -35,7 +35,7 @@ def main(request):
last_entry_date = Entries.objects.all()[0].date last_entry_date = Entries.objects.all()[0].date
day = datetime.timedelta(days=1) day = datetime.timedelta(days=1)
last_date_li = [] last_date_li = []
for x in xrange(6): for x in xrange(5):
last_entry_date -= day last_entry_date -= day
last_date_li.append(last_entry_date) last_date_li.append(last_entry_date)
@ -116,16 +116,52 @@ def list_members(request):
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 })
def query(request): def query(request):
# Determine if method is POST.
if (request.method == 'POST'):
## If Yes:
form = QueryForm(request.POST)
q_form = QueryForm() # Determine if all of them were valid.
if (form.is_valid()):
return render_response(request,'main/query.html',{ ## If Yes:
'BASE_URL' : BASE_URL,
'q_form':q_form,
})
def archive(request,archive_year='',archive_month='',archive_day=''): q_author_name = request.POST['q_author_name']
q_author_surname = request.POST['q_author_surname']
q_text = request.POST['q_text']
q_date_year = request.POST['q_date_year']
q_date_month = request.POST['q_date_month']
q_date_day = request.POST['q_date_day']
# Redirect or call /archive/ view with the existing POST arguments.
#++ Complex string operations in order to form needed target_url.
args_part = "?q_author_name=%s&q_author_surname=%s&q_text=%s" % (q_author_name,q_author_surname,q_text)
date_part = ''
if (q_date_year):
date_part = q_date_year
if(q_date_month):
date_part += "/" + q_date_month
if(q_date_day):
date_part += "/" + q_date_day + "/"
target_url = BASE_URL+"/archive/" + date_part + args_part
#--
return HttpResponseRedirect(target_url)
else:
# Issue an error message and show the form again.
form = QueryForm()
info_area = "query"
return render_to_response('main/query.html', {'q_form': form, 'BASE_URL': BASE_URL,'info_area':info_area})
else:
# Show the 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):
info_area = 'archive'
# This setting gets the content truncated which contains more than <truncate_words> words. # This setting gets the content truncated which contains more than <truncate_words> words.
truncate_words = 250 truncate_words = 250
items_per_page = 25 items_per_page = 25
@ -133,140 +169,103 @@ def archive(request,archive_year='',archive_month='',archive_day=''):
#get the last run time #get the last run time
run_time = RunTime.objects.all()[0] run_time = RunTime.objects.all()[0]
# Now we are creating few scenarios depending on the incoming variables.
### Determine if the request object includes any querying input or not. ### # This part is for validation.
if ('q_author_name' in request.GET and request.GET['q_author_name']): #If that exists and not empty
if ( (request.GET) and ('q_author_name' in request.GET or 'q_author_surname' in request.GET or 'q_text' in request.GET ) ): q_author_name = request.GET['q_author_name']
# 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 ###
else: else:
#Switch to return the result of arguments provided mode(archive viewing mode). q_author_name = ""
info_area = 'archive' # \This variable is used for determining which infoarea text should be used in "contenttop" div in /main/base.html 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 = ""
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 = ""
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 = ""
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 = ""
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 = ""
#--
#--
# For entry categories # Querying
entries_list1 = selected_entries.filter(entry_id__label_personal = 1) entries_list = Entries.objects.select_related()
entries_list2 = selected_entries.filter(entry_id__label_lkd = 1) # Name - surname queries.
entries_list3 = selected_entries.filter(entry_id__label_community = 1)
entries_list = entries_list1 | entries_list2 | entries_list3
## Validating arguments provided by urls.py. if(q_author_name):
# Check if archive_year is not empty and numeric. entries_list = entries_list.filter(entry_id__author_name__iexact = q_author_name)
if((archive_year != '' ) and (str(archive_year).isalnum()) and (not(str(archive_year).isalpha()))): if(q_author_surname):
entries_list = entries_list.filter(date__year=archive_year) entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname)
else: elif(q_author_surname):
# Fall back to main view. entries_list = entries_list.filter(entry_id__author_surname__iexact = q_author_surname)
return HttpResponseRedirect(BASE_URL+"/main")
#pass
# Check if archive_month is not empty and numeric. # Label based queries.
if(archive_month != ''and (str(archive_month).isalnum()) and not(str(archive_month).isalpha())): if(q_label_personal):
entries_list = entries_list.filter(date__month=archive_month) entries_list = entries_list.filter(entry_id__label_personal = 1)
if(q_label_community):
# Check if archive_day is not empty and numeric. entries_list = entries_list.filter(entry_id__label_community = 1)
if(archive_day != ''and (str(archive_day).isalnum()) and not(str(archive_day).isalpha())): if(q_label_lkd):
entries_list = entries_list.filter(date__day=archive_day) entries_list = entries_list.filter(entry_id__label_lkd = 1)
##
# Pagination # Text search.
elements_in_a_page = 25 # This determines, how many elements will be displayed in a paginator page. if(q_text):
paginator = Paginator(entries_list,elements_in_a_page) entries_list = entries_list.filter(content_text__icontains = q_text)
# Date based queries.
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)
# 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 . # Pagination
try: elements_in_a_page = 25 # This determines, how many elements will be displayed in a paginator page.
p_entries_list = paginator.page(page) paginator = Paginator(entries_list,elements_in_a_page)
except (EmptyPage, InvalidPage): # Validation for page number if it is not int return first page.
p_entries_list = paginator.page(paginator.num_pages) 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,
'archive_year' : archive_year,
'archive_month' : archive_month,
'archive_day' : archive_day,
'q_author_name':q_author_name,
'q_author_surname':q_author_surname,
'q_text':q_text,
'BASE_URL':BASE_URL,
})
def issue_error(request,error_msg=None):
return render_to_response('main/archive.html' ,{ info_area = 'error'
'entries_list':entries_list, if not(error_msg):
'p_entries_list':p_entries_list, error_msg = 'Bilinmeyen bir hata oluştu!'
'truncate_words':truncate_words, return render_response(request, 'main/error.html', {'error_msg': error_msg,'info_area' : info_area })
'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,
})

View File

@ -65,7 +65,7 @@ id = 5
[http://blog.oguz.biz/category/gezegen/rss2] [http://blog.oguz.biz/category/gezegen/rss2]
name = Alper Oğuz name = Alper Oğuz
face = face =
nick = aoguz nick = aoguz
label = Personal label = Personal
id = 6 id = 6
@ -371,7 +371,7 @@ label = Personal
id = 51 id = 51
# Rsssindeki tarih sorunundan dolayı girdisinin gezegende tekrarlı gösteriminden dolayı geçici süre kaldırıldı 17112008 # Rsssindeki tarih sorunundan dolayı girdisinin gezegende tekrarlı gösteriminden dolayı geçici süre kaldırıldı 17112008
# kendisinden gelen update ile adresi düzenlendi # kendisinden gelen update ile adresi düzenlendi
[http://tonguc.name/blog/?flav=atom] [http://tonguc.name/blog/?flav=atom]
name = Tonguç Yumruk name = Tonguç Yumruk
face = tongucyumruk.png face = tongucyumruk.png

View File

@ -44,8 +44,7 @@ TEMPLATE_FILES = "examples/basic/planet.html.tmpl"
import sys import sys
import os import os
# In order to reduce integration issues, this path gets defined automatically. # In order to reduce integration issues, this path gets defined automatically.
sys.path.append(os.path.abspath('../..')) sys.path.append("ABSOLUTEPATH")
os.environ['DJANGO_SETTINGS_MODULE'] = 'djagen.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'djagen.settings'
from djagen.collector.models import * from djagen.collector.models import *
@ -260,21 +259,48 @@ def main():
id_hash = item.id_hash id_hash = item.id_hash
try: try:
entry = author.entries_set.get(id_hash = id_hash) #Only check for get if that fails then switch to create new entry mode.
entry.title = item.title entry = author.entries_set.get(id_hash = item.id_hash)
entry.content_html = item.content
entry.content_text = entry.sanitize(item.content) try:
entry.summary = item.summary entry.title = item.title
entry.link = item.link except:
#print "title"
entry.title = None
try:
entry.content_html = item.content
except:
entry.content_html = None
try:
entry.content_text = entry.sanitize(item.content)
except:
entry.content_text = None
try:
entry.summary = item.summary
except:
#print "summary"
entry.summary = None
try:
entry.link = item.link
except:
#print "link"
entry.link = None
d = item.date d = item.date
entry.date = datetime.datetime(d[0], d[1], d[2], d[3], d[4], d[5]) entry.date = datetime.datetime(d[0], d[1], d[2], d[3], d[4], d[5])
except: except:
content_html = item.content content_html = item.content
#content_text = entry.sanitize(content_html) #content_text = entry.sanitize(content_html)
d = item.date d = item.date
if not item.has_key('summary'): summary = None if not item.has_key('summary'): summary = None
else: summary = item.summary else: summary = item.summary
entry = author.entries_set.create(id_hash=id_hash, title=item.title, content_html=item.content, summary=summary, link=item.link, date=datetime.datetime(d[0], d[1], d[2], d[3], d[4], d[5])) entry = author.entries_set.create(id_hash= item.id_hash, title=item.title, content_html=item.content, summary=summary, link=item.link, date=datetime.datetime(d[0], d[1], d[2], d[3], d[4], d[5]))
entry.content_text = entry.sanitize(content_html) entry.content_text = entry.sanitize(content_html)
entry.save() entry.save()

View File

@ -24,8 +24,8 @@
<body onload="BrowserCompatible.check()"> <body onload="BrowserCompatible.check()">
<div class="wrapper"> <div class="wrapper">
<div class="icons"> <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-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-atom-icon.png" alt="Atom" width="16" height="16" /></a>
</div> </div>
<div class="hdr"> <div class="hdr">
<div class="logo"></div> <div class="logo"></div>
@ -45,10 +45,12 @@
{% blocktrans %}<li><a href="{{ BASE_URL }}/english">İngilizce Günlükler</a></li>{% endblocktrans %} {% blocktrans %}<li><a href="{{ BASE_URL }}/english">İngilizce Günlükler</a></li>{% endblocktrans %}
<li><a href="#" id="arsiv">Arşiv</a> <li><a href="#" id="arsiv">Arşiv</a>
<ul class="navlist"> <ul class="navlist">
<li><a href="{{ BASE_URL }}/query/">{% trans "Ara" %}</a></li>
{% for dt in last_date_li %} {% for dt in last_date_li %}
<li><a href="{{ BASE_URL }}/archive/{{ dt|date:"Y/m/d"}}">{{ dt|date:"d.m.Y" }}</a> <li><a href="{{ BASE_URL }}/archive/{{ dt|date:"Y/m/d"}}">{{ dt|date:"d.m.Y" }}</a>
{% endfor %} {% endfor %}
<li><a href="{{ BASE_URL }}/main/">{% trans "Tümü" %}</a></li>
<li><a href="{{ BASE_URL }}/archive/">{% trans "Tümü" %}</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -59,36 +61,48 @@
<div class="contenttop"> <div class="contenttop">
{% if info_area == "main" %} {% if info_area == "main" %}
<p>Gezegen her 10 dakikada bir yenilenir. Son güncelleme: {{ run_time.get_run_time }}</p> <p>Gezegen her <b>10</b> dakikada bir yenilenir. Son güncelleme: <b>{{ run_time.get_run_time }}</b></p>
{% endif %} {% endif %}
{% if info_area == "archive" %} {% if info_area == "archive" %}
<p>Gezegen arşivi: <b>{{ archive_year }}</b> yılı, {% if entries_list|length %}
{% if archive_month %} <p>{% if archive_year %}
<b>{{ archive_month }}</b>. ay, <b>{{ archive_year }}</b> yılı,
{% endif %} {% endif %}
{% if archive_day %} {% if archive_month %}
<b>{{ archive_day }}</b>. gün <b>{{ archive_month }}</b>. ayı,
{% endif %} {% endif %}
arşivini gezmektesiniz. Bu arşivde toplam <b>{{ entries_list|length }}</b> blog girdisi mevcuttur.</p> {% if archive_day %}
<b>{{ archive_day }}</b>. günü
{% endif %}
{% if q_author_name or q_author_surname %}
{% if q_author_name %}
<b>{{ q_author_name }}</b> isimli,
{% endif %}
{% if q_author_surname %}
<b>{{ q_author_surname }}</b> soyisimli,
{% endif %}
yazara ait
{% endif %}
{% if q_text %}
içinde <b>"{{ q_text|truncatewords:4 }} ..."</b> geçen yazıların olduğu
{% endif %}
{% if archive_year or q_author_name or q_author_surname or q_text %}
gezegen
{% else %}
Gezegen
{% endif %}
arşivini gezmektesiniz.
Bu arşivde toplam <b>{{ entries_list|length }}</b> blog girdisi mevcuttur.</p>
{% else %}
<p><img src="/djagenmedia/img/warning.png" width="25" height="25" /> Bu kriterlere ait herhangi bir girdi <b>bulunmuyor</b>!</p>
{% endif %} {% endif %}
{% endif %}
{% if info_area == "query" %} {% if info_area == "query" %}
<p>Aradığınız kriterler: <p>Lütfen aramak istediğiniz kriterleri giriniz.</p>
{% if q_author_name or q_author_surname %}
{% if q_author_name %}
<b>{{ q_author_name }}</b>
{% endif %}
{% if q_author_surname %}
<b> {{ q_author_surname }}</b>
{% endif %}
isimli yazarlar
{% endif %}
{% if q_text %}
İçinde <b>{{ q_text|truncatewords:8 }}</b> geçen girdiler
{% endif %}.</p>
{% endif %} {% endif %}
@ -109,9 +123,7 @@
{% block footer%} {% block footer%}
<div id="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>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 %}
{% 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 %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -1,7 +1,7 @@
{% extends "main/base.html" %} {% extends "main/base.html" %}
{% block body %} {% block body %}
{% comment %} {% 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"> <b>Yazar<br> Adı:</b><input type="text" name="q_author_name">
ve/veya ve/veya
<b>Soyadı:</b><input type="text" name="q_author_surname"><br> <b>Soyadı:</b><input type="text" name="q_author_surname"><br>
@ -11,7 +11,7 @@
</form> </form>
{% endcomment %} {% endcomment %}
<form action="{{ BASE_URL }}/archive" 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/$','djagen.collector.views.archive'), (r'^archive/$','djagen.collector.views.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),
) )