team4alfanous team mailing list archive
-
team4alfanous team
-
Mailing list archive
-
Message #00351
[Branch ~team4alfanous/alfanous/alfanous-git] Rev 535: preparing the access control to the WUI and the JOS2
------------------------------------------------------------
revno: 535
committer: Assem Chelli <assem.ch@xxxxxxxxx>
timestamp: Tue 2013-01-08 15:45:07 +0100
message:
preparing the access control to the WUI and the JOS2
modified:
src/alfanous-django/wui/models.py
src/alfanous-django/wui/views.py
--
lp:alfanous
https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git
Your team Alfanous team is subscribed to branch lp:alfanous.
To unsubscribe from this branch go to https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git/+edit-subscription
=== modified file 'src/alfanous-django/wui/models.py'
--- src/alfanous-django/wui/models.py 2012-08-08 23:11:59 +0000
+++ src/alfanous-django/wui/models.py 2013-01-08 14:45:07 +0000
@@ -3,6 +3,10 @@
class Visit (models.Model):
id = models.AutoField(primary_key=True)
+ ip = models.CharField( max_length = 15 ) #may be this should be the key
+ host = models.CharField( max_length = 255 )
+ referer = models.CharField( max_length = 255 )
+ request = models.CharField( max_length = 255 )
query = models.CharField( max_length=255)
sorted_by = models.CharField( max_length=10)
recitation = models.CharField( max_length=30)
=== modified file 'src/alfanous-django/wui/views.py'
--- src/alfanous-django/wui/views.py 2013-01-08 11:00:30 +0000
+++ src/alfanous-django/wui/views.py 2013-01-08 14:45:07 +0000
@@ -32,34 +32,40 @@
# load the search engine, use default paths
RAWoutput = Raw()
+def control_access ( request ):
+ """ Controling access to the API """
+ print request.META["REMOTE_ADDR"]
+ print request.META["REMOTE_HOST"]
+ print request.META["QUERY_STRING"]
+ #print request.META["HTTP_REFERER"]
+ print request.META["QUERY_STRING"]
+ print "is ajax?", request.is_ajax()
+ return True
+
def jos2( request ):
""" JSON Output System II """
-
+ control_access( request )
if len( request.GET ):
response_data = RAWoutput.do( request.GET )
response = HttpResponse( json.dumps( response_data ), mimetype = "application/json" )
response['charset'] = 'utf-8'
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Methods'] = 'GET'
-
else:
response_data = RAWoutput._information["json_output_system_note"]
response = HttpResponse( response_data )
-
return response
-
def results( request, unit = "aya", language = None ):
""" """
- if unit not in ["aya", "word", "translation"]: # authorized units
+ available_units = ["aya", "word", "translation"]
+ if unit not in available_units:
unit = "aya"
mutable_request = {}
for k, v in request.GET.items():
mutable_request[k] = v
-
show_params = { "action":"show", "query": "all" }
-
if mutable_request.has_key( "query" ) and not ( mutable_request.has_key( "action" ) and not mutable_request["action"] == "search" ):
search_params = mutable_request
suggest_params = { "action":"suggest", "query": mutable_request["query"] }
@@ -74,7 +80,7 @@
suggest_params = {
"action":"suggest",
"query": mutable_request["search"]
- }
+ }
else:
search_params = {}
suggest_params = {}
@@ -86,7 +92,6 @@
raw_suggest = RAWoutput.do( suggest_params ) if suggest_params else None
#use show as third action
raw_show = RAWoutput.do( show_params ) if show_params else None
-
# language information
current_language = translation.get_language()
request_language = translation.get_language_from_request( request )[:2]
@@ -103,9 +108,7 @@
translation.activate( current_language )
language_info = get_language_info( current_language )
language = current_language
-
request.LANGUAGE_CODE = translation.get_language()
-
# language direction properties
bidi_val = language_info['bidi']
fields_mapping_en_ar = raw_show["show"]["fields_reverse"]
@@ -128,15 +131,21 @@
"fields": fields_mapping_en_ar
}
}
-
mytemplate = unit + '_search.html'
-
return render_to_response( mytemplate ,
{
- 'current_path': request.get_full_path(),
+ 'current': {
+ 'path': request.path,
+ 'request': request.GET.urlencode(),
+ 'unit': unit,
+ 'language': language,
+ },
"bidi":bidi_properties[bidi_val],
"language": language_info,
- "available_languages": available_languages,
+ "available": {
+ "languages": available_languages,
+ "units": available_units,
+ },
"params": search_params,
"results": raw_search,
"suggestions": raw_suggest,