def post(self, request): user = request.user # user = CustomUser.objects.get(username="******") employee = Employee.objects.get(user=user) print(request.body) data = json.loads(request.body) cell_info = data["cell_info"] graph_info = data["graph_info"] journal_name = cell_info["journal_name"] table_name = cell_info["table_name"] field_name = cell_info["field_name"] journal = Journal.objects.get(name=journal_name) table = Table.objects.get(name=table_name, journal_id=journal.id) field = Field.objects.get(name=field_name, table_id=table.id) dashboard_config = Setting.get_value(name="dashboard_config", employee=employee) if dashboard_config is None: dashboard_config = {} dashboard_config[str(field.id)] = dict(x=0, y=0, w=6, h=8, type=graph_info["type"]) Setting.set_value(name="dashboard_config", employee=employee, value=dashboard_config) return JsonResponse({"result": 1})
def post(self, request): # DEBUG # user = CustomUser.objects.get(username="******") # employee = Employee.objects.get(user=user) employee = request.user.employee setting_data = json.loads(request.body) Setting.set_value(name=setting_data["name"], value=setting_data["value"], employee=employee) return JsonResponse({"status": 1})
def test_animals_can_speak(self): """Settings are saved and work correctly""" Setting["brackets_test"] = "brackets_val" self.assertEqual(Setting["brackets_test"], "brackets_val") Setting.set_value(name='set_test', value='set_val') self.assertEqual(Setting.get_value('set_test1'), 'set_val') with self.assertRaises(ValueError): a = Setting['sadfsda']
def post(self, request): user = request.user employee = Employee.objects.get(user=user) graph_id = json.loads(request.body)["id"] dashboard_config = Setting.get_value(name="dashboard_config", employee=employee) if graph_id in dashboard_config.keys(): del dashboard_config[graph_id] Setting.set_value(name="dashboard_config", employee=employee, value=dashboard_config) return JsonResponse({"result": 1})
def post(self, request): layout = json.loads(request.body) employee = Employee.objects.get(user=request.user) config = Setting.get_value(name="dashboard_config", employee=employee) for item in layout: id = item["i"] for key in item: if key not in ["i", "moved"]: config[id][key] = item[key] Setting.set_value(name="dashboard_config", employee=employee, value=config) return JsonResponse({"result": 1})
def _save_m2m(self): super()._save_m2m() value = self.data.get('pickled_value', None) name = self.data.get('name', None) employee_id = self.data.get('employee', None) content_type_id = self.data.get('content_type', None) object_id = self.data.get('object_id', None) if name: if content_type_id and object_id: ct = ContentType.objects.get_for_id(content_type_id) object = ct.get_object_for_this_type(pk=object_id) else: object = None Setting.set_value(name=name, value=value, employee=Employee.objects.get(id=employee_id) if employee_id else None, obj=object if object else None)