@method_decorator(logged_in_or_basicauth(AUTH_REALM))
    @method_decorator(group_required(API_GROUP_NAME))  # FIXME: Should be more granular permissions
    def post(self, request):
        # Catch post with no payload
        try:
            mdt = request.POST['mdt']
        except KeyError:
            log.error('MetaDataTemplateHandler.create attempted with no payload.')
            if settings.DEBUG:
                raise
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)

        # Catch improper MDT payload
        try:
            data = json.loads(str(mdt))
        except ValueError, e:
            log.error('MetaDataTemplateHandler.create attempted with bad json payload. %s' % e)
            if settings.DEBUG:
                raise
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)

        # Try and validate MDT
        manager = MetaDataTemplateManager()
        if not manager.validate_mdt(mdt):
            return Response(status=status.HTTP_400_BAD_REQUEST)

        # Store MDT
        result = manager.store(data)
        if result is False:
            log.error('MetaDataTemplateHandler.create error occurred on store.')
            return Response(status=status.HTTP_409_CONFLICT)

        log.info('MetaDataTemplateHandler.create request fulfilled.')
        return Response(result, status=status.HTTP_200_OK)
dataset/ETHPy150Open adlibre/Adlibre-DMS/adlibre_dms/apps/api/views.py/MetaDataTemplateHandler.post/original