コード例 #1
0
ファイル: views.py プロジェクト: vfulco/MyJobs
def prm_edit_records(request):
    company, partner, user = prm_worthy(request)
    record_id = request.GET.get('id', None)

    try:
        instance = ContactRecord.objects.get(pk=record_id)
    except ContactRecord.DoesNotExist:
        instance = None

    if request.method == 'POST':
        instance = None
        if record_id:
            try:
                instance = ContactRecord.objects.get(pk=record_id)
            except ContactRecord.DoesNotExist:
                instance = None

        form = ContactRecordForm(request.POST, request.FILES,
                                 partner=partner, instance=instance)
        if form.is_valid():
            form.save(user, partner)
            return HttpResponseRedirect(reverse('record_view') + '?' +
                                        request.META['QUERY_STRING'])
    else:
        form = ContactRecordForm(partner=partner, instance=instance)

    ctx = {
        'company': company,
        'partner': partner,
        'content_type': ContentType.objects.get_for_model(ContactRecord).id,
        'item_id': record_id,
        'form': form,
    }
    return render_to_response('mypartners/edit_record.html', ctx,
                              RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: vfulco/MyJobs
def prm_edit_records(request):
    company, partner, user = prm_worthy(request)
    record_id = request.GET.get("id", None)

    try:
        instance = ContactRecord.objects.get(pk=record_id)
    except ContactRecord.DoesNotExist:
        instance = None

    if request.method == "POST":
        instance = None
        if record_id:
            try:
                instance = ContactRecord.objects.get(pk=record_id)
            except ContactRecord.DoesNotExist:
                instance = None

        form = ContactRecordForm(request.POST, request.FILES, partner=partner, instance=instance)
        if form.is_valid():
            form.save(user, partner)
            return HttpResponseRedirect(reverse("record_view") + "?" + request.META["QUERY_STRING"])
    else:
        form = ContactRecordForm(partner=partner, instance=instance)

    ctx = {
        "company": company,
        "partner": partner,
        "content_type": ContentType.objects.get_for_model(ContactRecord).id,
        "item_id": record_id,
        "form": form,
    }
    return render_to_response("mypartners/edit_record.html", ctx, RequestContext(request))
コード例 #3
0
ファイル: test_forms.py プロジェクト: supervisitor20/MyJobs
    def setUp(self):
        super(ContactRecordFormTests, self).setUp()

        self.contact_record = ContactRecordFactory(contact=self.contact,
                                                   partner=self.partner)

        # The contact record form has a lot of required fields.
        self.data = {
            'contact_type': self.contact_record.contact_type,
            'contact': self.contact_record.contact.pk,
            'contact_email': self.contact_record.contact_email,
            'length_0': "00",
            'length_1': "30",
            'date_time_0': "Aug",
            'date_time_1': "24",
            'date_time_2': "2015",
            'date_time_3': "03",
            'date_time_4': "10",
            'date_time_5': "PM",
            'notes': self.contact_record.notes,
            'partner': self.contact_record.partner.pk,
            'company': self.contact_record.partner.owner
        }
        self.form = ContactRecordForm(instance=self.contact_record,
                                      partner=self.partner,
                                      data=self.data)

        # add a few contact records so that we have some to select from
        ContactRecordFactory.create_batch(3,
                                          partner=self.partner,
                                          contact=self.contact,
                                          contact_type='phone')

        self.client.path = reverse(
            "partner_edit_record") + "?partner=%s" % self.partner.pk
コード例 #4
0
ファイル: test_forms.py プロジェクト: wejhink/MyJobs
 def test_add_contact_record_last_action_time(self):
     """
         Verify last action time is created when contact record form is saved
     """
     new_form = ContactRecordForm(data=self.data, partner=self.partner)
     self.assertTrue(new_form.is_valid())
     self.assertIsNone(new_form.fields.get('last_action_time'))
     saved_form_instance = new_form.save(user=self.contact_user, partner=self.partner)
     self.assertIsNotNone(saved_form_instance.last_action_time)
コード例 #5
0
ファイル: test_forms.py プロジェクト: DirectEmployers/MyJobs
 def test_add_contact_record_last_action_time(self):
     """
         Verify last action time is created when contact record form is saved
     """
     request = Mock()
     request.configure_mock(user=self.contact_user, impersonator=None)
     new_form = ContactRecordForm(data=self.data, partner=self.partner)
     self.assertTrue(new_form.is_valid())
     self.assertIsNone(new_form.fields.get('last_action_time'))
     saved_form_instance = new_form.save(request=request, partner=self.partner)
     self.assertIsNotNone(saved_form_instance.last_action_time)
コード例 #6
0
ファイル: test_forms.py プロジェクト: supervisitor20/MyJobs
 def test_add_contact_record_last_action_time(self):
     """
         Verify last action time is created when contact record form is saved
     """
     request = Mock()
     request.configure_mock(user=self.contact_user, impersonator=None)
     new_form = ContactRecordForm(data=self.data, partner=self.partner)
     self.assertTrue(new_form.is_valid())
     self.assertIsNone(new_form.fields.get('last_action_time'))
     saved_form_instance = new_form.save(request=request,
                                         partner=self.partner)
     self.assertIsNotNone(saved_form_instance.last_action_time)
コード例 #7
0
ファイル: test_forms.py プロジェクト: wejhink/MyJobs
    def setUp(self):
        super(ContactRecordFormTests, self).setUp()

        self.contact_record = ContactRecordFactory(
            contact=self.contact, partner=self.partner)

        # The contact record form has a lot of required fields.
        self.data = {
            'contact_type': self.contact_record.contact_type,
            'contact': self.contact_record.contact.pk,
            'contact_email': self.contact_record.contact_email,
            'length_0': "00",
            'length_1': "30",
            'date_time_0': "Aug",
            'date_time_1': "24",
            'date_time_2': "2015",
            'date_time_3': "03",
            'date_time_4': "10",
            'date_time_5': "PM",
            'notes': self.contact_record.notes,
            'partner': self.contact_record.partner.pk,
            'company': self.contact_record.partner.owner
        }
        self.form = ContactRecordForm(
            instance=self.contact_record, partner=self.partner, data=self.data)

        # add a few contact records so that we have some to select from
        ContactRecordFactory.create_batch(3, partner=self.partner,
                                          contact=self.contact,
                                          contact_type='phone')

        self.client.path = reverse(
            "partner_edit_record") + "?partner=%s" % self.partner.pk
コード例 #8
0
ファイル: test_forms.py プロジェクト: supervisitor20/MyJobs
    def test_archived_contacts_not_shown(self):
        """Test that archived contacts aren't selectable."""

        self.assertIn(self.contact, self.form.fields['contact'].queryset)

        self.contact.delete()
        form = ContactRecordForm(partner=self.partner)
        self.assertNotIn(self.contact, form.fields['contact'].queryset)
コード例 #9
0
    def test_get_form_delta(self):
        """Tests that form changes are properly captured in a delta."""

        request = Mock()
        request.configure_mock(user=self.staff_user, impersonator=None)
        contact_record = ContactRecordFactory(
            contact=self.contact, partner=self.partner)
        attachment = PRMAttachmentFactory(contact_record=contact_record)

        # The contact record form has a lot of required fields.
        data=dict(
            contact_type=contact_record.contact_type,
            contact=contact_record.contact.pk,
            contact_email=contact_record.contact_email,
            # contact_phone=contact_record.contact_phone,
            length_0="00",
            length_1="30",
            date_time_0="Aug",
            date_time_1="24",
            date_time_2="2015",
            date_time_3="03",
            date_time_4="10",
            date_time_5="PM",
            notes=contact_record.notes,
            partner=contact_record.partner.pk,
            company=contact_record.partner.owner,
            attach_delete=[attachment.pk]
        )
        form = ContactRecordForm(
            instance=contact_record, partner=contact_record.partner, data=data)

        # Before 8/25/2015, saving this form with such changes would cause an
        # error
        form.save(request, contact_record.partner)

        delta = json.loads(ContactLogEntry.objects.last().delta)
        # ensure a change is logged
        self.assertEqual(delta['attach_delete']['new'], [str(attachment.pk)])
        # ensure things that aren't changes aren't logged
        self.assertNotIn("notes", delta.keys())
コード例 #10
0
ファイル: test_forms.py プロジェクト: wejhink/MyJobs
class ContactRecordFormTests(MyPartnersTestCase):
    def setUp(self):
        super(ContactRecordFormTests, self).setUp()

        self.contact_record = ContactRecordFactory(
            contact=self.contact, partner=self.partner)

        # The contact record form has a lot of required fields.
        self.data = {
            'contact_type': self.contact_record.contact_type,
            'contact': self.contact_record.contact.pk,
            'contact_email': self.contact_record.contact_email,
            'length_0': "00",
            'length_1': "30",
            'date_time_0': "Aug",
            'date_time_1': "24",
            'date_time_2': "2015",
            'date_time_3': "03",
            'date_time_4': "10",
            'date_time_5': "PM",
            'notes': self.contact_record.notes,
            'partner': self.contact_record.partner.pk,
            'company': self.contact_record.partner.owner
        }
        self.form = ContactRecordForm(
            instance=self.contact_record, partner=self.partner, data=self.data)

        # add a few contact records so that we have some to select from
        ContactRecordFactory.create_batch(3, partner=self.partner,
                                          contact=self.contact,
                                          contact_type='phone')

        self.client.path = reverse(
            "partner_edit_record") + "?partner=%s" % self.partner.pk

    def test_archived_contacts_not_shown(self):
        """Test that archived contacts aren't selectable."""

        self.assertIn(self.contact, self.form.fields['contact'].queryset)

        self.contact.delete()
        form = ContactRecordForm(partner=self.partner)
        self.assertNotIn(self.contact, form.fields['contact'].queryset)

    def test_that_creating_a_record_redirects_properly(self):
        """
        Tests that when you create a record, you are redirected to the view
        which contains that record.
        """
        self.data.update({
            "notes": "brand new record"
        })

        record_count = ContactRecord.objects.count()

        response = self.client.post(data=self.data, follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(ContactRecord.objects.count(), record_count + 1)
        self.assertIn("brand new record", response.content)

    def test_changing_contact_type_redirects_correctly(self):
        """
        Test that when saving a contact record, you are redirected to the view
        which contains that record, even if you changed the contact type.
        """

        # the contact record we are interested in modifying and returning to
        contact_record = ContactRecord.objects.all()[2]
        # sanity check to make sure notes aren't modified yet
        self.assertEqual(contact_record.notes, "Some notes go here.")
        
        self.data.update({
            "contact_type": "phone",
            "contact_phone": "555-555-5555",
            "notes": "some test notes"
        })
        response = self.client.post(path=self.client.path + '&page=2',
                                    data=self.data, follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn("some test notes", response.content)

    def test_that_backdating_a_record_redirects_correctly(self):
        """
        Test that when saving a contact record, you are redirected to the view
        which contains that record, even if back-date the record.
        """

        # the contact record we are interested in modifying and returning to
        contact_record = ContactRecord.objects.all()[1]
        # sanity check to make sure notes aren't modified yet
        self.assertEqual(contact_record.notes, "Some notes go here.")
        
        self.data.update({
            'date_time_2': "2012",
            "notes": "some test notes"
        })
        response = self.client.post(path=self.client.path + '&page=2',
                                    data=self.data, follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn("some test notes", response.content)

    def test_edit_contact_record_last_action_time(self):
        """
            Verify last action time is updated when contact record form is edited
        """
        original_time = self.contact_record.last_action_time
        self.assertEqual(original_time, self.form.instance.last_action_time)
        saved_form_instance = self.form.save(user=self.contact_user, partner=self.partner)
        self.assertNotEqual(original_time, saved_form_instance.last_action_time)

    def test_add_contact_record_last_action_time(self):
        """
            Verify last action time is created when contact record form is saved
        """
        new_form = ContactRecordForm(data=self.data, partner=self.partner)
        self.assertTrue(new_form.is_valid())
        self.assertIsNone(new_form.fields.get('last_action_time'))
        saved_form_instance = new_form.save(user=self.contact_user, partner=self.partner)
        self.assertIsNotNone(saved_form_instance.last_action_time)
コード例 #11
0
ファイル: test_forms.py プロジェクト: supervisitor20/MyJobs
class ContactRecordFormTests(MyPartnersTestCase):
    def setUp(self):
        super(ContactRecordFormTests, self).setUp()

        self.contact_record = ContactRecordFactory(contact=self.contact,
                                                   partner=self.partner)

        # The contact record form has a lot of required fields.
        self.data = {
            'contact_type': self.contact_record.contact_type,
            'contact': self.contact_record.contact.pk,
            'contact_email': self.contact_record.contact_email,
            'length_0': "00",
            'length_1': "30",
            'date_time_0': "Aug",
            'date_time_1': "24",
            'date_time_2': "2015",
            'date_time_3': "03",
            'date_time_4': "10",
            'date_time_5': "PM",
            'notes': self.contact_record.notes,
            'partner': self.contact_record.partner.pk,
            'company': self.contact_record.partner.owner
        }
        self.form = ContactRecordForm(instance=self.contact_record,
                                      partner=self.partner,
                                      data=self.data)

        # add a few contact records so that we have some to select from
        ContactRecordFactory.create_batch(3,
                                          partner=self.partner,
                                          contact=self.contact,
                                          contact_type='phone')

        self.client.path = reverse(
            "partner_edit_record") + "?partner=%s" % self.partner.pk

    def test_archived_contacts_not_shown(self):
        """Test that archived contacts aren't selectable."""

        self.assertIn(self.contact, self.form.fields['contact'].queryset)

        self.contact.delete()
        form = ContactRecordForm(partner=self.partner)
        self.assertNotIn(self.contact, form.fields['contact'].queryset)

    def test_that_creating_a_record_redirects_properly(self):
        """
        Tests that when you create a record, you are redirected to the view
        which contains that record.
        """
        self.data.update({"notes": "brand new record"})

        record_count = ContactRecord.objects.count()

        response = self.client.post(data=self.data, follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(ContactRecord.objects.count(), record_count + 1)
        self.assertIn("brand new record", response.content)

    def test_changing_contact_type_redirects_correctly(self):
        """
        Test that when saving a contact record, you are redirected to the view
        which contains that record, even if you changed the contact type.
        """

        # the contact record we are interested in modifying and returning to
        contact_record = ContactRecord.objects.all()[2]
        # sanity check to make sure notes aren't modified yet
        self.assertEqual(contact_record.notes, "Some notes go here.")

        self.data.update({
            "contact_type": "phone",
            "contact_phone": "555-555-5555",
            "notes": "some test notes"
        })
        response = self.client.post(path=self.client.path + '&page=2',
                                    data=self.data,
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn("some test notes", response.content)

    def test_that_backdating_a_record_redirects_correctly(self):
        """
        Test that when saving a contact record, you are redirected to the view
        which contains that record, even if back-date the record.
        """

        # the contact record we are interested in modifying and returning to
        contact_record = ContactRecord.objects.all()[1]
        # sanity check to make sure notes aren't modified yet
        self.assertEqual(contact_record.notes, "Some notes go here.")

        self.data.update({'date_time_2': "2012", "notes": "some test notes"})
        response = self.client.post(path=self.client.path + '&page=2',
                                    data=self.data,
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn("some test notes", response.content)

    def test_edit_contact_record_last_action_time(self):
        """
            Verify last action time is updated when contact record form is edited
        """
        request = Mock()
        request.configure_mock(user=self.contact_user, impersonator=None)
        original_time = self.contact_record.last_action_time
        self.assertEqual(original_time, self.form.instance.last_action_time)
        saved_form_instance = self.form.save(request=request,
                                             partner=self.partner)
        self.assertNotEqual(original_time,
                            saved_form_instance.last_action_time)

    def test_add_contact_record_last_action_time(self):
        """
            Verify last action time is created when contact record form is saved
        """
        request = Mock()
        request.configure_mock(user=self.contact_user, impersonator=None)
        new_form = ContactRecordForm(data=self.data, partner=self.partner)
        self.assertTrue(new_form.is_valid())
        self.assertIsNone(new_form.fields.get('last_action_time'))
        saved_form_instance = new_form.save(request=request,
                                            partner=self.partner)
        self.assertIsNotNone(saved_form_instance.last_action_time)