Ejemplo n.º 1
0
 def post(self, request):
     name = request.POST.get("name")
     url = request.POST.get("imgURL")
     caption = request.POST.get("caption")
     post = Post(imgURL=url, caption=caption, postedBy=name)
     post.save()
     return HttpResponseRedirect("/")
Ejemplo n.º 2
0
    def post(self):
        try:
            user_id = get_jwt_identity()
            user = User.objects.get(id=user_id)

            body = {
                'title': request.form['title'],
                'content': request.form['content'],
                'hashtags': request.form.getlist('hashtags[]')
            }
            post = Post(**body, author=user)
            post.save()

            if request.files and 'file' in request.files:
                file = request.files['file']
                filename = str(post.id) + file.filename

                if save_file(filename, file):
                    post.update(set__image=filename)

            socketio.emit('update', {}, room='mentor' + str(user.id))

            return {'id': str(post.id)}, 200
        except (FieldDoesNotExist, ValidationError):
            raise SchemaValidationError
        except DoesNotExist:
            raise DocumentMissing
        except Exception as e:
            raise InternalServerError
Ejemplo n.º 3
0
 def post(self, request):
     if request.user.is_authenticated:
         title = request.POST.get("title")
         body = request.POST.get("body")
         name = request.user.username
         post = Post(title=title, body=body, postedBy=name, type="txt")
         post.save()
         return HttpResponseRedirect("/")
     return HttpResponseRedirect("/accounts/login")
Ejemplo n.º 4
0
 def post(self, request):
     if request.user.is_authenticated:
         title = request.POST.get("title")
         url = request.POST.get("url")
         name = request.user.username
         post = Post(title=title, url=url, postedBy=name, type="lnk")
         post.save()
         return HttpResponseRedirect("/")
     return HttpResponseRedirect("/accounts/login")
Ejemplo n.º 5
0
def notice_submit(request):
    if request.method == 'POST':
        title=request.POST['title']
        body=request.POST['body']
        date=datetime.datetime.now()

        new_notice = Post(title=title,body=body,date=date)
        new_notice.save()
        messages.success(request, "Success ! You are done !")
        return HttpResponseRedirect("/")
Ejemplo n.º 6
0
 def post(self):
     user_id = get_jwt_identity()
     body = request.get_json()
     user = User.objects.get(id=user_id)
     post = Post(**body, author=user)
     post.save()
     #user.update(push__post=post)
     user.save()
     id = post.id
     return {'id': str(id)}, 200
Ejemplo n.º 7
0
def addpost(req):
    # print(req.user.)
    if not req.user.is_authenticated:
        return Http404()
    data = req.body.decode('utf8')
    data = json.loads(data)
    title = data.get('title')
    content = data.get('content')
    reply = Post(by = req.user, title = title, content = content)
    reply.save()
    return JsonResponse({'status' : True})