3
3
from django .template import loader
4
4
import happybase
5
5
import sys ,os
6
- import extract
6
+ # import extract
7
7
from django .core .paginator import Paginator , EmptyPage , PageNotAnInteger
8
8
9
9
pool = happybase .ConnectionPool (size = 3 , host = '192.168.1.240' )
10
10
# pool = happybase.ConnectionPool(size=3, host='127.0.0.1')
11
- global_schema = extract .read_global_schema ("integration/rules/global_schema.txt" )
11
+ # global_schema = extract.read_global_schema("integration/rules/global_schema.txt")
12
12
13
13
14
14
# Create your views here.
@@ -29,10 +29,21 @@ def paginate(phones, page):
29
29
return phones
30
30
31
31
32
+ def _get_specs (columns , row_prefix , limit ):
33
+ with pool .connection () as connection :
34
+ table = connection .table ('phone_specs' )
35
+ try :
36
+ for key , data in table .scan (row_prefix = bytes (row_prefix ), limit = limit , columns = columns ):
37
+ print (key , data )
38
+ except IOError :
39
+ pass
40
+
41
+
32
42
def listing (request ):
33
43
parameters = request .GET
44
+ print parameters
34
45
tables = parameters .getlist ('table' ) if 'table' in parameters else ['phonearena' , 'gsmarena' ]
35
- row_prefix = parameters ['prefix' ]. upper () if 'prefix' in parameters else ''
46
+ row_prefix = parameters ['prefix' ] if 'prefix' in parameters else ''
36
47
try :
37
48
limit = int (parameters .get ('limit' ))
38
49
limit = limit if (limit <= 300 ) else 300
@@ -41,43 +52,47 @@ def listing(request):
41
52
except TypeError :
42
53
limit = 100
43
54
page = request .GET .get ('page' )
55
+ print row_prefix , tables , limit
44
56
45
- with pool .connection () as connection :
46
- phone_data = {}
47
- for table in tables :
48
- phones , exit_code = extract .get_phone_models (connection , table , row_prefix = row_prefix , limit = limit )
49
- if exit_code == 0 :
50
- # print str(phones)
51
- phone_data [table ] = paginate (tuple (phones .items ()), page )
52
- # phone_data[table] = phones
53
-
54
- return render (request , 'list.html' , {'phones' : phone_data ,
55
- 'prefix' : row_prefix , 'limit' : limit })
57
+ _get_specs (tables , row_prefix , limit )
56
58
59
+ # with pool.connection() as connection:
60
+ # phone_data = {}
61
+ # for table in tables:
62
+ # phones, exit_code = extract.get_phone_models(connection, table, row_prefix=row_prefix, limit=limit)
63
+ # if exit_code == 0:
64
+ # # print str(phones)
65
+ # phone_data[table] = paginate(tuple(phones.items()), page)
66
+ # phone_data[table] = phones
57
67
58
- def freebase (request ):
59
68
return HttpResponse ('Hello Freebase' )
69
+ # return render(request, 'list.html', {'phones': phone_data,
70
+ # 'prefix': row_prefix, 'limit': limit})
60
71
61
72
62
- def detail (request ):
63
- print request .POST
64
- if 'phone' in request .POST :
65
- params = request .POST .getlist ('phone' )
66
- with pool .connection () as connection :
67
- phone_data = {}
68
- for param in params :
69
- tokens = param .split ('###' )
70
- table = tokens [0 ]
71
- row_key = tokens [1 ]
72
- data , exit_code = extract .get_phone (connection , table , row_key )
73
- phone_data [param ] = sorted (data .items (), key = sortfn )
74
- return render (request , 'detail.html' , {'phone_data' : phone_data })
75
- else :
76
- return HttpResponseBadRequest ('Bad request' )
77
-
78
-
79
- def sortfn (item ):
80
- if len (global_schema ) == 0 :
81
- return item [0 ]
82
- else :
83
- return global_schema [item [0 ].lower ()]
73
+ # def freebase(request):
74
+ # return HttpResponse('Hello Freebase')
75
+ #
76
+ #
77
+ # def detail(request):
78
+ # print request.POST
79
+ # if 'phone' in request.POST:
80
+ # params = request.POST.getlist('phone')
81
+ # with pool.connection() as connection:
82
+ # phone_data = {}
83
+ # for param in params:
84
+ # tokens = param.split('###')
85
+ # table = tokens[0]
86
+ # row_key = tokens[1]
87
+ # data, exit_code = extract.get_phone(connection, table, row_key)
88
+ # phone_data[param] = sorted(data.items(), key=sortfn)
89
+ # return render(request, 'detail.html', {'phone_data': phone_data})
90
+ # else:
91
+ # return HttpResponseBadRequest('Bad request')
92
+ #
93
+ #
94
+ # def sortfn(item):
95
+ # if len(global_schema) == 0:
96
+ # return item[0]
97
+ # else:
98
+ # return global_schema[item[0].lower()]
0 commit comments