Exemple #1
0
    def sync_division_captains_email_group(self, force=False):
        group_address = generate_email_list_address(self, suffix='captains')
        group_name = generate_email_list_name(self, suffix='Captains')

        from ultimate.utils.google_api import GoogleAppsApi
        api = GoogleAppsApi()
        group_id = api.prepare_group_for_sync(
            group_name=group_name,
            group_id=self.division_captains_email_group_id,
            group_email_address=group_address,
            force=force)

        self.division_captains_email = group_address
        self.division_captains_email_group_id = group_id

        success_count = 0

        for team_member in TeamMember.objects.filter(team__league=self, captain=True).order_by('user__last_name'):
            success_count += add_to_group(
                group_email_address=group_address,
                group_id=group_id,
                email_address=team_member.user.email)

        self.save()

        return success_count, group_address
Exemple #2
0
    def sync_email_group(self, force=False):
        group_address = generate_email_list_address(self.league, team=self)
        group_name = generate_email_list_name(self.league, team=self)

        from ultimate.utils.google_api import GoogleAppsApi
        api = GoogleAppsApi()
        group_id = api.prepare_group_for_sync(
            group_name=group_name,
            group_id=self.group_id,
            group_email_address=group_address,
            force=force)

        self.email = group_address
        self.group_id = group_id

        success_count = 0
        for team_member in self.teammember_set.all().order_by('user__last_name', 'user__first_name'):
            success_count += add_to_group(
                group_email_address=group_address,
                group_id=group_id,
                email_address=team_member.user.email)

        self.save()

        return success_count, group_address
Exemple #3
0
    def sync_division_email_group(self, force=False):
        group_address = generate_email_list_address(self)
        group_name = generate_email_list_name(self)

        from ultimate.utils.google_api import GoogleAppsApi
        api = GoogleAppsApi()
        group_id = api.prepare_group_for_sync(
            group_name=group_name,
            group_id=self.division_email_group_id,
            group_email_address=group_address,
            force=force)

        self.division_email = group_address
        self.division_email_group_id = group_id

        success_count = 0

        if Team.objects.filter(league=self).exists():
            for team_member in TeamMember.objects.filter(team__league=self).order_by('user__last_name'):
                success_count += add_to_group(
                    group_email_address=group_address,
                    group_id=group_id,
                    email_address=team_member.user.email)
        else:
            for registration in sorted(self.get_complete_registrations(), key=lambda r: r.user.last_name):
                success_count += add_to_group(
                    group_email_address=group_address,
                    group_id=group_id,
                    email_address=registration.user.email)

        self.save()

        return success_count, group_address
Exemple #4
0
def add_to_group(group_id=None,
                 group_email_address=None,
                 email_address=None,
                 file_path=None):
    api = GoogleAppsApi()
    success_count = 0

    if email_address:
        if api.add_group_member(email_address,
                                group_id=group_id,
                                group_email_address=group_email_address):
            success_count = success_count + 1

    elif file_path:
        try:
            opened_file = open(file_path, 'r')
            email_list = opened_file.read().splitlines()

            for email_address in email_list:
                if api.add_group_member(
                        email_address,
                        group_id=group_id,
                        group_email_address=group_email_address):
                    success_count = success_count + 1

        finally:
            if opened_file is not None:
                opened_file.close()

    return success_count
def get_events():
    calendar_id = getattr(settings, 'GOOGLE_APPS_CALENDAR_ID', False)
    events = []
    since = timedelta(weeks=0)
    until = timedelta(weeks=12)

    if calendar_id:
        api = GoogleAppsApi()

        events = api.get_calendar_events(calendar_id, since, until)

    return events