-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
6,231 additions
and
1,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,8 @@ def test_with_manual_address(self): | |
'archived_by': None, | ||
'archived_on': None, | ||
'archived_reason': None, | ||
'created_on': '2017-04-18T13:25:30.986208' | ||
'created_on': '2017-04-18T13:25:30.986208', | ||
'modified_on': '2017-04-18T13:25:30.986208', | ||
} | ||
|
||
def test_with_address_same_as_company(self): | ||
|
@@ -282,42 +283,43 @@ def test_fails_without_primary_specified(self): | |
class TestEditContact(APITestMixin): | ||
"""Edit contact test case.""" | ||
|
||
@freeze_time('2017-04-18 13:25:30.986208+00:00') | ||
def test_patch(self): | ||
"""Test that it successfully patch an existing contact.""" | ||
company = CompanyFactory() | ||
with freeze_time('2017-04-18 13:25:30.986208+00:00'): | ||
company = CompanyFactory() | ||
|
||
contact = ContactFactory( | ||
title_id=constants.Title.admiral_of_the_fleet.value.id, | ||
first_name='Oratio', | ||
last_name='Nelson', | ||
job_title=constants.Role.owner.value.name, | ||
company=company, | ||
email='[email protected]', | ||
email_alternative='[email protected]', | ||
primary=True, | ||
adviser=self.user, | ||
telephone_countrycode='+44', | ||
telephone_number='123456789', | ||
telephone_alternative='987654321', | ||
address_same_as_company=False, | ||
address_1='Foo st.', | ||
address_2='adr 2', | ||
address_town='London', | ||
address_county='London', | ||
address_country_id=constants.Country.united_kingdom.value.id, | ||
address_postcode='SW1A1AA', | ||
notes='lorem ipsum', | ||
contactable_by_dit=False, | ||
contactable_by_dit_partners=False, | ||
contactable_by_email=True, | ||
contactable_by_phone=True | ||
) | ||
contact = ContactFactory( | ||
title_id=constants.Title.admiral_of_the_fleet.value.id, | ||
first_name='Oratio', | ||
last_name='Nelson', | ||
job_title=constants.Role.owner.value.name, | ||
company=company, | ||
email='[email protected]', | ||
email_alternative='[email protected]', | ||
primary=True, | ||
adviser=self.user, | ||
telephone_countrycode='+44', | ||
telephone_number='123456789', | ||
telephone_alternative='987654321', | ||
address_same_as_company=False, | ||
address_1='Foo st.', | ||
address_2='adr 2', | ||
address_town='London', | ||
address_county='London', | ||
address_country_id=constants.Country.united_kingdom.value.id, | ||
address_postcode='SW1A1AA', | ||
notes='lorem ipsum', | ||
contactable_by_dit=False, | ||
contactable_by_dit_partners=False, | ||
contactable_by_email=True, | ||
contactable_by_phone=True | ||
) | ||
|
||
url = reverse('api-v3:contact:detail', kwargs={'pk': contact.pk}) | ||
response = self.api_client.patch(url, { | ||
'first_name': 'New Oratio', | ||
}, format='json') | ||
with freeze_time('2017-04-19 13:25:30.986208+00:00'): | ||
response = self.api_client.patch(url, { | ||
'first_name': 'New Oratio', | ||
}, format='json') | ||
|
||
assert response.status_code == status.HTTP_200_OK, response.data | ||
assert response.json() == { | ||
|
@@ -364,7 +366,8 @@ def test_patch(self): | |
'archived_by': None, | ||
'archived_on': None, | ||
'archived_reason': None, | ||
'created_on': '2017-04-18T13:25:30.986208' | ||
'created_on': '2017-04-18T13:25:30.986208', | ||
'modified_on': '2017-04-19T13:25:30.986208', | ||
} | ||
|
||
|
||
|
@@ -502,7 +505,8 @@ def test_view(self): | |
'archived_by': None, | ||
'archived_on': None, | ||
'archived_reason': None, | ||
'created_on': '2017-04-18T13:25:30.986208' | ||
'created_on': '2017-04-18T13:25:30.986208', | ||
'modified_on': '2017-04-18T13:25:30.986208', | ||
} | ||
|
||
|
||
|
@@ -573,3 +577,5 @@ def test_audit_log_view(self): | |
assert entry['comment'] == 'Changed' | ||
assert entry['timestamp'] == changed_datetime.isoformat() | ||
assert entry['changes']['notes'] == ['Initial notes', 'New notes'] | ||
assert not {'created_on', 'created_by', 'modified_on', 'modified_by'} & entry[ | ||
'changes'].keys() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from reversion.admin import VersionAdmin | ||
|
||
|
||
class ConfigurableVersionAdmin(VersionAdmin): | ||
""" | ||
Subclass of VersionAdmin that allows the excluded model fields for django-reversion | ||
to be easily set. | ||
This is in line with the example on: | ||
https://django-reversion.readthedocs.io/en/stable/admin.html#reversion-admin-versionadmin | ||
Excluded fields are not saved in django-reversion versions. | ||
This is set in the admin class because we're using django-reversion auto-registration | ||
via VersionAdmin. | ||
""" | ||
|
||
reversion_excluded_fields = None | ||
|
||
def reversion_register(self, model, **options): | ||
"""Used the the django-reversion model auto-registration mechanism.""" | ||
if self.reversion_excluded_fields: | ||
options['exclude'] = self.reversion_excluded_fields | ||
super().reversion_register(model, **options) | ||
|
||
|
||
class BaseModelVersionAdmin(ConfigurableVersionAdmin): | ||
""" | ||
VersionAdmin subclass that excludes fields defined on BaseModel. | ||
These aren't particularly useful to save in django-reversion versions because | ||
created_by/created_on will not change between versions, and modified_on/modified_by | ||
is tracked by django-reversion separately in revisions. | ||
""" | ||
|
||
reversion_excluded_fields = ('created_on', 'created_by', 'modified_on', 'modified_by') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
from django.contrib import admin | ||
|
||
from reversion.admin import VersionAdmin | ||
|
||
from datahub.core.admin import BaseModelVersionAdmin | ||
from .models import Interaction, ServiceDelivery, ServiceOffer | ||
|
||
|
||
@admin.register(Interaction) | ||
class InteractionAdmin(VersionAdmin): | ||
class InteractionAdmin(BaseModelVersionAdmin): | ||
"""Interaction admin.""" | ||
|
||
search_fields = ['id', 'company__company_number', 'company__company_name', 'contact_email'] | ||
raw_id_fields = ('company', 'dit_adviser', 'investment_project', 'contact') | ||
|
||
|
||
@admin.register(ServiceDelivery) | ||
class ServiceDeliveryAdmin(VersionAdmin): | ||
class ServiceDeliveryAdmin(BaseModelVersionAdmin): | ||
"""Service Delivery admin.""" | ||
|
||
search_fields = ['id', 'company__company_number', 'company__company_name', 'contact_email'] | ||
raw_id_fields = ('company', 'dit_adviser', 'contact', 'event') | ||
|
||
|
||
@admin.register(ServiceOffer) | ||
class ServiceOfferAdmin(VersionAdmin): | ||
class ServiceOfferAdmin(BaseModelVersionAdmin): | ||
"""Service Offer admin.""" | ||
|
||
raw_id_fields = ('event',) |
Oops, something went wrong.