def test_form_signals(self): """ Test that each of the signals are sent. """ events = ["valid", "invalid"] invalid = lambda **kwargs: events.remove("invalid") form_invalid.connect(invalid) valid = lambda **kwargs: events.remove("valid") form_valid.connect(valid) form = Form.objects.create(title="Signals", slug='signals', status=STATUS_PUBLISHED) if USE_SITES: form.sites.add(current_site) form.save() form.fields.create(label="field", field_type=NAMES[0][0], required=True, visible=True) # # Create an HttpRequest object that can be passed directly to a view function, # specifically to form_detail() which accepts form POST data username = "******" password = "******" User.objects.create_superuser(username, "", password) req = HttpRequest() req.method = "POST" req.user = authenticate(username=username, password=password) # form_detail(req, "signals") data = {"field_%s" % form.fields.visible()[0].id: "test"} req.POST.update(data) form_detail(req, "signals") self.assertEqual(len(events), 0)
def test_form_signals(self): """ Test that each of the signals are sent. """ events = ["valid", "invalid"] invalid = lambda **kwargs: events.remove("invalid") form_invalid.connect(invalid) valid = lambda **kwargs: events.remove("valid") form_valid.connect(valid) form = Form.objects.create(title="Signals", status=STATUS_PUBLISHED) if USE_SITES: form.sites.add(self._site) form.save() form.fields.create(label="field", field_type=NAMES[0][0], required=True, visible=True) self.client.post(form.get_absolute_url(), data={}) data = {form.fields.visible()[0].slug: "test"} self.client.post(form.get_absolute_url(), data=data) self.assertEqual(len(events), 0)
user_profile = request.user.get_profile() # See if the User Profile exists when an Account is created with Social Auth if user_profile: entry.organization = user_profile.current_organization # Save all the canonical for the fields of the entry for f in entry.fields.all(): if models.DocumentSetFormField.objects.get( pk=f.field_id).autocomplete: f.canonical_label = f.get_canonical_value() f.save() # Save the entry entry.save() # Verify the document if request.user.is_staff or request.user.is_superuser: entry.force_verify() else: entry.document.verify() except Exception as e: # should delete the 'entry' here entry.delete() raise @receiver(form_invalid) def invalid_entry(sender=None, form=None, **kwargs): print repr(form.errors) form_valid.connect(create_entry, dispatch_uid="create_entry_signal")
try: # Create the entry entry.document = models.Document.objects.get(pk=document_id) entry.user = request.user # Save all the canonical for the fields of the entry for f in entry.fields.all(): if models.DocumentSetFormField.objects.get(pk=f.field_id).autocomplete: f.canonical_label = f.get_canonical_value() f.save() # Save the entry entry.save() # Verify the document if request.user.is_staff or request.user.is_superuser: entry.force_verify() else: entry.document.verify() except Exception as e: # should delete the 'entry' here entry.delete() raise @receiver(form_invalid) def invalid_entry(sender=None, form=None, **kwargs): print repr(form.errors) form_valid.connect(create_entry, dispatch_uid="create_entry_signal")