예제 #1
0
def squad_rewards_dashboard():
    squad_rewards = RewardsFinder.get_all_squad_rewards()
    rewards = RewardsFinder.get_all_rewards()
    event = EventsFinder.get_default_event()
    if (event is None or event.start_date is None or event.end_date is None):
        return render_template(
            'admin/students_app/rewards/rewards_dashboard.html',
            search=None,
            error='Please select a default event and its date',
            rewards=rewards,
            current_user=current_user)

    event_dates = EventsHandler.get_event_dates(event)

    for squad_reward in squad_rewards:
        if (squad_reward.date not in event_dates):
            RewardsHandler.delete_squad_reward(squad_reward)

    rewards_dates = [squad_reward.date for squad_reward in squad_rewards]

    for date in event_dates:
        if (not date in rewards_dates):
            RewardsHandler.create_squad_reward(reward_id=None, date=date)

    rewards = RewardsFinder.get_all_rewards()
    squad_rewards = RewardsFinder.get_all_squad_rewards()

    return render_template(
        'admin/students_app/rewards/squad_rewards_dashboard.html',
        error=None,
        squad_rewards=squad_rewards,
        rewards=rewards,
        current_user=current_user)
예제 #2
0
def update_level(level_external_id):
    level = LevelsFinder.get_level_from_external_id(level_external_id)
    if level is None:
        return APIErrorValue('Couldnt find level').json(500)

    reward_id = request.form.get('reward', None)
    if (reward_id == ""):
        reward_id = None
    if (reward_id is not None):
        reward = RewardsFinder.get_reward_from_external_id(reward_id)
        if (reward is None):
            return APIErrorValue('Invalid reward Id')

        reward_id = reward.id

    level = LevelsHandler.update_level(level, reward_id=reward_id)
    levels = LevelsFinder.get_all_levels()
    rewards = RewardsFinder.get_all_rewards()
    if (level is None):
        return render_template(
            'admin/students_app/levels/levels_dashboard.html',
            levels=levels,
            rewards=rewards,
            error='Failed to update reward',
            current_user=current_user)

    return render_template('admin/students_app/levels/levels_dashboard.html',
                           levels=levels,
                           rewards=rewards,
                           error=None,
                           current_user=current_user)
예제 #3
0
def update_squad_reward(squad_reward_external_id):
    squad_reward = RewardsFinder.get_squad_reward_from_external_id(
        squad_reward_external_id)
    if squad_reward is None:
        return APIErrorValue('Squad Reward not found').json(404)

    reward_id = request.form.get('reward', None)
    if (reward_id != ""):
        reward = RewardsFinder.get_reward_from_external_id(reward_id)
        if reward is None:
            return APIErrorValue('Reward not found').json(404)

        squad_reward = RewardsHandler.update_squad_reward(squad_reward,
                                                          reward_id=reward.id)
    else:
        squad_reward = RewardsHandler.update_squad_reward(squad_reward,
                                                          reward_id=None)

    if squad_reward is None:
        return render_template(
            'admin/students_app/rewards/squad_rewards_dashboard.html',
            error='Failed to update reward',
            squad_rewards=None,
            rewards=None,
            current_user=current_user)

    return render_template(
        'admin/students_app/rewards/squad_rewards_dashboard.html',
        error=None,
        squad_rewards=RewardsFinder.get_all_squad_rewards(),
        rewards=RewardsFinder.get_all_rewards(),
        current_user=current_user)
예제 #4
0
def jeecpot_reward_dashboard():
    jeecpot_rewards = RewardsFinder.get_all_jeecpot_rewards()
    rewards = RewardsFinder.get_all_rewards()

    if (jeecpot_rewards is None or len(jeecpot_rewards) < 1):
        RewardsHandler.create_jeecpot_reward()
        jeecpot_rewards = RewardsFinder.get_all_jeecpot_rewards()

    return render_template(
        'admin/students_app/rewards/jeecpot_rewards_dashboard.html',
        error=None,
        jeecpot_rewards=jeecpot_rewards[0],
        rewards=rewards,
        current_user=current_user)
예제 #5
0
def create_level():
    value = request.form.get('value', None)
    points = request.form.get('points', None)
    reward_id = request.form.get('reward', None)
    if (reward_id == ""):
        reward_id = None

    if (value is None or points is None):
        return APIErrorValue('Invalid value or points').json(500)

    if (reward_id is not None):
        reward = RewardsFinder.get_reward_from_external_id(reward_id)
        if (reward is None):
            return APIErrorValue('Invalid reward Id')

        reward_id = reward.id

    levels = LevelsFinder.get_all_levels()

    if ((len(levels) > 0 and int(levels[-1].value + 1) != int(value))
            or (len(levels) == 0 and int(value) != 1)):
        return APIErrorValue('Invalid level value').json(500)

    level = LevelsHandler.create_level(value=value,
                                       points=points,
                                       reward_id=reward_id)
    if (level is None):
        return APIErrorValue('Error creating level').json(500)

    if (len(levels) == 0 and level.value == 1):
        students = StudentsFinder.get_from_parameters({'level_id': None})
        for student in students:
            StudentsHandler.update_student(student, level_id=level.id)

    levels = LevelsFinder.get_all_levels()
    rewards = RewardsFinder.get_all_rewards()
    if (levels is None):
        return render_template(
            'admin/students_app/levels/levels_dashboard.html',
            levels=None,
            rewards=rewards,
            error='No levels found',
            current_user=current_user)

    return render_template('admin/students_app/levels/levels_dashboard.html',
                           levels=levels,
                           rewards=rewards,
                           error=None,
                           current_user=current_user)
예제 #6
0
def create_reward():
    name = request.form.get('name', None)
    description = request.form.get('description', None)
    link = request.form.get('link', None)
    quantity = request.form.get('quantity', None)

    reward = RewardsHandler.create_reward(name=name,
                                          description=description,
                                          link=link,
                                          quantity=quantity)
    if (reward is None):
        return render_template('admin/students_app/rewards/add_reward.html',
                               error='Failed to create reward')

    if request.files:
        image = request.files.get('image', None)
        if image:
            result, msg = RewardsHandler.upload_reward_image(
                image, str(reward.external_id))
            if result == False:
                RewardsHandler.delete_reward(reward)
                return render_template(
                    'admin/students_app/rewards/add_reward.html', error=msg)

    return render_template('admin/students_app/rewards/rewards_dashboard.html',
                           search=None,
                           error=None,
                           rewards=RewardsFinder.get_all_rewards(),
                           current_user=current_user)
예제 #7
0
def get_today_squad_reward(student):
    now = datetime.utcnow().strftime('%d %b %Y, %a')

    squad_reward = RewardsFinder.get_squad_reward_from_date(now)

    if (squad_reward is None):
        return RewardsValue(None).json(200)

    return RewardsValue(squad_reward.reward).json(200)
예제 #8
0
def update_reward_dashboard(reward_external_id):
    reward = RewardsFinder.get_reward_from_external_id(reward_external_id)
    if (reward is None):
        redirect(url_for('admin_api.rewards_dashboard'))

    image = RewardsHandler.find_reward_image(str(reward.external_id))

    return render_template('admin/students_app/rewards/update_reward.html',
                           error=None,
                           reward=reward,
                           current_user=current_user,
                           image=image)
예제 #9
0
def delete_reward(reward_external_id):
    reward = RewardsFinder.get_reward_from_external_id(reward_external_id)
    image = RewardsHandler.find_reward_image(str(reward.external_id))

    if RewardsHandler.delete_reward(reward):
        return redirect(url_for('admin_api.rewards_dashboard'))

    else:
        return render_template('admin/students_app/rewards/update_reward.html',
                               reward=reward,
                               image=image,
                               error="Failed to delete reward!")
예제 #10
0
def update_reward(reward_external_id):
    reward = RewardsFinder.get_reward_from_external_id(reward_external_id)
    if (reward is None):
        redirect(url_for('admin_api.rewards_dashboard'))

    name = request.form.get('name', None)
    description = request.form.get('description', None)
    link = request.form.get('link', None)
    quantity = request.form.get('quantity', None)

    reward = RewardsHandler.update_reward(reward,
                                          name=name,
                                          description=description,
                                          link=link,
                                          quantity=quantity)
    image = RewardsHandler.find_reward_image(str(reward.external_id))
    if reward is None:
        return render_template('admin/students_app/rewards/update_reward.html',
                               error='Failed to update reward',
                               reward=reward,
                               image=image)

    if request.files:
        image = request.files.get('image', None)
        if image:
            result, msg = RewardsHandler.upload_reward_image(
                image, str(reward.external_id))
            if result == False:
                RewardsHandler.delete_reward(reward)
                return render_template(
                    'admin/students_app/rewards/update_reward.html',
                    error=msg,
                    reward=reward,
                    image=image)

    return render_template('admin/students_app/rewards/rewards_dashboard.html',
                           search=None,
                           error=None,
                           rewards=RewardsFinder.get_all_rewards(),
                           current_user=current_user)
예제 #11
0
def rewards_dashboard():
    search = request.args.get('search', None)

    if search is not None:
        rewards = RewardsFinder.get_rewards_from_search(search)
    else:
        search = None
        rewards = RewardsFinder.get_all_rewards()

    if (rewards is None or len(rewards) == 0):
        return render_template(
            'admin/students_app/rewards/rewards_dashboard.html',
            search=search,
            error='No rewards found',
            rewards=rewards,
            current_user=current_user)

    return render_template('admin/students_app/rewards/rewards_dashboard.html',
                           search=search,
                           error=None,
                           rewards=rewards,
                           current_user=current_user)
예제 #12
0
def get_activity(activity_external_id):
    activity = ActivitiesFinder.get_from_external_id(activity_external_id)
    companies = CompaniesFinder.get_all()
    speakers = SpeakersFinder.get_all()
    tags = TagsFinder.get_all()
    rewards = RewardsFinder.get_all_rewards()

    event = EventsFinder.get_from_parameters({"default": True})
    if event is None or len(event) == 0:
        error = 'No default event found! Please set a default event in the menu "Events"'
        return render_template('admin/activities/activities_dashboard.html',
                               event=None,
                               error=error,
                               role=current_user.role.name)

    activity_types = event[0].activity_types
    company_activities = ActivitiesFinder.get_company_activities_from_activity_id(
        activity_external_id)
    speaker_activities = ActivitiesFinder.get_speaker_activities_from_activity_id(
        activity_external_id)
    activity_tags = TagsFinder.get_activity_tags_from_activity_id(
        activity_external_id)

    try:
        minDate = datetime.strptime(event[0].start_date,
                                    '%d %b %Y, %a').strftime("%Y,%m,%d")
        maxDate = datetime.strptime(event[0].end_date,
                                    '%d %b %Y, %a').strftime("%Y,%m,%d")
    except:
        minDate = None
        maxDate = None

    companies_zoom_url = {}
    for company in company_activities:
        companies_zoom_url[company.company_id] = company.zoom_link

    return render_template('admin/activities/update_activity.html', \
        activity=activity, \
        activity_types=activity_types, \
        companies=companies, \
        speakers=speakers, \
        tags=tags, \
        rewards=rewards, \
        company_activities=[company.company_id for company in company_activities], \
        speaker_activities=[speaker.speaker_id for speaker in speaker_activities], \
        companies_zoom_url=companies_zoom_url, \
        activity_tags=[tag.tag_id for tag in activity_tags], \
        minDate=minDate, \
        maxDate=maxDate, \
        error=None)
예제 #13
0
def levels_dashboard():
    levels = LevelsFinder.get_all_levels()
    rewards = RewardsFinder.get_all_rewards()
    if (levels is None):
        return render_template(
            'admin/students_app/levels/levels_dashboard.html',
            levels=None,
            rewards=rewards,
            error='No levels found',
            current_user=current_user)

    return render_template('admin/students_app/levels/levels_dashboard.html',
                           levels=levels,
                           rewards=rewards,
                           error=None,
                           current_user=current_user)
예제 #14
0
def select_winners():
    top_squads = SquadsFinder.get_first()
    if top_squads is None:
        return APIErrorValue("No squad found").json(404)

    winner = choice(top_squads)
    now = datetime.utcnow()
    date = now.strftime('%d %b %Y, %a')

    squad_reward = RewardsFinder.get_squad_reward_from_date(date)
    if squad_reward is None:
        return APIErrorValue("No reward found").json(404)

    squad_reward = RewardsHandler.update_squad_reward(squad_reward,
                                                      winner_id=winner.id)
    if squad_reward is None:
        return APIErrorValue("Error selecting winner").json(500)

    return jsonify("Success"), 200
예제 #15
0
def delete_level(level_external_id):
    level = LevelsFinder.get_level_from_external_id(level_external_id)
    if level is None:
        return APIErrorValue('Couldnt find level').json(500)

    levels = LevelsFinder.get_all_levels()
    if (len(levels) == 0 or (len(levels) > 0 and levels[-1] == level)):
        students = StudentsFinder.get_from_level_or_higher(level)
        previous_level = LevelsFinder.get_level_by_value(level.value - 1)

        if (previous_level is None):
            for student in students:
                StudentsHandler.update_student(student,
                                               level_id=None,
                                               total_points=0)
        else:
            for student in students:
                StudentsHandler.update_student(
                    student,
                    level_id=previous_level.id,
                    total_points=previous_level.points)

        LevelsHandler.delete_level(level)

    levels = LevelsFinder.get_all_levels()
    rewards = RewardsFinder.get_all_rewards()
    if (levels is None):
        return render_template(
            'admin/students_app/levels/levels_dashboard.html',
            levels=None,
            rewards=rewards,
            error='No levels found',
            current_user=current_user)

    return render_template('admin/students_app/levels/levels_dashboard.html',
                           levels=levels,
                           rewards=rewards,
                           error=None,
                           current_user=current_user)
예제 #16
0
def add_activity_dashboard():
    companies = CompaniesFinder.get_all()
    speakers = SpeakersFinder.get_all()
    tags = TagsFinder.get_all()
    rewards = RewardsFinder.get_all_rewards()

    event_id = request.args.get('event', None)
    if (event_id is None):
        event = EventsFinder.get_default_event()
    else:
        event = EventsFinder.get_from_external_id(event_id)

    if event is None:
        error = 'No default event found! Please set a default event in the menu "Events"'
        return render_template('admin/activities/activities_dashboard.html',
                               event=None,
                               error=error,
                               role=current_user.role.name)

    try:
        minDate = datetime.strptime(event.start_date,
                                    '%d %b %Y, %a').strftime("%Y,%m,%d")
        maxDate = datetime.strptime(event.end_date,
                                    '%d %b %Y, %a').strftime("%Y,%m,%d")
    except:
        minDate = None
        maxDate = None

    return render_template('admin/activities/add_activity.html', \
        companies=companies, \
        speakers=speakers, \
        tags=tags, \
        minDate=minDate, \
        maxDate=maxDate, \
        event=event, \
        rewards=rewards, \
        error=None)
예제 #17
0
def get_jeecpot_rewards(student):
    jeecpot_rewards = RewardsFinder.get_all_jeecpot_rewards()

    return JeecpotRewardsValue(jeecpot_rewards[0], student).json(200)
예제 #18
0
def update_jeecpot_reward(jeecpot_rewards_external_id):
    jeecpot_rewards = RewardsFinder.get_jeecpot_reward_from_external_id(
        jeecpot_rewards_external_id)
    if (jeecpot_rewards is None):
        return APIErrorValue('JEECPOT Rewards not found').json(500)

    first_student_reward_id = request.form.get('first_student_reward', None)
    if (first_student_reward_id is not None):
        if (first_student_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, first_student_reward_id=None)
        else:
            first_student_reward = RewardsFinder.get_reward_from_external_id(
                first_student_reward_id)
            if (first_student_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                first_student_reward_id=first_student_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    second_student_reward_id = request.form.get('second_student_reward', None)
    if (second_student_reward_id is not None):
        if (second_student_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, second_student_reward_id=None)
        else:
            second_student_reward = RewardsFinder.get_reward_from_external_id(
                second_student_reward_id)
            if (second_student_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                second_student_reward_id=second_student_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    third_student_reward_id = request.form.get('third_student_reward', None)
    if (third_student_reward_id is not None):
        if (third_student_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, third_student_reward_id=None)
        else:
            third_student_reward = RewardsFinder.get_reward_from_external_id(
                third_student_reward_id)
            if (third_student_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                third_student_reward_id=third_student_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    first_squad_reward_id = request.form.get('first_squad_reward', None)
    if (first_squad_reward_id is not None):
        if (first_squad_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, first_squad_reward_id=None)
        else:
            first_squad_reward = RewardsFinder.get_reward_from_external_id(
                first_squad_reward_id)
            if (first_squad_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, first_squad_reward_id=first_squad_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    second_squad_reward_id = request.form.get('second_squad_reward', None)
    if (second_squad_reward_id is not None):
        if (second_squad_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, second_squad_reward_id=None)
        else:
            second_squad_reward = RewardsFinder.get_reward_from_external_id(
                second_squad_reward_id)
            if (second_squad_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, second_squad_reward_id=second_squad_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    third_squad_reward_id = request.form.get('third_squad_reward', None)
    if (third_squad_reward_id is not None):
        if (third_squad_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, third_squad_reward_id=None)
        else:
            third_squad_reward = RewardsFinder.get_reward_from_external_id(
                third_squad_reward_id)
            if (third_squad_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, third_squad_reward_id=third_squad_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    king_job_fair_reward_id = request.form.get('king_job_fair_reward', None)
    if (king_job_fair_reward_id is not None):
        if (king_job_fair_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, king_job_fair_reward_id=None)
        else:
            king_job_fair_reward = RewardsFinder.get_reward_from_external_id(
                king_job_fair_reward_id)
            if (king_job_fair_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                king_job_fair_reward_id=king_job_fair_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    king_knowledge_reward_id = request.form.get('king_knowledge_reward', None)
    if (king_knowledge_reward_id is not None):
        if (king_knowledge_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, king_knowledge_reward_id=None)
        else:
            king_knowledge_reward = RewardsFinder.get_reward_from_external_id(
                king_knowledge_reward_id)
            if (king_knowledge_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                king_knowledge_reward_id=king_knowledge_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    king_hacking_reward_id = request.form.get('king_hacking_reward', None)
    if (king_hacking_reward_id is not None):
        if (king_hacking_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, king_hacking_reward_id=None)
        else:
            king_hacking_reward = RewardsFinder.get_reward_from_external_id(
                king_hacking_reward_id)
            if (king_hacking_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, king_hacking_reward_id=king_hacking_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    king_networking_reward_id = request.form.get('king_networking_reward',
                                                 None)
    if (king_networking_reward_id is not None):
        if (king_networking_reward_id == ""):
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards, king_networking_reward_id=None)
        else:
            king_networking_reward = RewardsFinder.get_reward_from_external_id(
                king_networking_reward_id)
            if (king_networking_reward is None):
                return APIErrorValue('Reward not found').json(404)
            jeecpot_rewards = RewardsHandler.update_jeecpot_reward(
                jeecpot_rewards,
                king_networking_reward_id=king_networking_reward.id)
        if (jeecpot_rewards is None):
            return APIErrorValue('Failed to update reward').json(500)

    return render_template(
        'admin/students_app/rewards/jeecpot_rewards_dashboard.html',
        error=None,
        jeecpot_rewards=jeecpot_rewards,
        rewards=RewardsFinder.get_all_rewards(),
        current_user=current_user)
예제 #19
0
def update_activity(activity_external_id):
    activity = ActivitiesFinder.get_from_external_id(activity_external_id)
    company_activities = ActivitiesFinder.get_company_activities_from_activity_id(
        activity_external_id)
    speaker_activities = ActivitiesFinder.get_speaker_activities_from_activity_id(
        activity_external_id)
    activity_tags = TagsFinder.get_activity_tags_from_activity_id(
        activity_external_id)

    if activity is None:
        return APIErrorValue('Couldnt find activity').json(500)

    name = request.form.get('name')
    description = request.form.get('description')
    location = request.form.get('location')
    day = request.form.get('day')
    time = request.form.get('time')
    end_time = request.form.get('end_time')
    registration_link = request.form.get('registration_link')
    registration_open = request.form.get('registration_open')
    points = request.form.get('points') or None
    quest = request.form.get('quest')
    chat = request.form.get('chat')
    zoom_link = request.form.get('zoom_url')
    reward_id = request.form.get('reward') or None
    moderator = request.form.get('moderator') or None

    if time > end_time is None:
        return APIErrorValue('Activity starting time after ending time').json(
            500)

    if registration_open == 'True':
        registration_open = True
    else:
        registration_open = False

    if quest == 'True':
        quest = True
    else:
        quest = False

    chat_type = ActivityChatEnum[chat] if chat else None

    activity_type_external_id = request.form.get('type')
    activity_type = ActivityTypesFinder.get_from_external_id(
        uuid.UUID(activity_type_external_id))

    updated_activity = ActivitiesHandler.update_activity(
        activity=activity,
        activity_type=activity_type,
        name=name,
        description=description,
        location=location,
        day=day,
        time=time,
        end_time=end_time,
        registration_link=registration_link,
        registration_open=registration_open,
        points=points,
        quest=quest,
        zoom_link=zoom_link,
        chat_type=chat_type,
        chat=(chat == 'general'),
        reward_id=reward_id)

    if company_activities:
        for company_activity in company_activities:
            ActivitiesHandler.delete_company_activities(company_activity)

    if speaker_activities:
        for speaker_activity in speaker_activities:
            ActivitiesHandler.delete_speaker_activities(speaker_activity)

    if activity_tags:
        for activity_tag in activity_tags:
            TagsHandler.delete_activity_tag(activity_tag)

    # extract company names and speaker names from parameters
    companies = request.form.getlist('company')
    zoom_urls = request.form.getlist('url')
    speakers = request.form.getlist('speaker')
    tags = request.form.getlist('tag')

    # if company names where provided
    if companies:
        for index, name in enumerate(companies):
            company = CompaniesFinder.get_from_name(name)
            if company is None:
                return APIErrorValue('Couldnt find company').json(500)

            company_activity = ActivitiesHandler.add_company_activity(
                company, activity, zoom_urls[index])
            if company_activity is None:
                return APIErrorValue('Failed to create company activity').json(
                    500)

            if activity_type.name == 'Job Fair':
                job_fair_booth = ActivityTypesFinder.get_from_name(
                    'Job Fair Booth')
                if not ActivitiesFinder.get_from_parameters(
                    {
                        'name': company.name + " Booth",
                        'day': day
                    }):
                    job_fair_booth_activity = ActivitiesHandler.create_activity(
                        name=company.name + " Booth",
                        description="Visit " + company.name +
                        " booth to earn extra points",
                        activity_type=job_fair_booth,
                        event=activity.event,
                        location="Job Fair",
                        day=day,
                        time='10:30',
                        end_time='16:30',
                        points=40,
                        quest=False)
                    ActivitiesHandler.add_company_activity(
                        company, job_fair_booth_activity)

    if speakers:
        for name in speakers:
            speaker = SpeakersFinder.get_from_name(name)
            if speaker is None:
                return APIErrorValue('Couldnt find speaker').json(500)

            speaker_activity = ActivitiesHandler.add_speaker_activity(
                speaker, activity)
            if speaker_activity is None:
                return APIErrorValue('Failed to create speaker activity').json(
                    500)

        if (moderator and moderator in speakers):
            moderator = SpeakersFinder.get_from_name(moderator)
            if moderator is None:
                return APIErrorValue('Couldnt find moderator').json(500)

            ActivitiesHandler.update_activity(activity,
                                              activity_type,
                                              moderator_id=moderator.id)

        elif (not moderator):
            ActivitiesHandler.update_activity(activity,
                                              activity_type,
                                              moderator_id=None)

    if tags:
        for name in tags:
            tag = TagsFinder.get_by_name(name)
            if tag is None:
                return APIErrorValue('Couldnt find tag').json(500)

            activity_tag = TagsHandler.add_activity_tag(activity, tag)
            if activity_tag is None:
                return APIErrorValue('Failed to create activity tag').json(500)

    if updated_activity is None:
        event = EventsFinder.get_from_parameters({"default": True})

        if event is None or len(event) == 0:
            error = 'No default event found! Please set a default event in the menu "Events"'
            return render_template(
                'admin/activities/activities_dashboard.html',
                event=None,
                error=error,
                role=current_user.role.name)

        activity_types = event[0].activity_types

        try:
            minDate = datetime.strptime(event[0].start_date,
                                        '%d %b %Y, %a').strftime("%Y,%m,%d")
            maxDate = datetime.strptime(event[0].end_date,
                                        '%d %b %Y, %a').strftime("%Y,%m,%d")
        except:
            minDate = None
            maxDate = None

        return render_template('admin/activities/update_activity.html', \
            activity=activity, \
            types=activity_types, \
            companies=CompaniesFinder.get_all(), \
            speakers=SpeakersFinder.get_all(), \
            tags=TagsFinder.get_all(), \
            rewards=RewardsFinder.get_all_rewards(), \
            minDate=minDate, \
            maxDate=maxDate, \
            error="Failed to update activity!")

    return redirect(url_for('admin_api.activities_dashboard'))
예제 #20
0
def get_squads_rewards(student):
    squads_rewards = RewardsFinder.get_all_squad_rewards()

    return SquadsRewardsValue(squads_rewards, student.squad).json(200)