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():
|
def _controllers():
|
||||||
return {
|
return {
|
||||||
conditions.CategoryFlag: CategoryConditionController,
|
conditions.CategoryFlag: CategoryConditionController,
|
||||||
|
conditions.GroupMemberDiscount: GroupMemberConditionController,
|
||||||
|
conditions.GroupMemberFlag: GroupMemberConditionController,
|
||||||
conditions.IncludedProductDiscount: ProductConditionController,
|
conditions.IncludedProductDiscount: ProductConditionController,
|
||||||
conditions.ProductFlag: ProductConditionController,
|
conditions.ProductFlag: ProductConditionController,
|
||||||
conditions.SpeakerFlag: SpeakerConditionController,
|
conditions.SpeakerFlag: SpeakerConditionController,
|
||||||
|
@ -319,7 +321,17 @@ class SpeakerConditionController(IsMetByFilter, ConditionController):
|
||||||
# User is a copresenter
|
# User is a copresenter
|
||||||
user_is_copresenter = Q(
|
user_is_copresenter = Q(
|
||||||
is_copresenter=True,
|
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)
|
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 . import inventory
|
||||||
|
|
||||||
|
from django.contrib.auth.models import Group
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
@ -81,7 +82,7 @@ class IncludedProductCondition(models.Model):
|
||||||
|
|
||||||
class SpeakerCondition(models.Model):
|
class SpeakerCondition(models.Model):
|
||||||
''' Conditions that are met if a user is a presenter, or copresenter,
|
''' 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:
|
class Meta:
|
||||||
abstract = True
|
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
|
# Discounts
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -325,12 +340,23 @@ class SpeakerDiscount(SpeakerCondition, DiscountBase):
|
||||||
verbose_name_plural = _("discounts (speaker)")
|
verbose_name_plural = _("discounts (speaker)")
|
||||||
|
|
||||||
|
|
||||||
class RoleDiscount(object):
|
class GroupMemberDiscount(GroupMemberCondition, DiscountBase):
|
||||||
''' Discounts that are enabled because the active user has a specific
|
''' Discounts that are enabled because the user is a member of a specific
|
||||||
role. This is for e.g. volunteers who can get a discount ticket. '''
|
django auth Group.
|
||||||
# TODO: implement RoleDiscount
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
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
|
@python_2_unicode_compatible
|
||||||
class FlagBase(models.Model):
|
class FlagBase(models.Model):
|
||||||
|
@ -517,9 +543,17 @@ class SpeakerFlag(SpeakerCondition, FlagBase):
|
||||||
verbose_name_plural = _("flags (speaker)")
|
verbose_name_plural = _("flags (speaker)")
|
||||||
|
|
||||||
|
|
||||||
# @python_2_unicode_compatible
|
class GroupMemberFlag(GroupMemberCondition, FlagBase):
|
||||||
class RoleFlag(object):
|
''' Flag whose conditions are metbecause the user is a member of a specific
|
||||||
''' The condition is met because the active user has a particular Role.
|
django auth Group.
|
||||||
This is for e.g. enabling Team tickets. '''
|
|
||||||
# TODO: implement RoleFlag
|
Attributes:
|
||||||
pass
|
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…
Reference in a new issue