@@ -37,8 +37,6 @@ def data_for_songs_list(request, search_string=''):
3737 sql = ''
3838 word_query_sql = ''
3939 songs_list = []
40- track_index = 0
41-
4240 results_lookup = {}
4341
4442 if (len (search_filters ) > 0 ):
@@ -49,21 +47,9 @@ def data_for_songs_list(request, search_string=''):
4947 row = cursor .fetchone ()
5048 results = []
5149 while (row ):
52- row_type = track_index % 2
5350 if (results_lookup .get (row [7 ]) is None ):
5451 results_lookup [row [7 ]] = 1
55- results .append ({
56- 'title' : row [0 ],
57- 'album' : row [1 ],
58- 'artist' : row [2 ],
59- 'image_file' : row [3 ],
60- 'path' : row [4 ],
61- 'year' : row [5 ],
62- 'track' : row [6 ],
63- 'row_type' : row_type ,
64- 'track_index' : track_index
65- })
66- track_index += 1
52+ results .append (_row_as_dict (row ))
6753 row = cursor .fetchone ()
6854 if (must_shuffle [query_index ]):
6955 songs_list .extend (random .shuffle (results ))
@@ -79,7 +65,6 @@ def data_for_songs_list(request, search_string=''):
7965 cursor .execute (sql , search_params )
8066 row = cursor .fetchone ()
8167 while (row ):
82- row_type = track_index % 2
8368 if (results_lookup .get (row [7 ]) is None ):
8469 results_lookup [row [7 ]] = 1
8570 songs_list .append ({
@@ -90,10 +75,7 @@ def data_for_songs_list(request, search_string=''):
9075 'path' : row [4 ],
9176 'year' : row [5 ],
9277 'track' : row [6 ],
93- 'row_type' : row_type ,
94- 'track_index' : track_index
9578 })
96- track_index += 1
9779 row = cursor .fetchone ()
9880
9981 context = {'songs_list' : songs_list ,
@@ -117,7 +99,9 @@ def get_filters_sql(search_filters):
11799 single_statements = []
118100 index = 0
119101 for single_query in single_queries :
120- sql = 'SELECT ' + ',' .join (selecting_fields ) + ' FROM ' + ',' .join (selecting_tables ) + ' WHERE ' + ' AND ' .join (common_conditions ) + ' AND ' + \
102+ sql = 'SELECT ' + ',' .join (selecting_fields ) + ' FROM ' + \
103+ ',' .join (selecting_tables ) + ' WHERE ' + \
104+ ' AND ' .join (common_conditions ) + ' AND ' + \
121105 single_query + ' ORDER BY ' + ',' .join (sorting_fields )
122106 single_statements .append (sql )
123107 index += 1
@@ -135,10 +119,13 @@ def get_filters_sql(search_filters):
135119
136120
137121def get_word_query_sql (search_words ):
122+ global inner_sql
138123 single_statements = []
139124 for i in (range (len (search_words ))):
140125 single_statements .append (
141- 'SELECT ' + ',' .join (selecting_fields ) + ' FROM ' + ',' .join (selecting_tables ) + ' WHERE ' + ' AND ' .join (common_conditions ) + 'AND ( title like %s or lister_album.description like %s or lister_artist.description like %s)' )
126+ 'SELECT ' + ',' .join (selecting_fields ) + ' FROM ' +
127+ ',' .join (selecting_tables ) + ' WHERE ' +
128+ ' AND ' .join (common_conditions ) + ' AND ' + inner_sql )
142129 word_query = ' UNION ' .join (
143130 single_statements ) + ' ORDER BY ' + ',' .join (sorting_fields )
144131 search_params = []
@@ -148,6 +135,13 @@ def get_word_query_sql(search_words):
148135 return (word_query , search_params )
149136
150137
138+ def _row_as_dict (row ):
139+ return {
140+ 'title' : row [0 ], 'album' : row [1 ], 'artist' : row [2 ],
141+ 'image_file' : row [3 ], 'path' : row [4 ], 'year' : row [5 ], 'track' : row [6 ]
142+ }
143+
144+
151145def get_counters ():
152146 counters = {}
153147 cursor = connection .cursor ()
0 commit comments