Exemple #1
0
def add_nugget_post(request):
    user = request.user
    text = request.POST['text']
    tags = request.POST['tags']
    source = request.POST['source']
    logger.info('user %s, text %s, tags %s, source %s' % (user, text, tags, source))
    nugget = Nugget.create_new_nugget(user, text, tags, source)
    return render(request, 'nuggetsapp/add-nugget.html', {'nugget': nugget})
Exemple #2
0
def add_nugget_post(request):
    user = request.user
    text = request.POST['text']
    tags = request.POST['tags']
    source = request.POST['source']
    logger.info('user %s, text %s, tags %s, source %s' %
                (user, text, tags, source))
    nugget = Nugget.create_new_nugget(user, text, tags, source)
    return render(request, 'nuggetsapp/add-nugget.html', {'nugget': nugget})
Exemple #3
0
def nuggets_op_by_user(request, user_id):
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        nuggets = Nugget.get_nuggets_by_user(user)
        serializer = NuggetSerializer(nuggets, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = NuggetSerializer(user, data=request.data)
        if serializer.is_valid():
            Nugget.create_new_nugget(user, serializer.validated_data['text'],
                                     serializer.validated_data['tags'],
                                     serializer.validated_data['source'])
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)