Fixes ordering error in error display
This commit is contained in:
		
							parent
							
								
									ded5114073
								
							
						
					
					
						commit
						de83015776
					
				
					 2 changed files with 32 additions and 27 deletions
				
			
		|  | @ -15,25 +15,6 @@ from registrasion.models import inventory | ||||||
| 
 | 
 | ||||||
| class FlagController(object): | class FlagController(object): | ||||||
| 
 | 
 | ||||||
|     SINGLE = True |  | ||||||
|     PLURAL = False |  | ||||||
|     NONE = True |  | ||||||
|     SOME = False |  | ||||||
|     MESSAGE = { |  | ||||||
|         NONE: { |  | ||||||
|             SINGLE: |  | ||||||
|                 "%(items)s is no longer available to you", |  | ||||||
|             PLURAL: |  | ||||||
|                 "%(items)s are no longer available to you", |  | ||||||
|         }, |  | ||||||
|         SOME: { |  | ||||||
|             SINGLE: |  | ||||||
|                 "Only %(remainder)d of the following item remains: %(items)s", |  | ||||||
|             PLURAL: |  | ||||||
|                 "Only %(remainder)d of the following items remain: %(items)s" |  | ||||||
|         }, |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def test_flags( |     def test_flags( | ||||||
|             cls, user, products=None, product_quantities=None): |             cls, user, products=None, product_quantities=None): | ||||||
|  | @ -103,9 +84,7 @@ class FlagController(object): | ||||||
|             met = consumed <= remainder |             met = consumed <= remainder | ||||||
| 
 | 
 | ||||||
|             if not met: |             if not met: | ||||||
|                 items = ", ".join(str(product) for product in all_products) |                 message = cls._error_message(all_products, remainder) | ||||||
|                 base = cls.MESSAGE[remainder == 0][len(all_products) == 1] |  | ||||||
|                 message = base % {"items": items, "remainder": remainder} |  | ||||||
| 
 | 
 | ||||||
|             for product in all_products: |             for product in all_products: | ||||||
|                 if condition.is_disable_if_false: |                 if condition.is_disable_if_false: | ||||||
|  | @ -135,13 +114,11 @@ class FlagController(object): | ||||||
|             if f.dif > 0 and f.dif != dif_count[product]: |             if f.dif > 0 and f.dif != dif_count[product]: | ||||||
|                 do_not_disable[product] = False |                 do_not_disable[product] = False | ||||||
|                 if product not in messages: |                 if product not in messages: | ||||||
|                     messages[product] = "Some disable-if-false " \ |                     messages[product] = cls._error_message([product], 0) | ||||||
|                                         "conditions were not met" |  | ||||||
|             if f.eit > 0 and product not in do_enable: |             if f.eit > 0 and product not in do_enable: | ||||||
|                 do_enable[product] = False |                 do_enable[product] = False | ||||||
|                 if product not in messages: |                 if product not in messages: | ||||||
|                     messages[product] = "Some enable-if-true " \ |                     messages[product] = cls._error_message([product], 0) | ||||||
|                                         "conditions were not met" |  | ||||||
| 
 | 
 | ||||||
|         for product in itertools.chain(do_not_disable, do_enable): |         for product in itertools.chain(do_not_disable, do_enable): | ||||||
|             f = total_flags.get(product) |             f = total_flags.get(product) | ||||||
|  | @ -160,6 +137,33 @@ class FlagController(object): | ||||||
| 
 | 
 | ||||||
|         return error_fields |         return error_fields | ||||||
| 
 | 
 | ||||||
|  |     SINGLE = True | ||||||
|  |     PLURAL = False | ||||||
|  |     NONE = True | ||||||
|  |     SOME = False | ||||||
|  |     MESSAGE = { | ||||||
|  |         NONE: { | ||||||
|  |             SINGLE: | ||||||
|  |                 "%(items)s is no longer available to you", | ||||||
|  |             PLURAL: | ||||||
|  |                 "%(items)s are no longer available to you", | ||||||
|  |         }, | ||||||
|  |         SOME: { | ||||||
|  |             SINGLE: | ||||||
|  |                 "Only %(remainder)d of the following item remains: %(items)s", | ||||||
|  |             PLURAL: | ||||||
|  |                 "Only %(remainder)d of the following items remain: %(items)s" | ||||||
|  |         }, | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @classmethod | ||||||
|  |     def _error_message(cls, affected, remainder): | ||||||
|  |         product_strings = (str(product) for product in affected) | ||||||
|  |         items = ", ".join(product_strings) | ||||||
|  |         base = cls.MESSAGE[remainder == 0][len(affected) == 1] | ||||||
|  |         message = base % {"items": items, "remainder": remainder} | ||||||
|  |         return message | ||||||
|  | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     @BatchController.memoise |     @BatchController.memoise | ||||||
|     def _filtered_flags(cls, user): |     def _filtered_flags(cls, user): | ||||||
|  |  | ||||||
|  | @ -451,7 +451,8 @@ def _set_quantities_from_products_form(products_form, current_cart): | ||||||
|     pks = [i[0] for i in quantities] |     pks = [i[0] for i in quantities] | ||||||
|     products = inventory.Product.objects.filter( |     products = inventory.Product.objects.filter( | ||||||
|         id__in=pks, |         id__in=pks, | ||||||
|     ).select_related("category") |     ).select_related("category").order_by("id") | ||||||
|  |     quantities.sort(key = lambda i: i[0]) | ||||||
| 
 | 
 | ||||||
|     product_quantities = [ |     product_quantities = [ | ||||||
|         (product, id_to_quantity[product.id]) for product in products |         (product, id_to_quantity[product.id]) for product in products | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer