コード例 #1
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def get_chat_room(student):
    company_name = request.args.get('company', None)
    user_id = request.args.get('member', None)

    if company_name:
        company = CompaniesFinder.get_from_name(company_name)
        if company is None:
            return APIErrorValue("Company not found").json(404)

        result = UsersHandler.join_channel(student.user, company.chat_id,
                                           company.chat_code)
        if result:
            return jsonify({'result': True}), 200
        else:
            return APIErrorValue("Failed to join room").json(500)

    elif user_id:
        company_user = UsersFinder.get_from_external_id(user_id)
        if company_user is None and not company_user.role.name == 'company':
            return APIErrorValue("Invalid user").json(500)

        room_id = UsersHandler.create_direct_message(student.user,
                                                     company_user)
        if room_id is None:
            return APIErrorValue(
                "Failed to create direct message session").json(500)

        return jsonify({"room_id": room_id}), 200

    else:
        return APIErrorValue("No room found").json(404)
コード例 #2
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def redeem_code(student):
    try:
        code = request.get_json()["code"].replace("-", "")
    except KeyError:
        return APIErrorValue('Code not inserted').json(500)

    return APIErrorValue('Code submission closed').json(500)
コード例 #3
0
def delete_activity_type(activity_type_external_id):
    activity_type = ActivityTypesFinder.get_from_external_id(
        activity_type_external_id)

    if activity_type.activities:
        for activity in activity_type.activities:
            if activity is None:
                return APIErrorValue('Couldnt find activity').json(500)

            company_activities = ActivitiesFinder.get_company_activities_from_activity_id(
                activity.external_id)
            speaker_activities = ActivitiesFinder.get_speaker_activities_from_activity_id(
                activity.external_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 not ActivitiesHandler.delete_activity(activity):
                return APIErrorValue('Couldnt delete activity').json(500)

    if ActivityTypesHandler.delete_activity_type(activity_type):
        return redirect(url_for('admin_api.activity_types_dashboard'))

    return render_template('admin/activities/update_activity_type.html',
                           activity_type=activity_type,
                           error="Failed to update activity type!")
コード例 #4
0
ファイル: routes.py プロジェクト: pfernandes21/brain
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)
コード例 #5
0
ファイル: routes.py プロジェクト: pfernandes21/brain
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)
コード例 #6
0
def get_speakers():
    search_parameters = request.args.to_dict()
    search_parameters.pop('event', None)
    if 'spotlight' in search_parameters:
        if search_parameters['spotlight'] == 'True':
            search_parameters['spotlight'] = True
        elif search_parameters['spotlight'] == 'False':
            search_parameters['spotlight'] = False

    event_name = request.args.get('event')
    if event_name is None:
        event = EventsFinder.get_default_event()
    else:
        event = EventsFinder.get_from_name(event_name)

    if event is None:
        return APIErrorValue("Event not found!").json(404)

    speakers_list = SpeakersFinder.get_website_speakers(
        event, search_parameters)

    if speakers_list is None:
        return APIErrorValue('No results found').json(400)

    return SpeakersValue(speakers_list).json(200)
コード例 #7
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def get_partner(student):
    name = request.args.get('name', None)
    if name is None:
        return APIErrorValue("Invalid name").json(500)

    company = CompaniesFinder.get_from_name(name)
    if company is None:
        return APIErrorValue('Company not found').json(404)

    return PartnersValue(company, student).json(200)
コード例 #8
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def reset_daily_points():
    squads = SquadsFinder.get_all()
    for squad in squads:
        if not SquadsHandler.reset_daily_points(squad):
            return APIErrorValue("Reset failed").json(500)

    students = StudentsFinder.get_all()
    for student in students:
        if not StudentsHandler.reset_daily_points(student):
            return APIErrorValue("Reset failed").json(500)

    return jsonify("Success"), 200
コード例 #9
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def invite_squad(student):
    if (student.squad is None):
        return APIErrorValue('No squad found').json(401)

    try:
        members = request.get_json()["members"]
    except KeyError:
        return APIErrorValue('Invalid members').json(500)

    if (StudentsHandler.invite_squad_members(student, members)):
        return jsonify('Success'), 200
    else:
        return APIErrorValue('Failed to invite').json(500)
コード例 #10
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def reject_invitation(student):
    try:
        invitation_id = request.get_json()["invitation_id"]
    except KeyError:
        return APIErrorValue('Invalid invitation').json(500)

    invitation = SquadsFinder.get_invitation_from_external_id(invitation_id)
    if (invitation is None):
        return APIErrorValue('Invitation not found').json(404)

    SquadsHandler.delete_squad_invitation(invitation)

    return jsonify('Success'), 200
コード例 #11
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def get_meal(company_user, meal_external_id):
    # get meal
    meal = MealsFinder.get_meal_from_external_id(meal_external_id)

    if meal is None:
        return APIErrorValue('Couldnt find meal').json(400)

    # check if company is allowed in meal
    if company_user.company not in MealsFinder.get_companies_from_meal_id(
            meal.id):
        return APIErrorValue('Company not allowed in this meal').json(400)

    # get company meal
    company_meal = MealsFinder.get_company_meals_from_meal_id_and_company_id(
        meal.id, company_user.company_id)

    if company_meal is None:
        return APIErrorValue('Couldnt find company meal').json(400)

    # get dishes from meal
    dishes = MealsFinder.get_dishes_from_meal_id(meal_external_id)

    # get company dishes
    company_dishes = MealsFinder.get_company_dishes_from_meal_id_and_company_id(
        meal.id, company_user.company_id)

    dish_types = []
    for dish in dishes:
        if (dish.type.name not in dish_types):
            dish_types.append(dish.type.name)

    if dishes is None:
        return render_template('companies/meals/meal.html', \
            meal=meal, \
            max_dish_quantity=None, \
            dish_types=None, \
            dishes=None, \
            company_dishes=None, \
            error='No dishes found.', \
            user=company_user)

    return render_template('companies/meals/meal.html', \
        meal=meal, \
        max_dish_quantity=company_meal.max_dish_quantity, \
        dish_types=dish_types, \
        dishes=dishes, \
        company_dishes=company_dishes, \
        error=None, \
        user=company_user)
コード例 #12
0
def auction_bid(company_user, auction_external_id):
    try:
        value = float(request.form.get('value'))
    except:
        return redirect(
            url_for('companies_api.auction_dashboard',
                    auction_external_id=auction_external_id))

    is_anonymous = request.form.get('is_anonymous')

    if is_anonymous == 'True':
        is_anonymous = True
    else:
        is_anonymous = False

    # get company
    company = CompaniesFinder.get_from_name(company_user.company.name)

    if company is None:
        return APIErrorValue('Couldnt find company').json(400)

    # get auction
    auction = AuctionsFinder.get_auction_by_external_id(auction_external_id)

    if auction is None:
        return APIErrorValue('Couldnt find auction').json(400)

    # get auction highest bid
    highest_bid = AuctionsFinder.get_auction_highest_bid(auction)

    if highest_bid is None:
        highest_bid_value = 0
    else:
        highest_bid_value = highest_bid.value

    # check if value is bigger than current highest bid
    if value <= highest_bid_value or value < auction.minimum_value:
        return redirect(
            url_for('companies_api.auction_dashboard',
                    auction_external_id=auction.external_id))

    AuctionsHandler.create_auction_bid(auction=auction,
                                       company=company,
                                       value=value,
                                       is_anonymous=is_anonymous)

    return redirect(
        url_for('companies_api.auction_dashboard',
                auction_external_id=auction.external_id))
コード例 #13
0
ファイル: routes.py プロジェクト: pfernandes21/brain
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)
コード例 #14
0
def auction_dashboard(company_user, auction_external_id):
    # get auction
    auction = AuctionsFinder.get_auction_by_external_id(auction_external_id)

    if auction is None:
        return APIErrorValue('Couldnt find auction').json(400)

    # check if company is allowed in auction
    if company_user.company not in auction.participants:
        return APIErrorValue('Company not allowed in this auction').json(400)

    # get auction highest bid
    highest_bid = AuctionsFinder.get_auction_highest_bid(auction)
    if highest_bid is None:
        highest_bid = None
        highest_bidder_logo = None
        highest_bidder_name = None
    else:
        # if highest bid is anonymous retrieve anonymous logo
        if highest_bid.is_anonymous is True:
            highest_bidder_logo = '/static/jeec_logo_mobile.svg'
            highest_bidder_name = 'Anonymous bidder'
        else:
            highest_bidder = CompaniesFinder.get_from_id(
                highest_bid.company_id)
            company_logo = CompaniesHandler.find_image(highest_bidder.name)
            highest_bidder_logo = company_logo
            highest_bidder_name = highest_bidder.name

    # get all company bids
    company_bids = AuctionsFinder.get_company_bids(auction,
                                                   company_user.company)

    # get all logos of companies in the auction
    participant_logos = []
    for participant in auction.participants:
        participant_logo = CompaniesHandler.find_image(participant.name)
        participant_logos.append(participant_logo)

    return render_template('companies/auction/auction_dashboard.html', \
        auction=auction, \
        highest_bid=highest_bid, \
        highest_bidder_name=highest_bidder_name, \
        highest_bidder_logo=highest_bidder_logo, \
        company_bids=company_bids, \
        participant_logos=participant_logos, \
        error=None, \
        user=company_user,
        search=None)
コード例 #15
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def ban_squad(squad_external_id):
    squad = SquadsFinder.get_from_external_id(squad_external_id)
    if squad is None:
        return APIErrorValue('Couldnt find squad').json(500)

    for member in squad.members:
        StudentsHandler.leave_squad(member)

        banned_student = StudentsHandler.create_banned_student(member)
        if banned_student is None:
            return APIErrorValue('Error banning student').json(500)

        UsersHandler.delete_user(member.user)

    return redirect(url_for('admin_api.squads_dashboard'))
コード例 #16
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def accept_invitation(student):
    try:
        invitation_id = request.get_json()["invitation_id"]
    except KeyError:
        return APIErrorValue('Invalid invitation').json(500)

    invitation = SquadsFinder.get_invitation_from_external_id(invitation_id)
    if (invitation is None):
        return APIErrorValue('Invitation not found').json(404)

    student = StudentsHandler.accept_invitation(student, invitation)
    if (not student):
        return APIErrorValue("Failed to join squad").json(500)

    return StudentsValue(student, details=True).json(200)
コード例 #17
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def ban_student(student_external_id):
    student = StudentsFinder.get_from_external_id(student_external_id)
    if student is None:
        return APIErrorValue('Couldnt find student').json(500)

    if student.squad:
        SquadsHandler.delete_squad(student.squad)

    banned_student = StudentsHandler.create_banned_student(student)
    if banned_student is None:
        return APIErrorValue('Error banning student').json(500)

    UsersHandler.delete_user(student.user)

    return redirect(url_for('admin_api.students_dashboard'))
コード例 #18
0
def get_activity_type(company_user, activity_type_external_id):
    activity_type = ActivityTypesFinder.get_from_external_id(
        activity_type_external_id)
    if activity_type is None:
        return APIErrorValue("No activity type found").json(404)

    activities = []
    for activity in company_user.company.activities:
        if activity.activity_type == activity_type:
            _activity = dict(
                ActivitiesFinder.get_from_external_id(
                    activity.external_id).__dict__)
            _activity['external_id'] = _activity['external_id'].hex
            _activity.pop('_sa_instance_state')
            _activity.pop('created_at')
            _activity.pop('chat_type')
            activities.append(_activity)

    now = datetime.utcnow()
    today = now.strftime('%d %b %Y, %a')
    for _ in range(len(activities)):
        if activities[0]['day'] == today:
            break
        activities.append(activities.pop(0))

    return render_template('companies/activities/activity_type.html', \
        activities=activities, \
        activity_type=activity_type, \
        error=None, \
        user=company_user)
コード例 #19
0
def delete_code(code):
    code = ActivityCodesFinder.get_from_code(code)
    if code is None:
        return APIErrorValue('Couldnt find code').json(404)

    return jsonify(
        {'success': ActivityCodesHandler.delete_activity_code(code)})
コード例 #20
0
def get_teams():
    search_parameters = request.args
    name = request.args.get('name')

    # handle search bar requests
    if name is not None:
        search = name
        teams_list = TeamsFinder.search_by_name(name)

    # handle parameter requests
    elif len(search_parameters) != 0:
        search_parameters = request.args
        search = 'search name'
        teams_list = TeamsFinder.get_from_parameters(search_parameters)

    # request endpoint with no parameters should return all activities
    else:
        search = None
        teams_list = TeamsFinder.get_all()

    if teams_list is None or len(teams_list) == 0:
        return APIErrorValue('No results found').json(400)

    teams_list.sort(key=lambda x: x.website_priority, reverse=True)

    return TeamsValue(teams_list).json(200)
コード例 #21
0
def delete_meal(meal_external_id):
    meal = MealsFinder.get_meal_from_external_id(meal_external_id)
    company_meals = MealsFinder.get_company_meals_from_meal_id(
        meal_external_id)
    dishes = MealsFinder.get_dishes_from_meal_id(meal_external_id)

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

    if company_meals:
        for company_meal in company_meals:
            MealsHandler.delete_company_meal(company_meal)

    if dishes:
        for dish in dishes:
            company_dishes = MealsFinder.get_company_dishes_from_dish_id(
                dish.id)

            if company_dishes:
                for company_dish in company_dishes:
                    MealsHandler.delete_company_dish(company_dish)

            MealsHandler.delete_dish(dish)

    if MealsHandler.delete_meal(meal):
        return redirect(url_for('admin_api.meals_dashboard'))

    else:
        return render_template('admin/meals/update_meal.html',
                               meal=meal,
                               error="Failed to delete meal!")
コード例 #22
0
def get_job_fair(company_user):
    job_fairs = []
    for activity in ActivitiesFinder.get_current_company_activities(
            company_user.company):
        if activity.activity_type.name == 'Job Fair Booth':
            _activity = dict(
                ActivitiesFinder.get_from_external_id(
                    activity.external_id).__dict__)
            _activity['external_id'] = _activity['external_id'].hex
            _activity.pop('_sa_instance_state')
            _activity.pop('created_at')
            _activity.pop('chat_type')
            job_fairs.append(_activity)

    if len(job_fairs) == 0:
        return APIErrorValue("Job Fair not found").json(404)

    now = datetime.utcnow()
    today = now.strftime('%d %b %Y, %a')
    if today not in [activity['day'] for activity in job_fairs]:
        generate_code = False
    else:
        generate_code = True

    chat_token = UsersHandler.get_chat_user_token(company_user.user)
    chat_url = Config.ROCKET_CHAT_APP_URL + 'home?resumeToken=' + chat_token

    return render_template('companies/activities/job_fair.html', \
        generate_code = generate_code, \
        chat_url = chat_url, \
        job_fairs=job_fairs, \
        error=None, \
        user=company_user)
コード例 #23
0
def delete_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)

    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)

    if ActivitiesHandler.delete_activity(activity):
        return redirect(url_for('admin_api.activities_dashboard'))

    else:
        return render_template('admin/activities/update_activity.html',
                               activity=activity,
                               error="Failed to delete activity!")
コード例 #24
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def kick_member(student):
    if (not student.is_captain()):
        return APIErrorValue('Student is not captain').json(401)

    try:
        member_ist_id = request.get_json()["ist_id"]
    except KeyError:
        return APIErrorValue('Invalid IST id').json(500)

    member = StudentsFinder.get_from_ist_id(member_ist_id)
    if (member is None):
        return APIErrorValue('Member not found').json(404)

    StudentsHandler.leave_squad(member)

    return SquadsValue(student.squad).json(200)
コード例 #25
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def get_chat_token(student):
    token = UsersHandler.get_chat_user_token(student.user)

    if token:
        return jsonify({'token': token}), 200
    else:
        return APIErrorValue("Error getting token").json(500)
コード例 #26
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def delete_tag(student):
    try:
        tag = request.get_json()["tag"]
    except KeyError:
        return APIErrorValue('Invalid tag').json(500)

    tag = TagsFinder.get_by_name(tag)
    if (tag is None):
        return APIErrorValue('Tag not found').json(404)

    student_tag = TagsFinder.get_student_tag(student, tag)
    if (student_tag is None):
        return APIErrorValue('Student tag not found').json(404)

    TagsHandler.delete_student_tag_service(student_tag)

    return StudentsValue(student, details=True).json(200)
コード例 #27
0
def delete_user(user_external_id):
    user = UsersFinder.get_from_external_id(user_external_id)

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

    if user.role.name == 'company':
        company_user = UsersFinder.get_company_user_from_user(user)
        if not company_user:
            return APIErrorValue('Couldnt find user').json(500)

        CompanyUsersHandler.delete_company_user(company_user)

    else:
        UsersHandler.delete_user(user)

    return redirect(url_for('admin_api.users_dashboard'))
コード例 #28
0
def generate_user_credentials(user_external_id):
    user = UsersFinder.get_from_external_id(user_external_id)

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

    UsersHandler.generate_new_user_credentials(user=user)
    return redirect(url_for('admin_api.companies_dashboard'))
コード例 #29
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def delete_company(student):
    try:
        company = request.get_json()["company"]
    except KeyError:
        return APIErrorValue('Invalid company').json(500)

    company = CompaniesFinder.get_from_name(company)
    if (company is None):
        return APIErrorValue('Company not found').json(404)

    student_company = StudentsFinder.get_student_company(student, company)
    if (student_company is None):
        return APIErrorValue('Student company not found').json(404)

    StudentsHandler.delete_student_company(student_company)

    return StudentsValue(student, details=True).json(200)
コード例 #30
0
ファイル: routes.py プロジェクト: pfernandes21/brain
def today_login(student):
    now = datetime.utcnow()
    date = now.strftime('%d %b %Y, %a')
    event = EventsFinder.get_default_event()
    dates = EventsHandler.get_event_dates(event)

    if date in dates:
        student_login = StudentsFinder.get_student_login(student, date)
        if student_login is None:
            StudentsHandler.add_student_login(student, date)
            StudentsHandler.add_points(student, int(Config.REWARD_LOGIN))
        else:
            return APIErrorValue("Already loggedin today").json(409)
    else:
        return APIErrorValue("Date out of event").json(409)

    return StudentsValue(student, details=True).json(200)