def get_context_data_edit(self, context): self.title = self.preferences.get('title', self.title) status_filter = self.preferences.get('status_filter') if status_filter: context['form'] = StatusWidgetForm(QueryDict(str(status_filter))) else: context['form'] = StatusWidgetForm() context['interval'] = self.preferences['refresh_interval'] / 1000 return context
def post(self, request): """Save navlet options on post""" navlet = self.account_navlet form = StatusWidgetForm(request.POST) if form.is_valid(): navlet.preferences['status_filter'] = request.POST.urlencode() try: navlet.preferences['refresh_interval'] = int( request.POST['interval']) * 1000 except Exception: pass navlet.save() return HttpResponse(json.dumps(self.preferences)) else: return JsonResponse(form.errors, status=400)
def find_extra_columns(status_filter): """Finds the chosen extra columns and returns them in a list""" column_choices = StatusWidgetForm().fields.get('extra_columns').choices chosen_columns = QueryDict(str(status_filter)).getlist('extra_columns') return [(k, v) for k, v in column_choices if k in chosen_columns]