示例#1
0
    def __init__(self, events):
        super(EventsValue, self).initialize({})

        if (not isinstance(events, list)):
            events = [events]

        events_array = []
        for event in events:

            event_value = {
                "name":
                event.name,
                "start_date":
                event.start_date,
                "end_date":
                event.end_date,
                "email":
                event.email,
                "location":
                event.location,
                "facebook_link":
                event.facebook_link,
                "facebook_event_link":
                event.facebook_event_link,
                "youtube_link":
                event.youtube_link,
                "instagram_link":
                event.instagram_link,
                "logo":
                EventsHandler.find_image(str(event.external_id)),
                "mobile_logo":
                EventsHandler.find_image(f'{event.external_id}_mobile'),
                "schedule":
                EventsHandler.find_image(f'{event.external_id}_schedule'),
                "blueprint":
                EventsHandler.find_image(f'{event.external_id}_blueprint'),
                "activity_types":
                ActivityTypesValue(
                    ActivityTypesFinder.get_from_parameters({
                        'event_id':
                        event.id,
                        'show_in_schedule':
                        True
                    })).to_dict(),
                "dates":
                EventsHandler.get_event_dates(event),
                "show_schedule":
                event.show_schedule,
                "show_registrations":
                event.show_registrations
            }
            events_array.append(event_value)
        self.serialize_with(data=events_array)

        if (len(events_array) == 1):
            self.serialize_with(data=events_array[0])
        else:
            self.serialize_with(data=events_array)
示例#2
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)
示例#3
0
def get_event(event_external_id):
    event = EventsFinder.get_from_external_id(event_external_id)

    if event is None:
        return render_template(url_for('admin_api.add_event_dashboard'))

    logo = EventsHandler.find_image(image_name=str(event.external_id))
    mobile_image_name = f'{event.external_id}_mobile'
    logo_mobile = EventsHandler.find_image(image_name=mobile_image_name)
    schedule_name = f'{event.external_id}_schedule'
    schedule = EventsHandler.find_image(image_name=schedule_name)
    blueprint_name = f'{event.external_id}_blueprint'
    blueprint = EventsHandler.find_image(image_name=blueprint_name)

    return render_template('admin/events/update_event.html',
                           event=event,
                           logo=logo,
                           logo_mobile=logo_mobile,
                           schedule=schedule,
                           blueprint=blueprint,
                           error=None)
示例#4
0
def dashboard():
    event = EventsFinder.get_default_event()
    if (event is None):
        return render_template('admin/dashboard.html',
                               event=None,
                               logo=None,
                               user=current_user)

    logo = EventsHandler.find_image(image_name=str(event.external_id))
    return render_template('admin/dashboard.html',
                           event=event,
                           logo=logo,
                           user=current_user)
示例#5
0
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)
示例#6
0
def create_event():
    name = request.form.get('name')
    start_date = request.form.get('start_date')
    end_date = request.form.get('end_date')
    cvs_submission_start = request.form.get('cvs_submission_start')
    cvs_submission_end = request.form.get('cvs_submission_end')
    cvs_access_start = request.form.get('cvs_access_start')
    cvs_access_end = request.form.get('cvs_access_end')
    email = request.form.get('email')
    location = request.form.get('location')
    default = request.form.get('default')
    facebook_event_link = request.form.get('facebook_event_link')
    facebook_link = request.form.get('facebook_link')
    youtube_link = request.form.get('youtube_link')
    instagram_link = request.form.get('instagram_link')
    show_schedule = request.form.get('show_schedule')
    show_registrations = request.form.get('show_registrations')

    if default == 'True':
        default = True
    else:
        default = False

    if show_schedule == 'True':
        show_schedule = True
    else:
        show_schedule = False

    if show_registrations == 'True':
        show_registrations = True
    else:
        show_registrations = False

    event = EventsHandler.create_event(
        name=name,
        start_date=start_date,
        end_date=end_date,
        default=default,
        email=email,
        location=location,
        facebook_link=facebook_link,
        facebook_event_link=facebook_event_link,
        youtube_link=youtube_link,
        instagram_link=instagram_link,
        show_schedule=show_schedule,
        show_registrations=show_registrations,
        cvs_submission_start=cvs_submission_start,
        cvs_submission_end=cvs_submission_end,
        cvs_access_start=cvs_access_start,
        cvs_access_end=cvs_access_end)

    if event is None:
        return render_template('admin/events/add_event.html',
                               error="Failed to create event!")

    # there can only be one default
    if default:
        default_events = EventsFinder.get_from_parameters({"default": True})
        for default_event in default_events:
            if default_event is not event:
                EventsHandler.update_event(event=default_event, default=False)

    if request.files:
        image_file = request.files.get('event_image', None)
        mobile_image_file = request.files.get('event_mobile_image', None)
        blueprint_file = request.files.get('event_blueprint', None)
        schedule_file = request.files.get('event_schedule', None)

        if image_file:
            result, msg = EventsHandler.upload_image(image_file,
                                                     str(event.external_id))

            if result == False:
                EventsHandler.delete_event(event)
                return render_template('admin/events/add_event.html',
                                       error=msg)

        if mobile_image_file:
            image_name = f'{event.external_id}_mobile'
            result, msg = EventsHandler.upload_image(mobile_image_file,
                                                     image_name)

            if result == False:
                EventsHandler.delete_event(event)
                return render_template('admin/events/add_event.html',
                                       error=msg)

        if blueprint_file:
            image_name = f'{event.external_id}_blueprint'
            result, msg = EventsHandler.upload_image(blueprint_file,
                                                     image_name)

            if result == False:
                EventsHandler.delete_event(event)
                return render_template('admin/events/add_event.html',
                                       error=msg)

        if schedule_file:
            image_name = f'{event.external_id}_schedule'
            result, msg = EventsHandler.upload_image(blueprint_file,
                                                     image_name)

            if result == False:
                EventsHandler.delete_event(event)
                return render_template('admin/events/add_event.html',
                                       error=msg)

    return redirect(url_for('admin_api.events_dashboard'))
示例#7
0
def update_event(event_external_id):
    event = EventsFinder.get_from_external_id(event_external_id)
    if event is None:
        return APIErrorValue('Couldnt find event').json(500)

    name = request.form.get('name')
    start_date = request.form.get('start_date')
    end_date = request.form.get('end_date')
    cvs_submission_start = request.form.get('cvs_submission_start')
    cvs_submission_end = request.form.get('cvs_submission_end')
    cvs_access_start = request.form.get('cvs_access_start')
    cvs_access_end = request.form.get('cvs_access_end')
    default = request.form.get('default')
    email = request.form.get('email')
    location = request.form.get('location')
    facebook_event_link = request.form.get('facebook_event_link')
    facebook_link = request.form.get('facebook_link')
    youtube_link = request.form.get('youtube_link')
    instagram_link = request.form.get('instagram_link')
    show_schedule = request.form.get('show_schedule')
    show_registrations = request.form.get('show_registrations')

    if default == 'True':
        default = True
    else:
        default = False

    if show_schedule == 'True':
        show_schedule = True
    else:
        show_schedule = False

    if show_registrations == 'True':
        show_registrations = True
    else:
        show_registrations = False

    updated_event = EventsHandler.update_event(
        event=event,
        name=name,
        start_date=start_date,
        end_date=end_date,
        default=default,
        email=email,
        location=location,
        facebook_link=facebook_link,
        facebook_event_link=facebook_event_link,
        youtube_link=youtube_link,
        instagram_link=instagram_link,
        show_schedule=show_schedule,
        show_registrations=show_registrations,
        cvs_submission_start=cvs_submission_start,
        cvs_submission_end=cvs_submission_end,
        cvs_access_start=cvs_access_start,
        cvs_access_end=cvs_access_end)

    logo = EventsHandler.find_image(image_name=str(event.external_id))
    mobile_image_name = f'{event.external_id}_mobile'
    logo_mobile = EventsHandler.find_image(image_name=mobile_image_name)
    schedule_name = f'{event.external_id}_schedule'
    schedule = EventsHandler.find_image(image_name=schedule_name)
    blueprint_name = f'{event.external_id}_blueprint'
    blueprint = EventsHandler.find_image(image_name=blueprint_name)

    if updated_event is None:
        return render_template('admin/events/update_event.html',
                               event=event,
                               logo=logo,
                               logo_mobile=logo_mobile,
                               schedule=schedule,
                               blueprint=blueprint,
                               error=msg)

    # there can only be one default
    if default:
        default_events = EventsFinder.get_from_parameters({"default": True})
        for default_event in default_events:
            if default_event is not updated_event:
                EventsHandler.update_event(event=default_event, default=False)

    current_app.logger.error(request.files)

    if request.files:
        image_file = request.files.get('event_image', None)
        mobile_image_file = request.files.get('event_mobile_image', None)
        blueprint_file = request.files.get('event_blueprint', None)
        schedule_file = request.files.get('event_schedule', None)

        if image_file:
            result, msg = EventsHandler.upload_image(
                image_file, str(updated_event.external_id))
            if result == False:
                return render_template('admin/events/update_event.html',
                                       event=event,
                                       logo=logo,
                                       logo_mobile=logo_mobile,
                                       schedule=schedule,
                                       blueprint=blueprint,
                                       error=msg)

        if mobile_image_file:
            image_name = f'{updated_event.external_id}_mobile'
            result, msg = EventsHandler.upload_image(mobile_image_file,
                                                     image_name)
            if result == False:
                return render_template('admin/events/update_event.html',
                                       event=event,
                                       logo=logo,
                                       logo_mobile=logo_mobile,
                                       schedule=schedule,
                                       blueprint=blueprint,
                                       error=msg)

        if blueprint_file:
            image_name = f'{updated_event.external_id}_blueprint'
            result, msg = EventsHandler.upload_image(blueprint_file,
                                                     image_name)
            if result == False:
                return render_template('admin/events/update_event.html',
                                       event=event,
                                       logo=logo,
                                       logo_mobile=logo_mobile,
                                       schedule=schedule,
                                       blueprint=blueprint,
                                       error=msg)

        if schedule_file:
            image_name = f'{updated_event.external_id}_schedule'
            result, msg = EventsHandler.upload_image(schedule_file, image_name)
            if result == False:
                return render_template('admin/events/update_event.html',
                                       event=event,
                                       logo=logo,
                                       logo_mobile=logo_mobile,
                                       schedule=schedule,
                                       blueprint=blueprint,
                                       error=msg)

    return redirect(url_for('admin_api.events_dashboard'))
示例#8
0
def get_activity_dates(student):
    event = EventsFinder.get_default_event()
    dates = EventsHandler.get_event_dates(event)

    return jsonify(dates)