Skip to content

Commit

Permalink
Merge branch 'release/nocino'
Browse files Browse the repository at this point in the history
  • Loading branch information
reupen committed Aug 21, 2017
2 parents e3c178b + ed27f8d commit 5b8360b
Show file tree
Hide file tree
Showing 105 changed files with 6,231 additions and 1,945 deletions.
6 changes: 4 additions & 2 deletions config/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datahub.company import urls as company_urls
from datahub.company import views as company_views
from datahub.interaction import views as interaction_views
from datahub.interaction import urls as interaction_urls
from datahub.investment import urls as investment_urls
from datahub.leads import urls as leads_urls
from datahub.omis import urls as omis_urls
Expand All @@ -32,11 +33,12 @@
# API V3

v3_urls = [
url(r'^', include((investment_urls, 'investment'), namespace='investment')),
url(r'^', include((leads_urls, 'business-leads'), namespace='business-leads')),
url(r'^', include((company_urls.contact_urls, 'contact'), namespace='contact')),
url(r'^', include((company_urls.company_urls, 'company'), namespace='company')),
url(r'^', include((company_urls.ch_company_urls, 'ch-company'), namespace='ch-company')),
url(r'^', include((interaction_urls, 'interaction'), namespace='interaction')),
url(r'^', include((investment_urls, 'investment'), namespace='investment')),
url(r'^', include((leads_urls, 'business-leads'), namespace='business-leads')),
url(r'^', include((search_urls, 'search'), namespace='search')),
url(r'^omis/', include((omis_urls, 'omis'), namespace='omis'))
]
3 changes: 3 additions & 0 deletions config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
# Leeloo stuff
ES_URL = env('ES_URL')
ES_INDEX = env('ES_INDEX')
ES_INDEX_SETTINGS = {
'index.mapping.nested_fields.limit': 100
}
DATAHUB_SECRET = env('DATAHUB_SECRET')
CDMS_AUTH_URL = env('CDMS_AUTH_URL')
CDMS_TEXT_MAX_LENGTH = 4000
Expand Down
6 changes: 2 additions & 4 deletions config/settings/common_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
MIDDLEWARE.append('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware')
INSTALLED_APPS.append('raven.contrib.django.raven_compat')

SENTRY_DSN = env('DJANGO_SENTRY_DSN')

# Logging
LOGGING = {
'version': 1,
Expand Down Expand Up @@ -48,7 +46,7 @@
},
}


RAVEN_CONFIG = {
'DSN': SENTRY_DSN,
'dsn': env('DJANGO_SENTRY_DSN'),
'include_paths': ['datahub']
}
5 changes: 5 additions & 0 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
]

ES_INDEX = 'test'
ES_INDEX_SETTINGS = {
'index.mapping.nested_fields.limit': 100,
'number_of_shards': 1,
'number_of_replicas': 0,
}
DOCUMENT_BUCKET='test-bucket'
AV_SERVICE_URL='http://av-service/'
9 changes: 4 additions & 5 deletions datahub/company/admin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from reversion.admin import VersionAdmin

from datahub.core.admin import BaseModelVersionAdmin
from .models import Advisor, CompaniesHouseCompany, Company, Contact


@admin.register(Company)
class CompanyAdmin(VersionAdmin):
class CompanyAdmin(BaseModelVersionAdmin):
"""Company admin."""

search_fields = ['name', 'id', 'company_number']
raw_id_fields = ('parent', 'one_list_account_owner', 'archived_by')


@admin.register(Contact)
class ContactAdmin(VersionAdmin):
class ContactAdmin(BaseModelVersionAdmin):
"""Contact admin."""

search_fields = ['first_name', 'last_name', 'company__name']
Expand All @@ -40,7 +39,7 @@ def get_readonly_fields(self, request, obj=None):


@admin.register(Advisor)
class AdviserAdmin(VersionAdmin, UserAdmin):
class AdviserAdmin(BaseModelVersionAdmin, UserAdmin):
"""Adviser admin."""

fieldsets = (
Expand Down
3 changes: 2 additions & 1 deletion datahub/company/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class Meta: # noqa: D101
'archived_on',
'archived_reason',
'archived_by',
'created_on'
'created_on',
'modified_on'
)


Expand Down
2 changes: 2 additions & 0 deletions datahub/company/test/test_company_views_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def test_audit_log_view(self):
assert entry['comment'] == 'Changed'
assert entry['timestamp'] == changed_datetime.isoformat()
assert entry['changes']['description'] == ['Initial desc', 'New desc']
assert not {'created_on', 'created_by', 'modified_on', 'modified_by'} & entry[
'changes'].keys()


class TestCHCompany(APITestMixin):
Expand Down
74 changes: 40 additions & 34 deletions datahub/company/test/test_contact_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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() == {
Expand Down Expand Up @@ -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',
}


Expand Down Expand Up @@ -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',
}


Expand Down Expand Up @@ -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()
36 changes: 36 additions & 0 deletions datahub/core/admin.py
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')
11 changes: 6 additions & 5 deletions datahub/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,13 @@ class Service(Enum):
class Team(Enum):
"""Team."""

healthcare_uk = Constant(
'Healthcare UK', '3ff47a07-002c-e311-a78e-e4115bead28a'
)
crm = Constant(
'crm', 'a7f924aa-9698-e211-a939-e4115bead28a'
healthcare_uk = Constant('Healthcare UK', '3ff47a07-002c-e311-a78e-e4115bead28a')
tees_valley_lep = Constant('Tees Valley LEP', 'a889ef76-8925-e511-b6bc-e4115bead28a')
td_events_healthcare = Constant(
'TD - Events - Healthcare', 'daf924aa-9698-e211-a939-e4115bead28a'
)
food_from_britain = Constant('Food From Britain', '8cf924aa-9698-e211-a939-e4115bead28a')
crm = Constant('crm', 'a7f924aa-9698-e211-a939-e4115bead28a')


class ServiceDeliveryStatus(Enum):
Expand Down
1 change: 1 addition & 0 deletions datahub/core/management/commands/loadmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ def handle(self, *args, **options):
METADATA_FIXTURE_DIR / 'teams.yaml',
METADATA_FIXTURE_DIR / 'titles.yaml',
METADATA_FIXTURE_DIR / 'uk_regions.yaml',
METADATA_FIXTURE_DIR / 'omis.yaml',
]
)
26 changes: 22 additions & 4 deletions datahub/core/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ def to_many_field(wrapped_func):
RemovedInDjango20Warning: Direct assignment to the reverse side of a related set is
deprecated due to the implicit save() that happens. Use xxx.set() instead.
This decorator doesn't call the decorated function; the decorated function is only used
for its name.
This decorator only calls the decorated function to get the default value if none has been
explicitly provided.
Example:
class MyFactory(factory.django.DjangoModelFactory):
...
@to_many_field
def my_m2m_field(self):
# return any default value
return [ob1, obj2]
Usage:
fac = MyFactory(my_m2m_field=[obj3]) # creates an object with my_m2m_field == [obj3]
fac = MyFactory() # creates an object with my_m2m_field == [obj1, obj2]
"""
@factory.post_generation
@wraps(wrapped_func)
Expand All @@ -28,8 +41,13 @@ def wrapping_func(self, create, extracted, **kwargs):
# should not be set
return

if extracted:
field = getattr(self, wrapped_func.__name__)
field = getattr(self, wrapped_func.__name__)
if extracted is not None:
field.set(extracted)
else:
# if the wrapped func returns a value, it's treated as a default value.
value = wrapped_func(self)
if value is not None:
field.set(value)

return wrapping_func
4 changes: 2 additions & 2 deletions datahub/dashboard/serializers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from rest_framework import serializers

from datahub.company.serializers import NestedContactSerializer
from datahub.interaction.serializers import InteractionSerializerRead
from datahub.interaction.serializers import InteractionSerializerReadV1


class IntelligentHomepageSerializer(serializers.Serializer):
"""Intelligent homepage serializer."""

interactions = InteractionSerializerRead(many=True)
interactions = InteractionSerializerReadV1(many=True)
contacts = NestedContactSerializer(many=True)

class Meta: # noqa: D101
Expand Down
4 changes: 2 additions & 2 deletions datahub/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework.views import APIView

from datahub.company.queryset import get_contact_queryset
from datahub.interaction.queryset import get_interaction_queryset
from datahub.interaction.queryset import get_interaction_queryset_v1

from .serializers import IntelligentHomepageSerializer

Expand All @@ -21,7 +21,7 @@ def get(self, request, format=None):
days = request.GET.get('days', 15)
days_in_the_past = now() - timedelta(days=int(days))

interactions = get_interaction_queryset().filter(
interactions = get_interaction_queryset_v1().filter(
dit_adviser=user,
created_on__gte=days_in_the_past
).order_by('-created_on')
Expand Down
9 changes: 4 additions & 5 deletions datahub/interaction/admin.py
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',)
Loading

0 comments on commit 5b8360b

Please sign in to comment.