Beispiel #1
0
def safe_week_for(date):
    dt = datetime(date.year, date.month, date.day)
    try:
        return str(warwick_week_for(dt))
    except Term.DoesNotExist:
        return ""
Beispiel #2
0
    def handle_noargs(self, **options):
        '''
        Runs main update for Compsoc membership details.  The update satisfies the
        following conditions:
        1. Internal Consistency of compsoc models
            user.is_active iff there is a join entry for the current year
        2. Equivalence between compsoc and union models
            user.is_active iff the user is a current member of compsoc or a guest
        3. User information
            compsoc members who have just had an account created, should be emailed
        '''
        from uwcs_website.shortcuts import current_year

        #1. get data from the union
        union_lookup = get_data()

        #2. soundness: if your account is not a guest account and is active then you must be a union member
        # a) sync active members info
        # b) deactivate non union members
        #for user in User.objects.exclude(member__guest=True):
        y = current_year()
        for user in User.objects.filter(is_active=True, member__guest=False):
            if union_lookup.has_key(user.username):
                (first, last, email) = union_lookup[user.username]

                # sync information
                user.first_name = first
                user.last_name = last
                if email is not None:
                    user.email = email
                else:
                    user.email = ""
                    user.is_active = False
                user.save()

                # note that they have joined this year
                MemberJoin.objects.get_or_create(user=user, year=y)

                del union_lookup[user.username]
            # if they're not listed in the union's api, could be a special case
            elif not user.is_staff:
                # next two lines should be removed when historical exec data is added
                ex, created = Group.objects.get_or_create(
                    name=settings.EX_EXEC_GROUP_NAME)

                # if not on the exec at some point or a society
                if not (user.groups.filter(name=settings.EX_EXEC_GROUP_NAME)
                        or Society.objects.filter(user_ptr=user)):
                    try:
                        week = warwick_week_for(datetime.now())
                    except Term.DoesNotExist:
                        week = settings.GRACE_PERIOD + 1  #assume outside of grace period

                    # if inside the grace period
                    if week <= settings.GRACE_PERIOD:
                        # but not a member from last year
                        if not user.memberjoin_set.filter(year=current_year() -
                                                          1):
                            user.is_active = False
                            user.save()
                    else:
                        user.is_active = False
                        user.save()

        #3. completeness: if you are a union member, then you must have a compsoc account
        #                 it is active iff you have a union email address
        #4. TODO: information: emails people who have just had their accounts added
        #5. consistency: ensure there exist current join years for members
        # a) create new accounts for those without
        # b) reactivate accounts for those already with inactive accounts
        for (id, (first, last, email)) in union_lookup.iteritems():

            active = True

            try:
                # find disabled accounts
                user = User.objects.get(username=id)
                print "reactivating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot reactivate %s: no email address" % id
            except User.DoesNotExist:
                print "creating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot activate %s: no email address" % id
                password = User.objects.make_random_password()
                user = User.objects.create_user(id, email, password)
                user.first_name = first
                user.last_name = last
                user.memberjoin_set.create(year=y)
                if not settings.DEBUG:
                    if user.email != "":
                        template_mail(
                            'Welcome to Compsoc', 'memberinfo/new_user_email',
                            {
                                'first': user.first_name,
                                'last': user.last_name,
                                'username': user.username,
                                'password': password,
                                'events': Event.objects.in_future()[:5]
                            }, settings.WEBMASTER_EMAIL, [user.email])

            #sync info
            user.first_name = first
            user.last_name = last
            user.is_active = active

            user.save()
            MemberJoin.objects.get_or_create(user=user, year=y)
Beispiel #3
0
    def handle_noargs(self, **options):
        '''
        Runs main update for Compsoc membership details.  The update satisfies the
        following conditions:
        1. Internal Consistency of compsoc models
            user.is_active iff there is a join entry for the current year
        2. Equivalence between compsoc and union models
            user.is_active iff the user is a current member of compsoc or a guest
        3. User information
            compsoc members who have just had an account created, should be emailed
        '''
        from uwcs_website.shortcuts import current_year

        #1. get data from the union
        union_lookup = get_data()

        #2. soundness: if your account is not a guest account and is active then you must be a union member
        # a) sync active members info
        # b) deactivate non union members
        #for user in User.objects.exclude(member__guest=True):
        y = current_year()
        for user in User.objects.filter(is_active=True, member__guest=False):
            if union_lookup.has_key(user.username):
                (first,last,email) = union_lookup[user.username]

                # sync information
                user.first_name = first
                user.last_name = last
                if email is not None:
                    user.email = email
                else:
                    user.email = ""
                    user.is_active = False
                user.save()

                # note that they have joined this year
                MemberJoin.objects.get_or_create(user=user,year=y)

                del union_lookup[user.username]
            # if they're not listed in the union's api, could be a special case
            elif not user.is_staff:
                # next two lines should be removed when historical exec data is added
                ex, created = Group.objects.get_or_create(name=settings.EX_EXEC_GROUP_NAME)

                # if not on the exec at some point or a society
                if not (user.groups.filter(name=settings.EX_EXEC_GROUP_NAME) or Society.objects.filter(user_ptr=user)):
                    try:
                        week = warwick_week_for(datetime.now())
                    except Term.DoesNotExist:
                        week = settings.GRACE_PERIOD + 1 #assume outside of grace period

                    # if inside the grace period 
                    if week <= settings.GRACE_PERIOD:
                        # but not a member from last year
                        if not user.memberjoin_set.filter(year=current_year()-1):
                            user.is_active = False
                            user.save()
                    else:
                        user.is_active = False
                        user.save()

        #3. completeness: if you are a union member, then you must have a compsoc account
        #                 it is active iff you have a union email address
        #4. TODO: information: emails people who have just had their accounts added
        #5. consistency: ensure there exist current join years for members
        # a) create new accounts for those without
        # b) reactivate accounts for those already with inactive accounts
        for (id,(first,last,email)) in union_lookup.iteritems():

            active = True

            try:
                # find disabled accounts
                user = User.objects.get(username=id)
                print "reactivating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot reactivate %s: no email address" % id
            except User.DoesNotExist:
                print "creating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot activate %s: no email address" % id
                password = User.objects.make_random_password()
                user = User.objects.create_user(id,email,password)
                user.first_name = first
                user.last_name = last
                user.memberjoin_set.create(year=y)
                if not settings.DEBUG:
                    if user.email != "":
                        template_mail(
                            'Welcome to Compsoc',
                            'memberinfo/new_user_email',
                            {'first': user.first_name, 'last':user.last_name, 'username':user.username, 'password':password, 'events':Event.objects.in_future()[:5]},
                            settings.WEBMASTER_EMAIL,
                            [user.email])

            #sync info
            user.first_name = first
            user.last_name = last 
            user.is_active = active

            user.save()
            MemberJoin.objects.get_or_create(user=user,year=y)
Beispiel #4
0
def safe_week_for(date):
    dt = datetime(date.year,date.month,date.day)
    try:
        return str(warwick_week_for(dt))
    except Term.DoesNotExist:
        return ""