diff --git a/commis/cookbooks/models.py b/commis/cookbooks/models.py index eedbc0a..5763c81 100644 --- a/commis/cookbooks/models.py +++ b/commis/cookbooks/models.py @@ -35,18 +35,21 @@ def from_dict(self, data): cookbook.recipes.create(name=name, description=description) for type, label in CookbookFile.TYPES: for file_info in data.get(type, []): + new_content = False try: - cookbook_file = cookbook.files.get(type=type, file__checksum=file_info['checksum']) + cookbook_file = cookbook.files.get(type=type, path=file_info["path"]) except CookbookFile.DoesNotExist: + cookbook_file = cookbook.files.create(type=type, path=file_info["path"]) + new_content = True + else: + if cookbook_file.file.checksum != file_info["checksum"]: + new_content = True + if new_content: try: - file = SandboxFile.objects.get(checksum=file_info['checksum']) + cookbook_file.file = SandboxFile.objects.get(checksum=file_info['checksum'], uploaded=True) except SandboxFile.DoesNotExist: raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum']) - if not file.uploaded: - raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum']) - cookbook_file = cookbook.files.create(type=type, file=file) cookbook_file.name = file_info['name'] - cookbook_file.path = file_info['path'] cookbook_file.specificity = file_info['specificity'] cookbook_file.save() cookbook.save() diff --git a/commis/data_bags/views.py b/commis/data_bags/views.py index c9fb27c..9b5aac1 100644 --- a/commis/data_bags/views.py +++ b/commis/data_bags/views.py @@ -11,6 +11,7 @@ from commis.data_bags.forms import DataBagForm, DataBagItemForm from commis.data_bags.models import DataBag, DataBagItem from commis.db import update +from commis.utils import json class DataBagAPIView(CommisAPIView): model = DataBag @@ -49,10 +50,13 @@ def item_get(self, request, bag_name, name): def item_update(self, request, bag_name, name): if not request.json: raise ChefAPIError(500, 'No data sent') - if request.json.get('id') != name: + data = request.json.get('raw_data') + if not isinstance(data, dict): + data = request.json + if not isinstance(data, dict) or data.get('id') != name: raise ChefAPIError(500, 'Name mismatch in data bag item') item = self.get_item_or_404(bag_name, name) - update(item, data=request.raw_post_data) + update(item, data=json.dumps(data)) return HttpResponse(item.data, status=200, content_type='application/json') @api('DELETE', admin=True) diff --git a/commis/wsgi.py b/commis/wsgi.py new file mode 100644 index 0000000..d4d9653 --- /dev/null +++ b/commis/wsgi.py @@ -0,0 +1,32 @@ +""" +WSGI config for commis project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks +# if running multiple sites in the same mod_wsgi process. To fix this, use +# mod_wsgi daemon mode with each site in its own daemon process, or use +# os.environ["DJANGO_SETTINGS_MODULE"] = "commis.settings" +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application)