Esempio n. 1
0
def create():
    if request.method == "GET":
        return render_template("create.html")
    else:

        title = str(request.form.get("title"))
        body = request.form.get("body")
        category = request.form.get("category")
        published_at = str(datetime.utcnow())
        user_id = "samjunior101"

        new_post = Post(title=title,
                        body=body,
                        user_id="samjunior101",
                        category=category)

        data = {
            u'title': title,
            u'body': body,
            u'published_at': published_at,
            u'user_id': user_id,
            u'category': category
        }

        Post.save(data=data)

        return redirect(url_for('index'))
Esempio n. 2
0
def postChallenge():
    data = request.form.to_dict()
    ops = []
    qtype = data['type']
    data['testcases'] = json.loads(data['testcases'])
    lang = langs[data['lang']]
    user = get_jwt_identity()
    if any(bad in data['code'] for bad in lang.invalid):
        ret = ''
        for i in lang.invalid:
            ret += i
        return Response(json.dumps({'success': False, 'err': 'Unsupported functions used.\nCannot use These Functions : '+ret}), mimetype="application/json", status=200)
    else:
        for i, tc in enumerate(data['testcases']):
            op = compile_and_run_code(lang, data['code'], tc)
            if not op['success']:
                if op['timeout']:
                    return Response(json.dumps({'success': False, 'err': 'Time out occured for Case #'+str(i+1)}), mimetype="application/json", status=200)
                else:
                    return Response(json.dumps({'success': False, 'err': 'Error in TestCase #'+str(i+1)+op['err']}), mimetype="application/json", status=200)
            else:
                ops.append(op['output'])

    # return Response(json.dumps({'Success': 'True', 'op': ops}), mimetype="application/json", status=200)
    temp = Post(originalPostBy=user, title=data['title'], qtype=qtype,
                description=data['description'], code=data['code'], testcases=data['testcases'], outputs=ops)
    temp.save()
    User.objects(username=get_jwt_identity()).update_one(push__posts=temp.ID)
    return Response(json.dumps({'success': True, 'link': '/dashboard'}), mimetype="application/json", status=201)
Esempio n. 3
0
def index():
    if current_user.is_authenticated():
        date_string = make_datestring(today())
        try:
            post = Post.objects.get(
                date_string=date_string, owner=current_user.id
            )
        except Post.DoesNotExist:
            post = Post(date_string=date_string, owner=current_user.id)
            post.save()
        return render_template(
            'index.html',
            post=post,
            past_status=past_status(),
            user=current_user
        )
    return render_template('unauth_index.html')
Esempio n. 4
0
def edit(post_id):
    if request.method == "GET":
        post = dictify(Post.get_one(post_id=post_id))
        return render_template("edit.html", post=post)
    else:
        title = str(request.form.get("title"))
        body = request.form.get("body")
        category = request.form.get("category")
        user_id = "samjunior101"

        data = {
            u'title': title,
            u'body': body,
            u'user_id': user_id,
            u'category': category
        }

        Post.save(data=data, post_id=post_id)
        return redirect(url_for("index"))