예제 #1
0
 def get_context_data(self, **kwargs):
     context = super(BoardUpdateView, self).get_context_data(**kwargs)
     if self.request.POST:
         context['graph_form'] = GraphFormSet(self.request.POST,
                                              instance=self.object)
     else:
         context['graph_form'] = GraphFormSet(instance=self.object)
     return context
예제 #2
0
 def post(self, request, *args, **kwargs):
     """
     Handles POST requests, instantiating a form instance and its inline
     formsets with the passed POST variables and then checking them for
     validity.
     """
     form_class = self.get_form_class()
     form = self.get_form(form_class)
     graph_form = GraphFormSet(self.request.POST)
     if form.is_valid() and graph_form.is_valid():
         return self.form_valid(form, graph_form)
     else:
         return self.form_invalid(form, graph_form)
예제 #3
0
 def get(self, request, *args, **kwargs):
     """
     Handles GET requests and instantiates blank versions of the form
     and its inline formsets.
     """
     screen_id = self.request.GET.get('screen_id')
     initials = zbx_get_graphs(screen_id)  # get inital items from zabbix
     form_class = self.get_form_class()
     form = self.get_form(form_class)
     form.initial = {'title': zbx_get_screen_name(screen_id)}
     graph_form = GraphFormSet()
     graph_form.extra = len(initials) + 1
     for subform, data in zip(graph_form.forms, initials):
         subform.initial = data
     return self.render_to_response(
         self.get_context_data(form=form, graph_form=graph_form)
     )