예제 #1
0
    def post(self):
        now = datetime.datetime.now()
        data = request.get_json()

        current_user = get_jwt_identity()

        bucketlist_exists = Bucketlist.query.filter_by(
            name=data.get('name'), created_by=current_user).first()

        if not bucketlist_exists:

            bucketlist = Bucketlist(name=data.get('name'),
                                    created_by=current_user,
                                    date_created=now)
            bucketlist.save()  # Save bucketlist name

            response = jsonify({
                'status': "Success",
                'message': "Bucketlist Created"
            })

            response.status_code = 201

        else:

            response = jsonify({
                'status': "Fail",
                'message': "Bucketlist already exists"
            })

            response.status_code = 409

        return make_response(response)
    def post(self, request, **kwargs):

        name = request.POST.get('name', '')

        if name:
            bucketlist = Bucketlist(name=name,
                                    created_by=request.user.username,
                                    user_id=request.user.id)
            bucketlist.save()
            msg = "Action succesfully performed."
            messages.add_message(request, messages.SUCCESS, msg)
            return HttpResponseRedirect(
                reverse_lazy('mylist',
                             kwargs={
                                 'username': request.user.username,
                             }))

        else:
            msg = "It seems like you didn't add an item."
            messages.add_message(request, messages.INFO, msg)
            return HttpResponseRedirect(
                reverse_lazy('mylist',
                             kwargs={
                                 'username': request.user.username,
                             }))
    def post(self, request):
        '''creates a bucketlist for a user'''

        # validate form
        form = CreateBucketlistForm(request.POST)

        if form.is_valid():
            bucketlist_name = form.cleaned_data['name']

            # create a new bucketlist
            new_bucketlist = Bucketlist(name=bucketlist_name,
                                        created_by=request.user)
            new_bucketlist.save()

            messages.add_message(request,
                                 messages.INFO,
                                 'Bucketlist successfully created.')
        else:
            # send back form errors as messages
            for error in form.errors:
                messages.add_message(request,
                                     messages.ERROR,
                                     form.errors[error])

        return HttpResponseRedirect(reverse('frontend:dashboard'))
예제 #4
0
    def post(self):
        """.. :quickref: Bucketlists Collection; Create a new bucket list.

        .. sourcecode:: http

          POST /bucketlists/1/ HTTP/1.1
          Host: localhost:5000
          Accept: application/json
          Authentication: <token>


        :reqheader Accept: application/json
        :reqheader Authentication: <token>

        :<json string name: bucketlist name


        :resheader Content-Type: application/json
        :status 201: bucketlist created
        :status 422: invalid parameters
        """

        token = request.headers.get('Authorization')
        if token:
            current_user = User.verify_auth_token(token)
        else:
            abort(400, message='Unauthorized Access!')
        if current_user:
            arguments = request.get_json(force=True)
            try:
                name = arguments['name']
            except:
                return {'message': 'Invalid parameter entered'}
            bucketlists = Bucketlist.query.filter_by(
                created_by=current_user.id)
            current_bucketlists = []

            if not name:
                # we return bad request since we require name
                return {'message': 'Missing required parameters.'}, 400
            for bucketlist in bucketlists:
                current_bucketlists.append(bucketlist.name)
            if name not in current_bucketlists:
                new_bucketlist = Bucketlist(name=name,
                                            created_by=current_user.id)
                new_bucketlist.save()

                return {'message': 'successfully added a new bucketlist'}
            return {'message': 'bucketlist already exists'}
        else:
            abort(400, message='Expired or invalid token')
    def post(self, request, **kwargs):

        name = request.POST.get('name', '')

        if name:
            bucketlist = Bucketlist(
                name=name, created_by=request.user.username,
                user_id=request.user.id)
            bucketlist.save()
            msg = "Action succesfully performed."
            messages.add_message(request, messages.SUCCESS, msg)
            return HttpResponseRedirect(reverse_lazy('mylist', kwargs={
                'username': request.user.username, }))

        else:
            msg = "It seems like you didn't add an item."
            messages.add_message(request, messages.INFO, msg)
            return HttpResponseRedirect(reverse_lazy('mylist', kwargs={
                'username': request.user.username, }))