Beispiel #1
0
def pump_blocs_table():
    for bloc in Bloc.query.all():
        print(bloc.name)

    for bloc in DEFAULT_BLOCS:
        existing_bloc = Bloc.get(name='{} Bloc'.format(bloc))
        if existing_bloc is not None:
            existing_bloc.update(is_default=True)

        Bloc(name='{} Bloc'.format(bloc), is_default=True).save()
Beispiel #2
0
def render_project_creation_page():
    if request.method == 'GET':
        user_id = request.args.get('user_id')

        user = User.get(id=user_id)

        context = {
            'user_id': user_id,
            'blocs': [bloc.as_json() for bloc in user.blocs]
        }

        return render_template('projects/create.html', **context)

    elif request.method == 'POST':
        user_id = request.form['user_id']
        title = request.form['title']
        description = request.form['description']
        weblink = request.form['weblink']
        bloc_name = request.form['bloc_name']

        bloc = Bloc.get(name=bloc_name)

        create_bloc_project(bloc=bloc,
                            user_id=user_id,
                            title=title,
                            description=description,
                            weblink=weblink)

        context = {'scope': 'Project'}

        return render_template('success.html', **context)
Beispiel #3
0
def get_bloc_projects(bloc_uid, page, per_page):
    bloc = Bloc.get(uid=bloc_uid)
    if bloc is None:
        raise errors.ResourceNotFound

    projects = Project.query_for_active(bloc_id=bloc.id, _desc=True)

    page = prep_paginate_query(projects, page=page, per_page=per_page)
    meta = get_pagination_meta(page)

    return page.items, meta
Beispiel #4
0
def get_events_for_bloc(bloc_uid, page, per_page):
    bloc = Bloc.get(uid=bloc_uid)
    if bloc is None:
        raise errors.ResourceNotFound('Bloc not found')

    events_query = Event.query_for_active(bloc_id=bloc.id, _desc=True)

    page = prep_paginate_query(events_query, page=page, per_page=per_page)
    meta = get_pagination_meta(page)

    return page.items, meta
Beispiel #5
0
def get_jobs_for_bloc(bloc_uid, page, per_page):
    bloc = Bloc.get(uid=bloc_uid)
    if bloc is None:
        raise errors.ResourceNotFound('Bloc not found')

    jobs_query = Job.query_for_active(bloc_id=bloc.id).order(bloc.id.desc())

    page = prep_paginate_query(jobs_query, page=page, per_page=per_page)
    meta = get_pagination_meta(page)

    return page.items, meta
Beispiel #6
0
def get_bloc_members(bloc_uid, page, per_page):
    bloc = Bloc.get(uid=bloc_uid)
    if bloc is None:
        raise errors.ResourceNotFound

    bloc_memberships = BlocMembership.query.filter_by(bloc_id=bloc.id)

    paginated_query = prep_paginate_query(
        bloc_memberships, page=page, per_page=per_page)
    meta = get_pagination_meta(paginated_query)

    return page.items, meta
Beispiel #7
0
def add_user_to_bloc(bloc_uid, user_uid):
    bloc = Bloc.get(uid=bloc_uid)
    if bloc is None:
        raise errors.ResourceNotFound

    user = User.get(uid=user_uid)
    if user is None:
        raise errors.ResourceNotFound

    bloc_membership = BlocMembership(bloc_id=bloc.id, user_id=user.id)

    bloc_membership.save()

    return bloc_membership
Beispiel #8
0
def add_bloc_post(user_uid, bloc_uid, title, body, attachment_uids):
    bloc = Bloc.get(uid=bloc_uid)
    if not bloc:
        raise errors.ResourceNotFound

    user = User.get(uid=user_uid)
    if not bloc:
        raise errors.ResourceNotFound

    post = Post(title=title, body=body, user_id=user.id, bloc_id=bloc.id)

    post.save()

    return post
Beispiel #9
0
def render_job_creation_page():
    if request.method == 'GET':
        user_id = request.args.get('user_id')

        user = User.get(id=user_id)

        context = {
            'user_id': user_id,
            'blocs': [bloc.as_json() for bloc in user.blocs],
            'currencies': eval(
                open('static/assets/world_currencies.txt', 'rb').read()
            ),
            'salary_intervals': SALARY_INTERVALS,
            'job_durations': ['SHORT TERM', 'FULL-TIME', 'PART-TIME']
        }

        return render_template('jobs/create.html', **context)

    elif request.method == 'POST':
        title = request.form['title']
        bloc_name = request.form['bloc_name']
        description = request.form['description']
        location = request.form['location']
        duration = request.form['duration']
        min_salary = request.form['min_salary']
        max_salary = request.form['max_salary']
        salary_currency = request.form['salary_currency']
        user_id = request.form['user_id']
        salary_interval = request.form['salary_interval']

        bloc = Bloc.get(name=bloc_name)

        create_job(
            bloc=bloc, title=title, description=description,
            duration=duration, location=location, min_salary=min_salary,
            max_salary=max_salary, salary_interval=salary_interval,
            user_id=user_id, salary_currency=salary_currency
        )

        context = {'scope': 'job'}

        return render_template('success.html', **context)
Beispiel #10
0
def render_event_creation_page():
    if request.method == 'GET':
        user_id = request.args.get('user_id')

        user = User.get(id=user_id)

        context = {
            'user_id': user_id,
            'blocs': [bloc.as_json() for bloc in user.blocs]
        }

        return render_template('events/create.html', **context)

    elif request.method == 'POST':
        title = request.form['title']
        description = request.form['description']
        venue = request.form['venue']
        day_ = request.form['day']
        month_ = request.form['month']
        year_ = request.form['year']
        time_ = request.form['time']
        bloc_name = request.form['bloc_name']
        user_id = request.form['user_id']

        bloc = Bloc.get(name=bloc_name)

        datetime_ = date_parser.parse('{} {} {} {}'.format(
            day_, month_, year_, time_))

        create_event(bloc=bloc,
                     title=title,
                     description=description,
                     venue=venue,
                     datetime=datetime_,
                     created_by_id=user_id)

        context = {'scope': 'event for {}'.format(bloc_name)}
        return render_template('success.html', **context)
Beispiel #11
0
def create_bloc(name, is_private, color, location=None, is_default=False):
    existing_bloc = _check_for_existing_bloc_with_name(name)

    if existing_bloc:
        return

    bloc = Bloc(
        name=name,
        is_private=is_private,
        theme_color=color,
        created_by=g.user.id,
        is_default=is_default
    )

    if location is not None:
        bloc.location_id = location.id

    if is_private:
        bloc.set_invite_code()

    bloc.save()

    return bloc
Beispiel #12
0
def render_bloc_invitation_page(bloc_id):
    bloc = Bloc.get(id=bloc_id)

    return "{} invited you to their Bloc {}".format(
        bloc.created_by.full_name, bloc.name)
Beispiel #13
0
def get_blocs_for_location(location):
    return Bloc.get(location=location)
Beispiel #14
0
def _check_for_existing_bloc_with_name(name):
    normalized_name = _normalize_name(name)

    return Bloc.get(name=normalized_name)
Beispiel #15
0
def add_dummy_user_to_bloc():
    user = User.query_for_active()[0]
    bloc = Bloc.query_for_active()[0]

    BlocMembership(user_id=user.id, bloc_id=bloc.id).save()
Beispiel #16
0
def render_course_creation_page():
    if request.method == 'GET':
        user_id = request.args.get('user_id')

        user = User.get(id=user_id)

        if user.access_token is None:
            dest_url = url_for('web_blueprint.render_course_creation_page',
                               user_id=user_id)

            return redirect(
                url_for('web_blueprint.oauth_login_request',
                        app='Facebook',
                        motive='all courses are taken over Facebook Live',
                        destination=dest_url,
                        login_url=url_for('web_blueprint.oauth_facebook',
                                          user_id=user_id)))

        context = {
            'user_id':
            user_id,
            'blocs': [bloc.as_json() for bloc in user.blocs],
            'timezones': ['GMT', 'PST', 'CAT'],
            'days_of_week': [
                'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
                'Saturday', 'Sunday'
            ]
        }

        return render_template('courses/create.html', **context)

    elif request.method == 'POST':
        request_data = request.form

        title = request_data['title']
        bloc = request_data['bloc_name']
        description = request_data['description']
        time = request_data['time']
        days_of_week = request_data['days_of_week']
        timezone = request_data['timezone']
        start_day = request_data['start_day']
        start_month = request_data['start_month']
        start_year = request_data['start_year']
        end_day = request_data['end_day']
        end_month = request_data['end_month']
        end_year = request_data['end_year']
        user_id = request_data['user_id']
        thumbnail = None  # request_data['thumbnail']

        start_date = date_parser.parse('{} {} {}'.format(
            start_day, start_month, start_year))
        end_date = date_parser.parse('{} {} {}'.format(end_day, end_month,
                                                       end_year))

        bloc = Bloc.get(name=bloc)

        create_course(title=title,
                      description=description,
                      time=time,
                      days_of_week=days_of_week,
                      timezone=timezone,
                      start_date=start_date,
                      end_date=end_date,
                      bloc=bloc,
                      thumbnail=thumbnail,
                      user_id=user_id)

        context = {'scope': 'course'}

        return render_template('success.html', **context)
Beispiel #17
0
def get_bloc_posts(bloc_uid, page, per_page):
    bloc = Bloc.get(uid=bloc_uid)
    if not bloc:
        raise errors.ResourceNotFound