コード例 #1
0
 def test_save(self):
     initial_values  = self.initial_values
     data = get_values().copy()
     data["version"] = 'test'
     now = datetime.datetime(2018, 1, 1, 23, 0, 0)
     data['DATETIME_VALUE_0'] = now.date()
     data['DATETIME_VALUE_1'] = now.time()
     del data['DATETIME_VALUE']
     f = ConstanceForm(initial=initial_values, data=data)
     self.assertTrue(f.is_valid(), msg=f.errors.as_data())
     f.save()
     self.assertEqual(f.cleaned_data['DATETIME_VALUE'], now)
コード例 #2
0
 def post(self, request, *args, **kwargs):
     """
     Update App Config\n
         POST params:
         - auto_login: bool
         - standard_optional_locators: list[str]
         see settings.OPTIONAL_LOCATORS
     """
     initial = get_values()
     form = ConstanceForm(data=request.data, initial=initial)
     form.data['version'] = initial.get('version')
     if form.is_valid():
         form.save()
         message = 'Application settings updated successfully.'
     else:
         message = form.errors
     return JsonResponse(message, safe=False)
コード例 #3
0
 def post(self, request, *args, **kwargs):
     """
     Update App Config\n
         Params:
             - auto_login: bool
             - standard_optional_locators: list[str], see settings.OPTIONAL_LOCATORS
             - data: json, - custom settings for project
     """
     initial = get_values()
     data = initial.copy()
     data.update(request.data)
     if 'data' in data:
         data['data'] = json.dumps(data['data'])
     form = ConstanceForm(data=data, initial=initial)
     form.data['version'] = initial.get('version')
     if form.is_valid():
         form.save()
         return Response('Application settings updated successfully.')
     else:
         return Response(form.errors, status=500)
コード例 #4
0
    def post(self, request, *args, **kwargs):
        """
        Update App Config data\n
            Params:
                dictionary {key1: val2, key2: val2, ...} - json, custom settings for project
        """
        initial_config = get_values()

        data = json.loads(initial_config['data'])
        data.update(request.data)

        updated_config = initial_config.copy()
        updated_config['data'] = json.dumps(data)

        form = ConstanceForm(data=updated_config, initial=initial_config)
        form.data['version'] = initial_config.get('version')
        if form.is_valid():
            form.save()
            return Response('Application settings updated successfully.')
        else:
            return Response(form.errors, status=500)
コード例 #5
0
    def delete(self, request, *args, **kwargs):
        """
        Delete specific key from App Config data
        """
        initial_config = get_values()
        param = request.data.get('param')

        if not param:
            raise APIException('Provide key to delete')

        data = json.loads(initial_config['data'])
        data.pop(param, None)
        updated_config = initial_config.copy()
        updated_config['data'] = json.dumps(data)

        form = ConstanceForm(data=updated_config, initial=initial_config)
        form.data['version'] = initial_config.get('version')
        if form.is_valid():
            form.save()
            return Response('OK')
        else:
            return Response(form.errors, status=500)