Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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!")
Beispiel #5
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)
Beispiel #6
0
    def __init__(self, reward):
        super(RewardsValue, self).initialize({})

        if (reward is not None):
            self.serialize_with(name=reward.name)
            self.serialize_with(image=RewardsHandler.find_reward_image(
                str(reward.external_id)))
        else:
            self.serialize_with(name="")
            self.serialize_with(image="")
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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
Beispiel #10
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)