def sync_division_email_group(self, force=False):
        group_address = "{}{}-{}-{}@lists.annarborultimate.org".format(
            self.season.slug, self.league_start_date.strftime("%y"), self.league_start_date.strftime("%a"), self.level
        ).lower()
        group_name = "{} {} {} {}".format(
            self.season.name,
            self.league_start_date.strftime("%Y"),
            self.league_start_date.strftime("%A"),
            self.display_level,
        )

        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_email = group_address
        self.division_email_group_id = group_id

        success_count = 0
        for registration in self.get_complete_registrations():
            if api.add_group_member(
                registration.user.email, group_id=self.division_email_group_id, group_email_address=group_address
            ):
                success_count = success_count + 1

        self.division_email = group_address
        self.save()

        return success_count, group_address
Exemple #2
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
    def sync_email_group(self, force=False):
        group_address = "{}{}-{}-{}-{}@lists.annarborultimate.org".format(
            self.league.season.slug,
            self.league.league_start_date.strftime("%y"),
            self.league.league_start_date.strftime("%a"),
            self.league.level,
            self.id,
        ).lower()
        group_name = "{} {} {} {} Team {}".format(
            self.league.season.name,
            self.league.league_start_date.strftime("%Y"),
            self.league.league_start_date.strftime("%A"),
            self.league.display_level,
            self.id,
        )

        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():
            if api.add_group_member(team_member.user.email, group_id=self.group_id, group_email_address=group_address):
                success_count = success_count + 1

        self.save()

        return success_count, group_address
Exemple #4
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 #5
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 #6
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
Exemple #7
0
def get_events():
    calendar_id = getattr(settings, 'GOOGLE_APPS_CALENDAR_ID', False)
    events = []
    since = timedelta(weeks=4)

    if calendar_id:
        api = GoogleAppsApi()

        events = api.get_calendar_events(calendar_id, since)

    return events
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
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
Exemple #10
0
    def sync_division_captains_email_group(self, force=False):
        group_address = '{}{}-{}-{}[email protected]'.format(
            self.season.slug,
            self.league_start_date.strftime('%y'),
            self.league_start_date.strftime('%a'),
            self.level,
            ).lower()
        group_name = '{} {} {} {} Captains'.format(
            self.season.name,
            self.league_start_date.strftime('%Y'),
            self.league_start_date.strftime('%A'),
            self.display_level,
            )

        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 registration in self.get_complete_registrations():
            team_member_captain = 0
            team_member_models = TeamMember.objects.filter(user=registration.user, team__league=registration.league)
            if team_member_models.count():
                if team_member_models[:1].get().captain:
                    if api.add_group_member(registration.user.email, group_id=self.division_captains_email_group_id, group_email_address=group_address):
                        success_count = success_count + 1

        self.save()

        return success_count, group_address