Rename vars photos -> results since results may contain albums.
This commit is contained in:
		
							parent
							
								
									0e0f296270
								
							
						
					
					
						commit
						18c2f0dc78
					
				
					 2 changed files with 20 additions and 18 deletions
				
			
		|  | @ -396,20 +396,19 @@ def get_search_core(): | ||||||
|     search_kwargs['tag_mays'] = tagname_helper(search_kwargs['tag_mays']) |     search_kwargs['tag_mays'] = tagname_helper(search_kwargs['tag_mays']) | ||||||
|     search_kwargs['tag_forbids'] = tagname_helper(search_kwargs['tag_forbids']) |     search_kwargs['tag_forbids'] = tagname_helper(search_kwargs['tag_forbids']) | ||||||
| 
 | 
 | ||||||
|     search_results = list(search_generator) |  | ||||||
|     warnings = set() |     warnings = set() | ||||||
|     photos = [] |     search_results = [] | ||||||
|     for item in search_results: |     for item in search_generator: | ||||||
|         if isinstance(item, etiquette.objects.WarningBag): |         if isinstance(item, etiquette.objects.WarningBag): | ||||||
|             warnings.update(item.warnings) |             warnings.update(item.warnings) | ||||||
|         else: |         else: | ||||||
|             photos.append(item) |             search_results.append(item) | ||||||
| 
 | 
 | ||||||
|     # TAGS ON THIS PAGE |     # TAGS ON THIS PAGE | ||||||
|     total_tags = set() |     total_tags = set() | ||||||
|     for photo in photos: |     for result in search_results: | ||||||
|         if isinstance(photo, etiquette.objects.Photo): |         if isinstance(result, etiquette.objects.Photo): | ||||||
|             total_tags.update(photo.get_tags()) |             total_tags.update(result.get_tags()) | ||||||
|     total_tags = sorted(total_tags, key=lambda t: t.name) |     total_tags = sorted(total_tags, key=lambda t: t.name) | ||||||
| 
 | 
 | ||||||
|     # PREV-NEXT PAGE URLS |     # PREV-NEXT PAGE URLS | ||||||
|  | @ -417,7 +416,7 @@ def get_search_core(): | ||||||
|     original_params = request.args.to_dict() |     original_params = request.args.to_dict() | ||||||
|     original_params['limit'] = limit |     original_params['limit'] = limit | ||||||
| 
 | 
 | ||||||
|     if limit and len(photos) >= limit: |     if limit and len(search_results) >= limit: | ||||||
|         next_params = original_params.copy() |         next_params = original_params.copy() | ||||||
|         next_params['offset'] = offset + limit |         next_params['offset'] = offset + limit | ||||||
|         next_params = helpers.dict_to_params(next_params) |         next_params = helpers.dict_to_params(next_params) | ||||||
|  | @ -443,7 +442,7 @@ def get_search_core(): | ||||||
|     final_results = { |     final_results = { | ||||||
|         'next_page_url': next_page_url, |         'next_page_url': next_page_url, | ||||||
|         'prev_page_url': prev_page_url, |         'prev_page_url': prev_page_url, | ||||||
|         'photos': photos, |         'results': search_results, | ||||||
|         'total_tags': total_tags, |         'total_tags': total_tags, | ||||||
|         'warnings': list(warnings), |         'warnings': list(warnings), | ||||||
|         'search_kwargs': search_kwargs, |         'search_kwargs': search_kwargs, | ||||||
|  | @ -460,7 +459,7 @@ def get_search_html(): | ||||||
|         'search.html', |         'search.html', | ||||||
|         next_page_url=search_results['next_page_url'], |         next_page_url=search_results['next_page_url'], | ||||||
|         prev_page_url=search_results['prev_page_url'], |         prev_page_url=search_results['prev_page_url'], | ||||||
|         photos=search_results['photos'], |         results=search_results['results'], | ||||||
|         search_kwargs=search_kwargs, |         search_kwargs=search_kwargs, | ||||||
|         total_tags=search_results['total_tags'], |         total_tags=search_results['total_tags'], | ||||||
|         warnings=search_results['warnings'], |         warnings=search_results['warnings'], | ||||||
|  | @ -471,8 +470,11 @@ def get_search_html(): | ||||||
| @session_manager.give_token | @session_manager.give_token | ||||||
| def get_search_json(): | def get_search_json(): | ||||||
|     search_results = get_search_core() |     search_results = get_search_core() | ||||||
|     search_results['photos'] = [ |     search_results['results'] = [ | ||||||
|         etiquette.jsonify.photo(photo, include_albums=False) for photo in search_results['photos'] |         etiquette.jsonify.photo(result, include_albums=False) | ||||||
|  |         if isinstance(result, etiquette.objects.Photo) else | ||||||
|  |         etiquette.jsonify.album(result, minimal=True) | ||||||
|  |         for result in search_results['results'] | ||||||
|     ] |     ] | ||||||
|     search_results['total_tags'] = [ |     search_results['total_tags'] = [ | ||||||
|         etiquette.jsonify.tag(tag, minimal=True) for tag in search_results['total_tags'] |         etiquette.jsonify.tag(tag, minimal=True) for tag in search_results['total_tags'] | ||||||
|  |  | ||||||
|  | @ -343,16 +343,16 @@ | ||||||
|         {% endfor %} |         {% endfor %} | ||||||
|     </div> |     </div> | ||||||
|     <div id="happy_message_area"> |     <div id="happy_message_area"> | ||||||
|         <p>You got {{photos|length}} items.</p> |         <p>You got {{results|length}} items.</p> | ||||||
|     </div> |     </div> | ||||||
|     <div id="right"> |     <div id="right"> | ||||||
|         {{prev_next_buttons()}} |         {{prev_next_buttons()}} | ||||||
|         <div id="search_results_holder"> |         <div id="search_results_holder"> | ||||||
|             {% for photo in photos %} |             {% for result in results %} | ||||||
|                 {% if photo.__class__.__name__ == 'Photo' %} |                 {% if result.__class__.__name__ == 'Photo' %} | ||||||
|                 {{photo_card.create_photo_card(photo, view=search_kwargs["view"])}} |                 {{photo_card.create_photo_card(result, view=search_kwargs["view"])}} | ||||||
|                 {% elif photo.__class__.__name__ == 'Album' %} |                 {% elif result.__class__.__name__ == 'Album' %} | ||||||
|                 {{album_card.create_album_card(photo, view=search_kwargs["view"])}} |                 {{album_card.create_album_card(result, view=search_kwargs["view"])}} | ||||||
|                 {% endif %} |                 {% endif %} | ||||||
|             {% endfor %} |             {% endfor %} | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue