Esempio n. 1
0
def add_company_user_dashboard():
    companies = CompaniesFinder.get_all()

    return render_template('admin/users/add_company_user.html', \
        user = current_user, \
        companies=companies, \
        error=None)
Esempio n. 2
0
def add_meal_dashboard():
    companies = CompaniesFinder.get_all()
    meal_types = GetMealTypesService.call()
    dish_types = GetDishTypesService.call()
    return render_template('admin/meals/add_meal.html', \
        meal_types = meal_types, \
        dish_types = dish_types, \
        companies=companies, \
        error=None)
Esempio n. 3
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)
Esempio n. 4
0
def companies_dashboard():
    companies_list = CompaniesFinder.get_all()

    if len(companies_list) == 0:
        error = 'No results found'
        return render_template('admin/companies/companies_dashboard.html',
                               companies=None,
                               error=error,
                               search=None,
                               role=current_user.role.name)

    return render_template('admin/companies/companies_dashboard.html',
                           companies=companies_list,
                           error=None,
                           search=None,
                           role=current_user.role.name)
Esempio n. 5
0
def get_meal(meal_external_id):
    meal = MealsFinder.get_meal_from_external_id(meal_external_id)
    companies = CompaniesFinder.get_all()
    meal_types = GetMealTypesService.call()
    dish_types = GetDishTypesService.call()
    company_meals = MealsFinder.get_company_meals_from_meal_id(
        meal_external_id)
    dishes = MealsFinder.get_dishes_from_meal_id(meal_external_id)

    return render_template('admin/meals/update_meal.html', \
        meal=meal, \
        meal_types=meal_types, \
        dish_types=dish_types, \
        companies=companies, \
        company_meals=[company.company_id for company in company_meals], \
        dishes=dishes, \
        error=None)
Esempio n. 6
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)
Esempio n. 7
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'))
Esempio n. 8
0
def create_user():
    # extract form parameters
    name = request.form.get('name')
    username = request.form.get('username')
    email = request.form.get('email', None)
    role = request.form.get('role', None)
    post = request.form.get('post', None)
    evf_username = request.form.get('evf_username', None)
    evf_password = request.form.get('evf_password', None)

    # check if is creating company user
    company_external_id = request.form.get('company_external_id')
    if company_external_id is not None:
        company = CompaniesFinder.get_from_external_id(company_external_id)
        company_id = company.id

        if company is None:
            return 'No company found', 404

    # extract food_manager from parameters
    food_manager = request.form.get('food_manager', None)

    if food_manager == 'True':
        food_manager = True
    elif food_manager == 'False':
        food_manager = False
    else:
        food_manager = None

    # create new company user
    if company_external_id:
        company_user = CompanyUsersHandler.create_company_user(
            name, username, email, company_id, post, food_manager,
            evf_username, evf_password)
        if not company_user:
            return render_template('admin/users/add_company_user.html', \
                    user=current_user, \
                    companies=CompaniesFinder.get_all(), \
                    roles=GetRolesService.call(), \
                    error="Failed to create user!")

        if not UsersHandler.join_channel(company_user.user, company.chat_id,
                                         company.chat_code):
            CompanyUsersHandler.delete_company_user(company_user)
            return render_template('admin/users/add_company_user.html', \
                    user=current_user, \
                    companies=CompaniesFinder.get_all(), \
                    roles=GetRolesService.call(), \
                    error="Failed to create user!")

        for activity in company_user.company.activities:
            if activity.chat_id:
                if not ActivitiesHandler.join_channel(company_user.user,
                                                      activity):
                    CompanyUsersHandler.delete_company_user(company_user)
                    return render_template('admin/users/add_company_user.html', \
                        user=current_user, \
                        companies=CompaniesFinder.get_all(), \
                        roles=GetRolesService.call(), \
                        error="Failed to create user!")

    else:
        if role not in GetRolesService.call():
            return 'Wrong role type provided', 404
        else:
            role = RolesEnum[role]

        user = UsersHandler.create_user(
            name=name,
            username=username,
            email=email,
            role=role,
            password=GenerateCredentialsService().call())

        if user is None:
            return render_template('admin/users/add_user.html', \
                roles=GetRolesService.call(), \
                error="Failed to create user!")

    return redirect(url_for('admin_api.users_dashboard'))
Esempio n. 9
0
def create_meal():
    # extract form parameters
    meal_type = request.form.get('type')
    location = request.form.get('location')
    day = request.form.get('day')
    time = request.form.get('time')
    registration_day = request.form.get('registration_day')
    registration_time = request.form.get('registration_time')

    if meal_type not in GetMealTypesService.call():
        return 'Wrong meal type provided', 404
    else:
        meal_type = MealTypeEnum[meal_type]

    # create new meal
    meal = MealsHandler.create_meal(type=meal_type,
                                    location=location,
                                    day=day,
                                    time=time,
                                    registration_day=registration_day,
                                    registration_time=registration_time)

    if meal is None:
        return render_template('admin/meals/add_meal.html', \
            type=meal_type, \
            companies=CompaniesFinder.get_all(), \
            error="Failed to create meal!")

    # extract company names and max dish quantities from parameters
    companies = request.form.getlist('company')
    max_dish_quantities = request.form.getlist('max_dish_quantity')

    # 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)

            try:
                max_dish_quantity = int(max_dish_quantities[index])
            except:
                max_dish_quantity = None

            company_meal = MealsHandler.add_company_meal(
                company, meal, max_dish_quantity)
            if company_meal is None:
                return APIErrorValue('Failed to create company meal').json(500)

    # extract dish names and descriptions from parameters
    dish_names = request.form.getlist('dish_name')
    dish_descriptions = request.form.getlist('dish_description')
    dish_types = request.form.getlist('dish_type')

    # if dishes names where provided
    if dish_names:
        for index, name in enumerate(dish_names):
            if not name:
                continue

            try:
                dish_description = dish_descriptions[index]
            except:
                dish_description = None

            try:
                dish_type = dish_types[index]
            except:
                dish_type = None

            if dish_type not in GetDishTypesService.call():
                return 'Wrong dish type provided', 404
            else:
                dish_type = DishTypeEnum[dish_type]

            meal_dish = MealsHandler.create_dish(name=name,
                                                 description=dish_description,
                                                 meal_id=meal.id,
                                                 type=dish_type)
            if meal_dish is None:
                return APIErrorValue('Failed to create dish').json(500)

    return redirect(url_for('admin_api.meals_dashboard'))
Esempio n. 10
0
def update_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)

    # extract form parameters
    meal_type = request.form.get('type')
    location = request.form.get('location')
    day = request.form.get('day')
    time = request.form.get('time')
    registration_day = request.form.get('registration_day')
    registration_time = request.form.get('registration_time')

    if meal_type not in GetMealTypesService.call():
        return 'Wrong meal type provided', 404
    else:
        meal_type = MealTypeEnum[meal_type]

    updated_meal = MealsHandler.update_meal(
        meal=meal,
        type=meal_type,
        location=location,
        day=day,
        time=time,
        registration_day=registration_day,
        registration_time=registration_time)

    previous_companies = [
        company_meal.company_id for company_meal in company_meals
    ]

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

    # extract company names and max dish quantities from parameters
    companies = request.form.getlist('company')
    max_dish_quantities = request.form.getlist('max_dish_quantity')

    updated_companies = []

    # 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)

            updated_companies.append(company.id)

            try:
                max_dish_quantity = max_dish_quantities[index]
            except:
                max_dish_quantity = None

            company_meal = MealsHandler.add_company_meal(
                company, meal, max_dish_quantity)
            if company_meal is None:
                return APIErrorValue('Failed to create company meal').json(500)

    # delete dishes from deleted companies
    for company_id in previous_companies:
        if company_id not in updated_companies:
            company_dishes = MealsFinder.get_company_dishes_from_meal_id_and_company_id(
                meal.id, company_id)

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

    # extract dish names and descriptions from parameters
    dish_names = request.form.getlist('dish_name')
    dish_descriptions = request.form.getlist('dish_description')
    dish_types = request.form.getlist('dish_type')

    previous_dish_names = [dish.name for dish in dishes]
    previous_dish_descriptions = [dish.description for dish in dishes]
    previous_dish_types = [dish.type for dish in dishes]

    updated_dishes = []

    # if dishes names where provided
    if dish_names:
        for index, name in enumerate(dish_names):
            if not name:
                continue

            try:
                dish_description = dish_descriptions[index]
            except:
                pass

            try:
                dish_type = dish_types[index]
            except:
                dish_type = None

            if dish_type not in GetDishTypesService.call():
                return 'Wrong dish type provided', 404
            else:
                dish_type = DishTypeEnum[dish_type]

            #if dish name already exists
            if name in previous_dish_names:
                #if dish already exists do nothing
                if dish_description == previous_dish_descriptions[
                        previous_dish_names.index(
                            name)] and dish_type == previous_dish_types[
                                previous_dish_names.index(name)]:
                    updated_dishes.append(
                        dishes[previous_dish_names.index(name)])
                    continue

                #if descrition or type is changed, update it
                updated_dish = MealsHandler.update_dish(
                    dish=dishes[previous_dish_names.index(name)],
                    name=name,
                    description=dish_description,
                    meal_id=meal.id,
                    type=dish_type)
                if updated_dish is None:
                    return APIErrorValue('Failed to update dish').json(500)

                updated_dishes.append(updated_dish)
                continue

            #if dish doesnt exist, create it
            created_dish = MealsHandler.create_dish(
                name=name,
                description=dish_description,
                meal_id=meal.id,
                type=dish_type)

            if created_dish is None:
                return APIErrorValue('Failed to create dish').json(500)

    #delete non updated dishes
    if dishes:
        for dish in dishes:
            if (dish in updated_dishes):
                continue

            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 updated_meal is None:
        return render_template('admin/meals/update_meal.html', \
            meal=meal, \
            types=GetMealTypesService.call(), \
            companies=CompaniesFinder.get_all(), \
            error="Failed to update meal!")

    return redirect(url_for('admin_api.meals_dashboard'))