示例#1
0
def update_profile(request):
    if request.method == "PUT":
        profile = get_object_or_404(Profile, user=request.user)
        serializer = ProfileSerializer(profile, data=request.data)
        if serializer.is_valid():
            serializer.save()
            data = serializer.data
            data['username'] = request.user.username
            return Response(data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
def profile_view(request, username):
    try:
        account = Account.objects.get(username=username)
    except Account.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = ProfileSerializer(account)
        return Response(serializer.data)
示例#3
0
def get_profile(request):
    if request.method == "GET":
        profile = get_object_or_404(Profile, user=request.user)
        pr_serializer = ProfileSerializer(profile)
        data = pr_serializer.data
        data['username'] = profile.user.username

        orgs = profile.organizations.all().order_by("name")
        data['orgs'] = [{"org_id": org.id, "org_name": org.name} for org in orgs]
        return Response(data)
示例#4
0
class StatusSerializer(serializers.ModelSerializer):
	profile = ProfileSerializer()
	class Meta:
		model = Status
		fields = [
			'pk',
			'profile',
			'text',
			'timestamp',
		]
示例#5
0
class DesignSerializer(serializers.ModelSerializer):
	profile = ProfileSerializer()
	class Meta:
		model = Design
		fields = [
			'pk',
			'profile',
			'title',
			'image',
			'description',
			'timestamp',
		]
示例#6
0
def api_profile_details(request):
    try:
        prof = Profile.objects.get(pk=request.user.profile.id)
    except Profile.DoesNotExist:
        content = "Profile Does Not Exist !!"
        return Response(content)
        return Response(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        if request.user.profile.id:
            serializer = ProfileSerializer(prof)
            return Response(serializer.data)
        else:
            content = "Error Token"
            return Response(content)
    elif request.method == 'PUT':
        serializer = ProfileSerializer(prof, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#7
0
def profile_create(request):
    serializer = ProfileSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return JsonResponse({'success': True, "data": serializer.data})
    return JsonResponse({'success': False, 'message': "user doesn't exist"})