def post(self, request, *args, **kwargs):
     self.object = self.get_object()
     print self.object
     print request.user
     print request.POST
     context = self.get_context_data(object=self.object)
     if "recent_com" in request.POST:
         form_com = RecentComForm(
             request.POST,
             user=request.user,
             contact=self.object
         )
         if form_com.is_valid():
             form_com.save()
             messages.info(request, "Entry added.")
             return redirect("contact_detail", self.object.pk)
         else:
             context["form_com"] = form_com
     if "con" in request.POST:
         form_con = ConnectionForm(request.POST, contact=self.object)
         if form_con.is_valid():
             form_con.save()
             messages.info(request, "Connection created.")
             return redirect("contact_detail", self.object.pk)
         else:
             context["form_con"] = ConnectionForm(contact=self.object)
     return self.render_to_response(context)
 def post(self, request, *args, **kwargs):
     self.object = self.get_object()
     print self.object
     print request.user
     print request.POST
     context = self.get_context_data(object=self.object)
     if "recent_com" in request.POST:
         form_com = RecentComForm(request.POST,
                                  user=request.user,
                                  contact=self.object)
         if form_com.is_valid():
             form_com.save()
             messages.info(request, "Entry added.")
             return redirect("contact_detail", self.object.pk)
         else:
             context["form_com"] = form_com
     if "con" in request.POST:
         form_con = ConnectionForm(request.POST, contact=self.object)
         if form_con.is_valid():
             form_con.save()
             messages.info(request, "Connection created.")
             return redirect("contact_detail", self.object.pk)
         else:
             context["form_con"] = ConnectionForm(contact=self.object)
     return self.render_to_response(context)
 def test_empty_valid_form(self):
     form = RecentComForm(
         {},
         self.recent_com,
         user=self.user,
         contact=self.contact
     )
     self.assertTrue(form.is_valid())
 def test_save_valid_form(self):
     form_data = {
         "communication": "New communication message",
     }
     form = RecentComForm(form_data,
                          self.recent_com,
                          user=self.user,
                          contact=self.contact)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(form.cleaned_data["communication"],
                      "New communication message")
 def test_save_valid_form(self):
     form_data = {
         "communication": "New communication message",
     }
     form = RecentComForm(
         form_data,
         self.recent_com,
         user=self.user,
         contact=self.contact
     )
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(
         form.cleaned_data["communication"],
         "New communication message"
     )
Exemplo n.º 6
0
 def get_context_data(self, **kwargs):
     context = super(ContactDetail, self).get_context_data(**kwargs)
     context.update({
         "form_com": RecentComForm(user=self.request.user, contact=self.object),
         "recent_coms": self.object.recent_communications.all().order_by("-created"),
         "form_con": ConnectionForm(contact=self.object),
         "connections": self.object.source_connections.all().order_by("con_type")
     })
     return context
 def test_empty_valid_form(self):
     form = RecentComForm({},
                          self.recent_com,
                          user=self.user,
                          contact=self.contact)
     self.assertTrue(form.is_valid())