Example #1
0
    def filter_on_email(email):
        """Because the `focus.models.Enrollment.email` field is of the `ntext` type, we can't perform lookups on it
        without casting it to nvarchar, which we can't do through the ORM layer."""
        from membership.util import kdu_2016_dates

        # First filter on the given email with a raw query. Django takes care of SQL injection.
        query = 'select * from %s where Cast(Email as nvarchar(max)) = %%s' % Enrollment._meta.db_table
        params = [email]
        enrollments = Enrollment.objects.raw(query, params)

        # Now we need to reimplement the filtering in `Enrollment.get_active`.

        # Filter on valid payment method
        enrollments = [
            e for e in enrollments
            if e.payment_method in [PAYMENT_METHOD_CODES['card'], PAYMENT_METHOD_CODES['invoice']]
        ]

        # Exclude submitted entries; these members should now be retrieved from `Actor`
        enrollments = [
            e for e in enrollments
            if e.submitted_date is None
            # Special case for KDU-dagen 2016: Members enrolled on the following dates will have submitted_date
            # specified, but should be accessible regardless.
            # @TODO: Remove after årskravet 2016, when these pending members become proper members.
            or (
                e.registration_date >= kdu_2016_dates()['start']
                and e.registration_date <= kdu_2016_dates()['end']
            )
        ]

        # Okay, return the queryset
        return enrollments
Example #2
0
    def get_active():
        from membership.util import kdu_2016_dates
        # Note: Any changes to the `get_active` filter should most likely be duplicated in the `filter_on_email` static
        # method below.
        return Enrollment.objects.filter(
            # Valid payment method
            Q(payment_method=PAYMENT_METHOD_CODES['card']) |
            Q(payment_method=PAYMENT_METHOD_CODES['invoice']),

            # Exclude submitted entries; these members should now be retrieved from `Actor`
            Q(submitted_date__isnull=True) |

            # Special case for KDU-dagen 2016: Members enrolled on the following dates will have submitted_date
            # specified, but should be accessible regardless.
            # @TODO: Remove after årskravet 2016, when these pending members become proper members.
            Q(
                registration_date__gte=kdu_2016_dates()['start'],
                registration_date__lte=kdu_2016_dates()['end'],
            )
        )
Example #3
0
 def is_kdu_2016_member(self):
     # @TODO: Remove after årskravet 2016
     from membership.util import kdu_2016_dates
     return self.enrollment.registration_date >= kdu_2016_dates()['start'] \
         and self.enrollment.registration_date <= kdu_2016_dates()['end']