Beispiel #1
0
    def update(self, request, id):
        try:
            user = DropboxToken.objects.get(id=id)
        except DropboxToken.DoesNotExist:
            return rc.NOT_FOUND

        form = DropboxTokenForm(request.PUT, request.FILES, instance=user)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            return user
        else:
            return form.errors
Beispiel #2
0
    def create(self, request):
        instance = User()
        form = DropboxTokenForm(request.POST, request.FILES, instance=instance)

        if form.is_valid():
            form_dropbox_data = form.save(commit=False)

            if DropboxToken.objects.filter(user=form_dropbox_data.user).exists():
                dropbox_token = DropboxToken.objects.get(user=form_dropbox_data.user)
                dropbox_token.password = form_dropbox_data.password
                dropbox_token.save()

            else:
                dropbox_token = form_dropbox_data

            return dropbox_token

        else:
            return form.errors