예제 #1
0
 def getFilterTerms(self):
     get_dict = self.request.GET
     kwargs = RequestFunctions.getMultipleRequestObj(get_dict, 'kwargs')
     if kwargs is not None:
         kwargs = json.loads(kwargs)
         return kwargs
     return {}
    def getRangeTerms(self):
        get_dict = self.request.GET
        range_start = RequestFunctions.getMultipleRequestObj(get_dict, 'start')
        range_end = RequestFunctions.getMultipleRequestObj(get_dict, 'end')

        try:
            range_start = (int(range_start) -
                           1 if int(range_start) - 1 >= 0 else 0)
        except Exception:
            range_start = 0

        try:
            range_end = (int(range_end) if int(range_end) >= 0 else 0)
        except Exception:
            range_end = 0

        if range_end <= range_start:
            range_start = 0
            range_end = None

        return range_start, range_end
예제 #3
0
 def getRangeTerms(self):
     get_dict = self.request.GET
     range_start = RequestFunctions.getMultipleRequestObj(get_dict, 'start')
     range_end = RequestFunctions.getMultipleRequestObj(get_dict, 'end')
     return MiscUtils.verifyRangeTerms(range_start, range_end)
예제 #4
0
    def _add(self, **kwargs):
        post_dict = dict(self.request.POST)

        event_type = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_type')
        event_name = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_name')
        event_status = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_status')
        event_description = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_description')
        event_location = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_location')
        event_season = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_season')
        event_region = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_region')
        event_host = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_host')
        event_school = RequestFunctions.getMultipleRequestObj(
            post_dict, 'event_team')
        event_race_number = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_race_number')
        event_boat_rotation_name = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_boat_rotation_name')
        event_start_date = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_start_date')
        event_end_date = RequestFunctions.getSingleRequestObj(
            post_dict, 'event_end_date')

        race_tag_dict = dict()
        team_activity_dict = dict()

        # event generation
        event_creation = self.base_class()
        event_creation.event_type = int(event_type)
        event_creation.event_name = event_name
        event_creation.event_status = event_status
        event_creation.event_description = event_description
        event_creation.event_location = event_location
        event_creation.event_season = event_season
        event_creation.event_region = int(event_region)
        event_creation.event_host = int(event_host)
        event_creation.event_boat_rotation_name = event_boat_rotation_name
        event_creation.event_race_number = int(event_race_number)
        event_creation.event_start_date = event_start_date
        event_creation.event_end_date = event_end_date
        event_creation.event_team_number = len(event_school)
        event_creation.event_school_ids = event_school
        event_creation.event_rotation_detail = dict()
        event_creation.save()

        # event tag generation
        for tag in self.EVENT_RACE_TAG:
            event_tag = EventTag()
            event_tag.event_tag_event_id = event_creation.id
            event_tag.event_tag_name = tag
            event_tag.save()
            race_tag_dict[tag] = event_tag.id

        for school_id in event_school:
            # NOTE: Cannot use API here because no permission to get Model.
            school = ModelFunctions.getModelObject(School, id=school_id)
            # summary generation
            summary = Summary()
            summary.summary_event_parent = event_creation.id
            summary.summary_event_school = school_id
            summary.save()

            # team generation
            for index, suffix in enumerate(self.EVENT_TEAM_NAME_SUFFIX):
                team = Team()
                team_name = '{} {}'.format(school.school_default_team_name,
                                           suffix)
                team.team_name = team_name
                team.team_school = school_id
                team.team_status = Team.TEAM_STATUS_ACTIVE
                team.team_tag_id = list(race_tag_dict.values())[index]
                team.save()
                if self.EVENT_RACE_TAG[index] not in team_activity_dict:
                    team_activity_dict[self.EVENT_RACE_TAG[index]] = []
                team_activity_dict[self.EVENT_RACE_TAG[index]].append(team.id)

        for tag, tag_id in race_tag_dict.items():
            for race in range(event_creation.event_race_number):
                # event activity generation
                event_activity = EventActivity()
                event_activity.event_activity_event_parent = event_creation.id
                event_activity.event_activity_event_tag = tag_id
                event_activity.event_activity_name = '{} Race {}'.format(
                    tag, str(race + 1))
                event_activity.event_activity_order = race + 1
                event_activity.event_activity_result = dict()
                event_activity.event_activity_note = ""
                event_activity.event_activity_type = EventActivity.EVENT_ACTIVITY_TYPE_RACE
                event_activity.event_activity_status = Event.EVENT_STATUS_PENDING
                event_activity.save()

                for team_id in team_activity_dict[tag]:
                    # event team link generation
                    event_team = EventTeam()
                    event_team.event_team_event_activity_id = event_activity.id
                    event_team.event_team_id = team_id
                    event_team.save()

        event_creation.event_rotation_detail = self.__rotationGenerator(
            race_tag_dict, team_activity_dict,
            event_creation.event_race_number, event_creation.event_team_number)
        event_creation.save()