Skip to content

Commit

Permalink
[refs ##118671] Prepare for vans/cars notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaboiangiu committed Jun 17, 2020
1 parent c491fa4 commit 627d3ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ services:
postgres:
image: postgres:9-alpine
container_name: not.db
environment:
- POSTGRES_PASSWORD=test
environment:
TZ: Europe/Copenhagen
POSTGRES_PASSWORD: test
volumes:
- data:/var/lib/postgresql/data
- ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql
Expand Down
8 changes: 6 additions & 2 deletions notifications/management/commands/fetch_bdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ def parse_person_data(self, person):

def set_current_user_true(self, person, companies):
for company in companies:
person_company, _ = PersonCompany.objects.really_all().get_or_create(company=company,person=person)
person_company.current = True
try:
person_company = PersonCompany.objects.really_all().get(company=company, person=person)
person_company.delete()
person_company = PersonCompany.objects.create(company=company, person=person, current=True)
except PersonCompany.DoesNotExist:
person_company = PersonCompany.objects.create(company=company, person=person, current=True)

def fetch_persons(self, registry):
person_count = 0
Expand Down
34 changes: 26 additions & 8 deletions notifications/views/emailtemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.core.exceptions import PermissionDenied
from django.utils import timezone

from notifications import BDR_GROUP_CODES, ECR_GROUP_CODES
from notifications.forms import (
CycleEmailTemplateEditForm,
CycleEmailTemplateTestForm,
Expand Down Expand Up @@ -264,6 +265,26 @@ def get_sort(self, order, direction):
return '-' + sorting[order]
return sorting[order]

def get_companies_ecr(self, companies, order):
return companies.filter(personcompany__current=True).values_list('external_id', 'name',
'personcompany__person__name', 'personcompany__person__email').extra(
select={
'integer_external_id': 'CAST(external_id AS INTEGER)',
'lower_name':'lower(name)',
'lower_personcompany__person__name': 'personcompany__person__name',
'lower_personcompany__person__email': 'personcompany__person__email'
}).order_by(order)

def get_companies_bdr(self, companies, order):
return companies.filter(personcompany__current=True).values_list('external_id', 'name',
'personcompany__person__name', 'personcompany__person__email').extra(
select={
'integer_external_id': 'external_id',
'lower_name':'lower(name)',
'lower_personcompany__person__name': 'personcompany__person__name',
'lower_personcompany__person__email': 'personcompany__person__email'
}).order_by(order)

def get_data(self, context):
order = self.request.POST.get('order[0][column]')
direction = self.request.POST.get('order[0][dir]')
Expand All @@ -274,14 +295,11 @@ def get_data(self, context):
if self.object.is_triggered:
companies = Company.objects.filter(notifications__emailtemplate=self.object).all().prefetch_related('personcompany_set')
companies = self.get_recipient_companies(self.request.POST.getlist('filtered_companies[]', None))
companies = companies.filter(personcompany__current=True).values_list('external_id', 'name',
'personcompany__person__name', 'personcompany__person__email').extra(
select={
'integer_external_id': 'CAST(external_id AS INTEGER)',
'lower_name':'lower(name)',
'lower_personcompany__person__name': 'personcompany__person__name',
'lower_personcompany__person__email': 'personcompany__person__email'
}).order_by(order)
if self.object.group.code in BDR_GROUP_CODES:
companies = self.get_companies_bdr(companies, order)
else:
companies = self.get_companies_ecr(companies, order)

if search_value:
companies = companies.annotate(search=SearchVector(
'external_id', 'name', 'personcompany__person__name', 'personcompany__person__email')).filter(search__contains=search_value).distinct()
Expand Down

0 comments on commit 627d3ce

Please sign in to comment.