Adds GroupMemberCondition, derivatives, and controllers.
This commit is contained in:
		
							parent
							
								
									0601470006
								
							
						
					
					
						commit
						136c68aa0a
					
				
					 2 changed files with 59 additions and 13 deletions
				
			
		|  | @ -23,6 +23,8 @@ class ConditionController(object): | |||
|     def _controllers(): | ||||
|         return { | ||||
|             conditions.CategoryFlag: CategoryConditionController, | ||||
|             conditions.GroupMemberDiscount: GroupMemberConditionController, | ||||
|             conditions.GroupMemberFlag: GroupMemberConditionController, | ||||
|             conditions.IncludedProductDiscount: ProductConditionController, | ||||
|             conditions.ProductFlag: ProductConditionController, | ||||
|             conditions.SpeakerFlag: SpeakerConditionController, | ||||
|  | @ -319,7 +321,17 @@ class SpeakerConditionController(IsMetByFilter, ConditionController): | |||
|         # User is a copresenter | ||||
|         user_is_copresenter = Q( | ||||
|             is_copresenter=True, | ||||
|             proposal_kind__proposalbase__presentation__additional_speakers__user=u, | ||||
|             proposal_kind__proposalbase__presentation__additional_speakers__user=u,  # NOQA | ||||
|         ) | ||||
| 
 | ||||
|         return queryset.filter(user_is_presenter | user_is_copresenter) | ||||
| 
 | ||||
| 
 | ||||
| class GroupMemberConditionController(IsMetByFilter, ConditionController): | ||||
| 
 | ||||
|     @classmethod | ||||
|     def pre_filter(self, queryset, user): | ||||
|         ''' Returns all of the items from queryset which are enabled by a user | ||||
|         being member of a Django Auth Group. ''' | ||||
| 
 | ||||
|         return queryset | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ import itertools | |||
| 
 | ||||
| from . import inventory | ||||
| 
 | ||||
| from django.contrib.auth.models import Group | ||||
| from django.core.exceptions import ValidationError | ||||
| from django.db import models | ||||
| from django.utils.encoding import python_2_unicode_compatible | ||||
|  | @ -81,7 +82,7 @@ class IncludedProductCondition(models.Model): | |||
| 
 | ||||
| class SpeakerCondition(models.Model): | ||||
|     ''' Conditions that are met if a user is a presenter, or copresenter, | ||||
|     of a specific of presentation. ''' | ||||
|     of a specific kind of presentation. ''' | ||||
| 
 | ||||
|     class Meta: | ||||
|         abstract = True | ||||
|  | @ -103,6 +104,20 @@ class SpeakerCondition(models.Model): | |||
|     ) | ||||
| 
 | ||||
| 
 | ||||
| class GroupMemberCondition(models.Model): | ||||
|     ''' Conditions that are met if a user is a member (not declined or | ||||
|     rejected) of a specific django auth group. ''' | ||||
| 
 | ||||
|     class Meta: | ||||
|         abstract = True | ||||
| 
 | ||||
|     group = models.ManyToManyField( | ||||
|         Group, | ||||
|         help_text=_("The groups a user needs to be a member of for this" | ||||
|                     "condition to be met."), | ||||
|     ) | ||||
| 
 | ||||
| 
 | ||||
| # Discounts | ||||
| 
 | ||||
| @python_2_unicode_compatible | ||||
|  | @ -325,12 +340,23 @@ class SpeakerDiscount(SpeakerCondition, DiscountBase): | |||
|         verbose_name_plural = _("discounts (speaker)") | ||||
| 
 | ||||
| 
 | ||||
| class RoleDiscount(object): | ||||
|     ''' Discounts that are enabled because the active user has a specific | ||||
|     role. This is for e.g. volunteers who can get a discount ticket. ''' | ||||
|     # TODO: implement RoleDiscount | ||||
|     pass | ||||
| class GroupMemberDiscount(GroupMemberCondition, DiscountBase): | ||||
|     ''' Discounts that are enabled because the user is a member of a specific | ||||
|     django auth Group. | ||||
| 
 | ||||
|     Attributes: | ||||
|         group ([Group, ...]): The condition should be met if the user is a | ||||
|             member of one of these groups. | ||||
| 
 | ||||
|     ''' | ||||
| 
 | ||||
|     class Meta: | ||||
|         app_label = "registrasion" | ||||
|         verbose_name = _("discount (group member)") | ||||
|         verbose_name_plural = _("discounts (group member)") | ||||
| 
 | ||||
| 
 | ||||
| # Flags | ||||
| 
 | ||||
| @python_2_unicode_compatible | ||||
| class FlagBase(models.Model): | ||||
|  | @ -517,9 +543,17 @@ class SpeakerFlag(SpeakerCondition, FlagBase): | |||
|         verbose_name_plural = _("flags (speaker)") | ||||
| 
 | ||||
| 
 | ||||
| # @python_2_unicode_compatible | ||||
| class RoleFlag(object): | ||||
|     ''' The condition is met because the active user has a particular Role. | ||||
|     This is for e.g. enabling Team tickets. ''' | ||||
|     # TODO: implement RoleFlag | ||||
|     pass | ||||
| class GroupMemberFlag(GroupMemberCondition, FlagBase): | ||||
|     ''' Flag whose conditions are metbecause the user is a member of a specific | ||||
|     django auth Group. | ||||
| 
 | ||||
|     Attributes: | ||||
|         group ([Group, ...]): The condition should be met if the user is a | ||||
|             member of one of these groups. | ||||
| 
 | ||||
|     ''' | ||||
| 
 | ||||
|     class Meta: | ||||
|         app_label = "registrasion" | ||||
|         verbose_name = _("flag (group member)") | ||||
|         verbose_name_plural = _("flags (group member)") | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer