예제 #1
0
def create_event(bloc, title, description, venue, datetime, created_by_id):
    event = Event(title=title,
                  description=description,
                  venue=venue,
                  datetime=datetime,
                  created_by_id=created_by_id,
                  bloc_id=bloc.id)

    event.save()

    event_creation_text = (
        "Hey everyone! Y'all could join me at {venue} on {date}.\nThat's if "
        "you don't want to miss out on {title}, anyways.\n\n#Blocs #{bloc}".
        format(venue=event.venue,
               date=event.humane_date,
               title=event.title,
               bloc=event.bloc.name))

    url = url_for('web_blueprint.render_event_details',
                  event_id=event.id,
                  _external=True)

    user = User.get(id=created_by_id)
    # publish_post(user.access_token, event_creation_text, url=url)

    return event
예제 #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)
예제 #3
0
def add_course_to_offered(course_id):
    user = User.get(id=g.user.id)

    courses_offered = loads(user.courses_offered)
    courses_offered.append(course_id)

    user.update(courses_offered=dumps(courses_offered))
예제 #4
0
def render_bloc_creation_page():
    if request.method == 'GET':
        user_id = request.args.get('user_id')

        user = User.get(id=user_id)

        context = {
            'user_id': g.user.id,
            'blocs': [bloc.as_json() for bloc in user.blocs]
        }
        return render_template('blocs/create.html', **context)

    elif request.method == 'POST':
        name = request.form['name']
        is_private = bool(request.form['is_private'])
        color = request.form['color']

        bloc = create_bloc(name=name, is_private=is_private, color=color)

        context = {'scope': 'Bloc'}
        if is_private:
            context['subtext'] = 'Invite code: <b>{}</b>'.format(
                bloc.invite_code)

        return render_template('success.html', **context)
예제 #5
0
def render_declare_event_interest_page(event_id):
    user_id = request.args.get('user_id')

    g.user = User.get(id=user_id)

    declare_event_interest(event_id)

    return render_template('success.html')
예제 #6
0
    def get(self):
        code = request.args.get('code')

        redirect_url = url_for(
            'web_blueprint.oauth_facebook', _external=True)

        if code is None:
            user_id = request.args.get('user_id')

            graph = facebook.GraphAPI(PAGE_ACCESS_TOKEN)

            fb_login_url = graph.get_auth_url(
                FACEBOOK_APP_ID, redirect_url, REQUIRED_PERMISSIONS,
                state=user_id
            )

            return redirect(fb_login_url)

        else:
            user_id = request.args.get('state')

            params = {
                'client_id': FACEBOOK_APP_ID,
                'redirect_uri': redirect_url,
                'client_secret': FACEBOOK_APP_SECRET,
                'code': code
            }

            response = requests.get(
                'https://graph.facebook.com/v3.0/oauth/access_token',
                params=params
            ).content.decode()

            # {"access_token":
            #      "EAAGTzHZCz6UQBAL4ziJ7zcVbSgsuUeqi5lkgl6cWcCpMBpXD3aScni7O1Wuu"
            #      "7ux5nZC7XCJYox9guGZCijBCZAjsZBHZCNibwZAieaYda7XctcPZBgR9WHFiv"
            #      "EBgcqpwLZAJvtJ3EWCup0nIb0nUbiMBuB5bQqwKuk7KSaViWzVvW1AZDZD",
            #  "token_type": "bearer", "expires_in": 5178778}

            response_data = loads(response)

            # print(response_data)

            access_token = response_data['access_token']

            user = User.get(id=user_id)
            user.update(access_token=access_token)

            destination = session.pop('destination')
            if destination:
                return redirect(destination)

            return redirect(
                url_for('web_blueprint.render_success_page'))
예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #11
0
def get_user_access_token(app, external_app_uid):
    user = User.get(external_app_uid=external_app_uid)

    return user.access_token
예제 #12
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)