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 get(self, request): employee = Employee.objects.get(user=request.user) dashboard_config = Setting.get_value(name="dashboard_config", employee=employee) if dashboard_config: return JsonResponse({"config": dashboard_config}) else: return JsonResponse({"config": {}})
def get(self, request): # DEBUG # user = CustomUser.objects.get(username="******") # employee = Employee.objects.get(user=user) employee = request.user.employee name = request.GET.get("name", None) value = Setting.get_value(name=name, employee=employee) return JsonResponse(dict(name=value if value else ""), safe=False)
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})