Last active
April 23, 2020 11:19
-
-
Save sekharpanja/f0e02a2cc175e0a648b587b61e840f43 to your computer and use it in GitHub Desktop.
Model changes to incorporate export pipeline models into existing company lists.
This file contains hidden or 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
| from uuid import uuid4 | |
| from django.conf import settings | |
| from django.db import models | |
| from datahub.core.models import BaseModel | |
| from datahub.core.utils import StrEnum | |
| class AbstractCompanyListBase(BaseModel): | |
| """Abstract base model for user-created list of companies.""" | |
| id = models.UUIDField(primary_key=True, default=uuid4) | |
| name = models.CharField(max_length=settings.CHAR_FIELD_MAX_LENGTH) | |
| adviser = models.ForeignKey( | |
| 'company.Advisor', | |
| on_delete=models.CASCADE, | |
| related_name='company_lists', | |
| ) | |
| def __str__(self): | |
| """Human-friendly representation.""" | |
| return f'{self.name} – {self.adviser}' | |
| class Meta: | |
| abstract = True | |
| class AbstractCompanyListItemBase(BaseModel): | |
| """Abstract base model for holding items on a user's personal list of companies.""" | |
| id = models.UUIDField(primary_key=True, default=uuid4) | |
| list = models.ForeignKey(CompanyList, models.CASCADE, related_name='items') | |
| company = models.ForeignKey( | |
| 'company.Company', | |
| on_delete=models.CASCADE, | |
| related_name='company_list_items', | |
| ) | |
| class Meta: | |
| abstract = True | |
| constraints = [ | |
| models.UniqueConstraint( | |
| fields=('list', 'company'), | |
| name='unique_list_and_company', | |
| ), | |
| ] | |
| class CompanyList(AbstractCompanyListBase): | |
| """ | |
| A user-created list of companies. | |
| (List contents are stored in the separate CompanyListItem model.) | |
| """ | |
| def __str__(self): | |
| """Human-friendly representation.""" | |
| return f'Company List: {self.name} – {self.adviser}' | |
| class CompanyListItemPermissionCode(StrEnum): | |
| """CompanyListItem permission codename constants.""" | |
| view_company_list_item = 'view_companylistitem' | |
| add_company_list_item = 'add_companylistitem' | |
| change_company_list_item = 'change_companylistitem' | |
| delete_company_list_item = 'delete_companylistitem' | |
| class CompanyListItem(AbstractCompanyListItemBase): | |
| """ | |
| An item on a user's personal list of companies. | |
| Each company can appear only once for a particular user. | |
| Note that the primary key is not exposed via the API. | |
| """ | |
| def __str__(self): | |
| """Human-friendly representation.""" | |
| return f'{self.company} – {self.list}' | |
| class ExportPipelineList(AbstractCompanyListBase): | |
| """ | |
| Model holding export pipeline list for each Adviser. | |
| This is required to distinguish pipeline lists from Company lists | |
| and to avoid exposing pipeline lists within My Company Lists. | |
| """ | |
| def __str__(self): | |
| """Human-friendly representation.""" | |
| return f'Export pipeline list: {self.name} – {self.adviser}' | |
| class ExportPipelineListItem(AbstractCompanyListItemBase): | |
| """ | |
| Model holding pipeline list items. | |
| """ | |
| class Status(models.TextChoices): | |
| LEADS = ('leads', 'Leads') | |
| IN_PROGRESS = ('in_progress', 'In progress') | |
| EXPORT_WINS = ('export_wins', 'Export wins') | |
| status = models.CharField( | |
| max_length=settings.CHAR_FIELD_MAX_LENGTH, | |
| choices=Status.choices, | |
| ) | |
| def __str__(self): | |
| """Human-friendly representation.""" | |
| return f'{self.company} – {self.list} - {self.status}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment