def all_apps_ready(self): from creme import emails self.EmailCampaign = emails.get_emailcampaign_model() self.EmailTemplate = emails.get_emailtemplate_model() self.EntityEmail = emails.get_entityemail_model() self.MailingList = emails.get_mailinglist_model() super().all_apps_ready() from . import signals # NOQA
def populate(self): already_populated = RelationType.objects.filter( pk=constants.REL_SUB_MAIL_RECEIVED).exists() EmailCampaign = emails.get_emailcampaign_model() EmailTemplate = emails.get_emailtemplate_model() EntityEmail = emails.get_entityemail_model() MailingList = emails.get_mailinglist_model() Contact = persons.get_contact_model() Organisation = persons.get_organisation_model() # --------------------------- SettingValue.objects.get_or_create(key_id=emailcampaign_sender.id, defaults={'value': ''}) # --------------------------- RelationType.create((constants.REL_SUB_MAIL_RECEIVED, _('(email) received by'), [EntityEmail]), (constants.REL_OBJ_MAIL_RECEIVED, _('received the email'), [Organisation, Contact])) RelationType.create((constants.REL_SUB_MAIL_SENDED, _('(email) sent by'), [EntityEmail]), (constants.REL_OBJ_MAIL_SENDED, _('sent the email'), [Organisation, Contact])) RelationType.create( (constants.REL_SUB_RELATED_TO, _('(email) related to'), [EntityEmail]), (constants.REL_OBJ_RELATED_TO, _('related to the email'), [])) # --------------------------- create_hf = HeaderFilter.create create_hf( pk=constants.DEFAULT_HFILTER_MAILINGLIST, model=MailingList, name=_('Mailing list view'), cells_desc=[(EntityCellRegularField, { 'name': 'name' })], ) create_hf( pk=constants.DEFAULT_HFILTER_CAMPAIGN, model=EmailCampaign, name=_('Campaign view'), cells_desc=[(EntityCellRegularField, { 'name': 'name' })], ) create_hf( pk=constants.DEFAULT_HFILTER_TEMPLATE, model=EmailTemplate, name=_('Email template view'), cells_desc=[ (EntityCellRegularField, { 'name': 'name' }), (EntityCellRegularField, { 'name': 'subject' }), ], ) create_hf( pk=constants.DEFAULT_HFILTER_EMAIL, model=EntityEmail, name=_('Email view'), cells_desc=[ (EntityCellRegularField, { 'name': 'sender' }), (EntityCellRegularField, { 'name': 'recipient' }), (EntityCellRegularField, { 'name': 'subject' }), ], ) # --------------------------- create_searchconf = SearchConfigItem.create_if_needed create_searchconf(EmailCampaign, ['name', 'mailing_lists__name']) create_searchconf(MailingList, [ 'name', 'children__name', 'contacts__first_name', 'contacts__last_name', 'organisations__name' ]) create_searchconf(EmailTemplate, ['name', 'subject', 'body', 'attachments__title']) create_searchconf(EntityEmail, ['sender', 'recipient', 'subject']) # --------------------------- create_job = Job.objects.get_or_create create_job(type_id=entity_emails_send_type.id, defaults={ 'language': settings.LANGUAGE_CODE, 'status': Job.STATUS_OK, }) create_job(type_id=campaign_emails_send_type.id, defaults={ 'language': settings.LANGUAGE_CODE, 'status': Job.STATUS_OK, }) # --------------------------- if not already_populated: create_cbci = CustomBrickConfigItem.objects.create build_cell = EntityCellRegularField.build cbci_email = create_cbci( id='emails-entityemail_info', name=_('Email information'), content_type=EntityEmail, cells=[ build_cell(EntityEmail, 'user'), build_cell(EntityEmail, 'reads'), build_cell(EntityEmail, 'status'), build_cell(EntityEmail, 'sender'), build_cell(EntityEmail, 'recipient'), build_cell(EntityEmail, 'subject'), build_cell(EntityEmail, 'reception_date'), build_cell(EntityEmail, 'attachments'), build_cell(EntityEmail, 'body'), build_cell(EntityEmail, 'description'), ], ) cbci_template = create_cbci( id='emails-emailtemplate_info', name=_('Email template information'), content_type=EmailTemplate, cells=[ build_cell(EmailTemplate, 'created'), build_cell(EmailTemplate, 'modified'), build_cell(EmailTemplate, 'user'), build_cell(EmailTemplate, 'name'), build_cell(EmailTemplate, 'subject'), build_cell(EmailTemplate, 'body'), build_cell(EmailTemplate, 'signature'), build_cell(EmailTemplate, 'description'), ], ) create_bdl = BrickDetailviewLocation.objects.create_if_needed create_bdl_4_model = BrickDetailviewLocation.objects.create_for_model_brick TOP = BrickDetailviewLocation.TOP LEFT = BrickDetailviewLocation.LEFT RIGHT = BrickDetailviewLocation.RIGHT create_bdl(brick=cbci_email.generate_id(), order=5, zone=LEFT, model=EntityEmail) create_bdl(brick=bricks.EmailHTMLBodyBrick, order=20, zone=LEFT, model=EntityEmail) create_bdl(brick=core_bricks.CustomFieldsBrick, order=40, zone=LEFT, model=EntityEmail) create_bdl(brick=core_bricks.PropertiesBrick, order=450, zone=LEFT, model=EntityEmail) create_bdl(brick=core_bricks.RelationsBrick, order=500, zone=LEFT, model=EntityEmail) create_bdl(brick=core_bricks.HistoryBrick, order=20, zone=RIGHT, model=EntityEmail) create_bdl_4_model(order=5, zone=LEFT, model=MailingList) create_bdl(brick=core_bricks.CustomFieldsBrick, order=40, zone=LEFT, model=MailingList) create_bdl(brick=bricks.EmailRecipientsBrick, order=80, zone=LEFT, model=MailingList) create_bdl(brick=bricks.ContactsBrick, order=90, zone=LEFT, model=MailingList) create_bdl(brick=bricks.OrganisationsBrick, order=95, zone=LEFT, model=MailingList) create_bdl(brick=bricks.ChildListsBrick, order=100, zone=LEFT, model=MailingList) create_bdl(brick=bricks.ParentListsBrick, order=105, zone=LEFT, model=MailingList) create_bdl(brick=core_bricks.PropertiesBrick, order=450, zone=LEFT, model=MailingList) create_bdl(brick=core_bricks.RelationsBrick, order=500, zone=LEFT, model=MailingList) create_bdl(brick=core_bricks.HistoryBrick, order=20, zone=RIGHT, model=MailingList) create_bdl(brick=bricks.SendingsBrick, order=2, zone=TOP, model=EmailCampaign) create_bdl_4_model(order=5, zone=LEFT, model=EmailCampaign) create_bdl(brick=core_bricks.CustomFieldsBrick, order=40, zone=LEFT, model=EmailCampaign) create_bdl(brick=bricks.MailingListsBrick, order=120, zone=LEFT, model=EmailCampaign) create_bdl(brick=core_bricks.PropertiesBrick, order=450, zone=LEFT, model=EmailCampaign) create_bdl(brick=core_bricks.RelationsBrick, order=500, zone=LEFT, model=EmailCampaign) create_bdl(brick=core_bricks.HistoryBrick, order=20, zone=RIGHT, model=EmailCampaign) create_bdl(brick=cbci_template.generate_id(), order=5, zone=LEFT, model=EmailTemplate) create_bdl(brick=core_bricks.CustomFieldsBrick, order=40, zone=LEFT, model=EmailTemplate) create_bdl(brick=bricks.AttachmentsBrick, order=60, zone=LEFT, model=EmailTemplate) create_bdl(brick=bricks.TemplateHTMLBodyBrick, order=70, zone=LEFT, model=EmailTemplate) create_bdl(brick=core_bricks.PropertiesBrick, order=450, zone=LEFT, model=EmailTemplate) create_bdl(brick=core_bricks.RelationsBrick, order=500, zone=LEFT, model=EmailTemplate) create_bdl(brick=core_bricks.HistoryBrick, order=20, zone=RIGHT, model=EmailTemplate) # 'persons' app create_bdl(brick=bricks.MailsHistoryBrick, order=600, zone=RIGHT, model=Contact) create_bdl(brick=bricks.MailsHistoryBrick, order=600, zone=RIGHT, model=Organisation) if apps.is_installed('creme.assistants'): logger.info( 'Assistants app is installed => we use the assistants blocks on detail views' ) from creme.assistants import bricks as a_bricks for model in (MailingList, EmailCampaign, EmailTemplate): create_bdl(brick=a_bricks.TodosBrick, order=100, zone=RIGHT, model=model) create_bdl(brick=a_bricks.MemosBrick, order=200, zone=RIGHT, model=model) create_bdl(brick=a_bricks.AlertsBrick, order=300, zone=RIGHT, model=model) create_bdl(brick=a_bricks.UserMessagesBrick, order=400, zone=RIGHT, model=model) if apps.is_installed('creme.documents'): # logger.info("Documents app is installed => we use the documents block on EmailCampaign's detail view") from creme.documents.bricks import LinkedDocsBrick create_bdl(brick=LinkedDocsBrick, order=600, zone=RIGHT, model=EmailCampaign) # --------------------------- ButtonMenuItem.create_if_needed( pk='emails-entity_email_link_button', model=EntityEmail, button=buttons.EntityEmailLinkButton, order=20)
def populate(self): already_populated = RelationType.objects.filter( pk=constants.REL_SUB_MAIL_RECEIVED, ).exists() EmailCampaign = emails.get_emailcampaign_model() EmailTemplate = emails.get_emailtemplate_model() EntityEmail = emails.get_entityemail_model() MailingList = emails.get_mailinglist_model() Contact = persons.get_contact_model() Organisation = persons.get_organisation_model() # --------------------------- SettingValue.objects.get_or_create( key_id=emailcampaign_sender.id, defaults={'value': ''}, ) # --------------------------- RelationType.create( (constants.REL_SUB_MAIL_RECEIVED, _('(email) received by'), [EntityEmail]), (constants.REL_OBJ_MAIL_RECEIVED, _('received the email'), [Organisation, Contact]), ) RelationType.create( (constants.REL_SUB_MAIL_SENDED, _('(email) sent by'), [EntityEmail]), (constants.REL_OBJ_MAIL_SENDED, _('sent the email'), [Organisation, Contact]), ) RelationType.create( (constants.REL_SUB_RELATED_TO, _('(email) related to'), [EntityEmail]), (constants.REL_OBJ_RELATED_TO, _('related to the email'), []), ) # --------------------------- create_hf = HeaderFilter.objects.create_if_needed create_hf( pk=constants.DEFAULT_HFILTER_MAILINGLIST, model=MailingList, name=_('Mailing list view'), cells_desc=[(EntityCellRegularField, { 'name': 'name' })], ) create_hf( pk=constants.DEFAULT_HFILTER_CAMPAIGN, model=EmailCampaign, name=_('Campaign view'), cells_desc=[(EntityCellRegularField, { 'name': 'name' })], ) create_hf( pk=constants.DEFAULT_HFILTER_TEMPLATE, model=EmailTemplate, name=_('Email template view'), cells_desc=[ (EntityCellRegularField, { 'name': 'name' }), (EntityCellRegularField, { 'name': 'subject' }), ], ) create_hf( pk=constants.DEFAULT_HFILTER_EMAIL, model=EntityEmail, name=_('Email view'), cells_desc=[ (EntityCellRegularField, { 'name': 'sender' }), (EntityCellRegularField, { 'name': 'recipient' }), (EntityCellRegularField, { 'name': 'subject' }), ], ) # --------------------------- common_groups_desc = [ { 'name': _('Description'), 'cells': [ (EntityCellRegularField, { 'name': 'description' }), ], }, { 'name': _('Custom fields'), 'cells': [ ( EntityCellCustomFormSpecial, { 'name': EntityCellCustomFormSpecial.REMAINING_CUSTOMFIELDS }, ), ], }, ] def build_creation_custom_form_items(descriptor, field_names): CustomFormConfigItem.objects.create_if_needed( descriptor=descriptor, groups_desc=[ { 'name': _('General information'), 'cells': [ *((EntityCellRegularField, { 'name': fname }) for fname in field_names), ( EntityCellCustomFormSpecial, { 'name': EntityCellCustomFormSpecial. REMAINING_REGULARFIELDS }, ), ], }, *common_groups_desc, { 'name': _('Properties'), 'cells': [ ( EntityCellCustomFormSpecial, { 'name': EntityCellCustomFormSpecial. CREME_PROPERTIES }, ), ], }, { 'name': _('Relationships'), 'cells': [ ( EntityCellCustomFormSpecial, { 'name': EntityCellCustomFormSpecial.RELATIONS }, ), ], }, ], ) def build_edition_custom_form_items(descriptor, field_names): CustomFormConfigItem.objects.create_if_needed( descriptor=descriptor, groups_desc=[ { 'name': _('General information'), 'cells': [ *((EntityCellRegularField, { 'name': fname }) for fname in field_names), ( EntityCellCustomFormSpecial, { 'name': EntityCellCustomFormSpecial. REMAINING_REGULARFIELDS }, ), ], }, *common_groups_desc, ], ) build_creation_custom_form_items( descriptor=custom_forms.CAMPAIGN_CREATION_CFORM, field_names=[ 'user', 'name', 'mailing_lists', ], ) build_edition_custom_form_items( descriptor=custom_forms.CAMPAIGN_EDITION_CFORM, field_names=[ 'user', 'name', # 'mailing_lists', ], ) template_field_names = [ 'user', 'name', 'subject', 'body', 'body_html', 'signature', 'attachments', ] build_creation_custom_form_items( descriptor=custom_forms.TEMPLATE_CREATION_CFORM, field_names=template_field_names, ) build_edition_custom_form_items( descriptor=custom_forms.TEMPLATE_EDITION_CFORM, field_names=template_field_names, ) mlist_field_names = ['user', 'name'] build_creation_custom_form_items( descriptor=custom_forms.MAILINGLIST_CREATION_CFORM, field_names=mlist_field_names, ) build_edition_custom_form_items( descriptor=custom_forms.MAILINGLIST_EDITION_CFORM, field_names=mlist_field_names, ) # --------------------------- create_searchconf = SearchConfigItem.objects.create_if_needed create_searchconf( EmailCampaign, ['name', 'mailing_lists__name'], ) create_searchconf( MailingList, [ 'name', 'children__name', 'contacts__first_name', 'contacts__last_name', 'organisations__name', ], ) create_searchconf( EmailTemplate, ['name', 'subject', 'body', 'attachments__title'], ) create_searchconf( EntityEmail, ['sender', 'recipient', 'subject'], ) # --------------------------- create_job = Job.objects.get_or_create create_job( type_id=entity_emails_send_type.id, defaults={ 'language': settings.LANGUAGE_CODE, 'status': Job.STATUS_OK, }, ) create_job( type_id=campaign_emails_send_type.id, defaults={ 'language': settings.LANGUAGE_CODE, 'status': Job.STATUS_OK, }, ) # --------------------------- # TODO: move to "not already_populated" section in creme2.4 if not MenuConfigItem.objects.filter( entry_id__startswith='emails-').exists(): container = MenuConfigItem.objects.get_or_create( entry_id=ContainerEntry.id, entry_data={'label': _('Marketing')}, defaults={'order': 200}, )[0] create_mitem = partial(MenuConfigItem.objects.create, parent=container) create_mitem(entry_id=menu.EmailCampaignsEntry.id, order=10) create_mitem(entry_id=menu.MailingListsEntry.id, order=15) create_mitem(entry_id=menu.EmailTemplatesEntry.id, order=20) create_mitem(entry_id=menu.EntityEmailsEntry.id, order=25) sync_entry_id = menu.EmailSyncEntry.id if sync_entry_id: create_mitem(entry_id=sync_entry_id, order=30) # --------------------------- if not already_populated: create_cbci = CustomBrickConfigItem.objects.create build_cell = EntityCellRegularField.build cbci_email = create_cbci( id='emails-entityemail_info', name=_('Email information'), content_type=EntityEmail, cells=[ build_cell(EntityEmail, 'user'), build_cell(EntityEmail, 'reads'), build_cell(EntityEmail, 'status'), build_cell(EntityEmail, 'sender'), build_cell(EntityEmail, 'recipient'), build_cell(EntityEmail, 'subject'), build_cell(EntityEmail, 'reception_date'), build_cell(EntityEmail, 'attachments'), build_cell(EntityEmail, 'body'), build_cell(EntityEmail, 'description'), ], ) cbci_template = create_cbci( id='emails-emailtemplate_info', name=_('Email template information'), content_type=EmailTemplate, cells=[ build_cell(EmailTemplate, 'created'), build_cell(EmailTemplate, 'modified'), build_cell(EmailTemplate, 'user'), build_cell(EmailTemplate, 'name'), build_cell(EmailTemplate, 'subject'), build_cell(EmailTemplate, 'body'), build_cell(EmailTemplate, 'signature'), build_cell(EmailTemplate, 'description'), ], ) TOP = BrickDetailviewLocation.TOP LEFT = BrickDetailviewLocation.LEFT RIGHT = BrickDetailviewLocation.RIGHT BrickDetailviewLocation.objects.multi_create( defaults={ 'model': EntityEmail, 'zone': LEFT }, data=[ { 'brick': cbci_email.brick_id, 'order': 5 }, { 'brick': bricks.EmailHTMLBodyBrick, 'order': 20 }, { 'brick': core_bricks.CustomFieldsBrick, 'order': 40 }, { 'brick': core_bricks.PropertiesBrick, 'order': 450 }, { 'brick': core_bricks.RelationsBrick, 'order': 500 }, { 'brick': core_bricks.HistoryBrick, 'order': 20, 'zone': RIGHT }, ], ) BrickDetailviewLocation.objects.multi_create( defaults={ 'model': MailingList, 'zone': LEFT }, data=[ { 'order': 5 }, { 'brick': core_bricks.CustomFieldsBrick, 'order': 40 }, { 'brick': bricks.EmailRecipientsBrick, 'order': 80 }, { 'brick': bricks.ContactsBrick, 'order': 90 }, { 'brick': bricks.OrganisationsBrick, 'order': 95 }, { 'brick': bricks.ChildListsBrick, 'order': 100 }, { 'brick': bricks.ParentListsBrick, 'order': 105 }, { 'brick': core_bricks.PropertiesBrick, 'order': 450 }, { 'brick': core_bricks.RelationsBrick, 'order': 500 }, { 'brick': core_bricks.HistoryBrick, 'order': 20, 'zone': RIGHT }, ], ) BrickDetailviewLocation.objects.multi_create( defaults={ 'model': EmailCampaign, 'zone': LEFT }, data=[ { 'brick': bricks.SendingsBrick, 'order': 2, 'zone': TOP }, { 'order': 5 }, { 'brick': core_bricks.CustomFieldsBrick, 'order': 40 }, { 'brick': bricks.MailingListsBrick, 'order': 120 }, { 'brick': core_bricks.PropertiesBrick, 'order': 450 }, { 'brick': core_bricks.RelationsBrick, 'order': 500 }, { 'brick': core_bricks.HistoryBrick, 'order': 20, 'zone': RIGHT }, ], ) BrickDetailviewLocation.objects.multi_create( defaults={ 'model': EmailTemplate, 'zone': LEFT }, data=[ { 'brick': cbci_template.brick_id, 'order': 5 }, { 'brick': core_bricks.CustomFieldsBrick, 'order': 40 }, { 'brick': bricks.AttachmentsBrick, 'order': 60 }, { 'brick': bricks.TemplateHTMLBodyBrick, 'order': 70 }, { 'brick': core_bricks.PropertiesBrick, 'order': 450 }, { 'brick': core_bricks.RelationsBrick, 'order': 500 }, { 'brick': core_bricks.HistoryBrick, 'order': 20, 'zone': RIGHT }, ], ) # 'persons' app BrickDetailviewLocation.objects.multi_create( defaults={ 'brick': bricks.MailsHistoryBrick, 'order': 600, 'zone': RIGHT }, data=[ { 'model': Contact }, { 'model': Organisation }, ], ) if apps.is_installed('creme.assistants'): logger.info( 'Assistants app is installed => we use the assistants blocks on detail views' ) from creme.assistants import bricks as a_bricks for model in (MailingList, EmailCampaign, EmailTemplate): BrickDetailviewLocation.objects.multi_create( defaults={ 'model': model, 'zone': RIGHT }, data=[ { 'brick': a_bricks.TodosBrick, 'order': 100 }, { 'brick': a_bricks.MemosBrick, 'order': 200 }, { 'brick': a_bricks.AlertsBrick, 'order': 300 }, { 'brick': a_bricks.UserMessagesBrick, 'order': 400 }, ], ) if apps.is_installed('creme.documents'): # logger.info("Documents app is installed # => we use the documents block on EmailCampaign's detail view") from creme.documents.bricks import LinkedDocsBrick BrickDetailviewLocation.objects.create_if_needed( brick=LinkedDocsBrick, order=600, zone=RIGHT, model=EmailCampaign, ) # --------------------------- ButtonMenuItem.objects.create_if_needed( model=EntityEmail, button=buttons.EntityEmailLinkButton, order=20, )
from django.urls import reverse from django.utils.translation import gettext_lazy as _ from creme.creme_core.gui.bricks import Brick, SimpleBrick, QuerysetBrick from creme.creme_core.models import CremeEntity, Relation from creme import documents, persons, emails from . import constants from .models import EmailSignature, EmailRecipient, EmailSending, LightWeightEmail Document = documents.get_document_model() Contact = persons.get_contact_model() Organisation = persons.get_organisation_model() EmailTemplate = emails.get_emailtemplate_model() EmailCampaign = emails.get_emailcampaign_model() EntityEmail = emails.get_entityemail_model() MailingList = emails.get_mailinglist_model() class EntityEmailBarHatBrick(SimpleBrick): # NB: we do not set an ID because it's the main Header Brick. template_name = 'emails/bricks/mail-hat-bar.html' class _HTMLBodyBrick(Brick): verbose_name = _('HTML body') template_name = 'emails/bricks/html-body.html' def _get_body_url(self, instance): return reverse('creme_core__sanitized_html_field',