def test_create_if_needed03( self): # TODO: remove this test when pkstring is removed "PK collision" class TestButton(Button): id_ = Button.generate_id('creme_core', 'test_create_if_needed03') verbose_name = u'Testing purpose' # button = TestButton() old_count = ButtonMenuItem.objects.count() # ButtonMenuItem.create_if_needed('creme_core-test_button', None, button, 15) ButtonMenuItem.create_if_needed('creme_core-test_button', None, TestButton, 15) self.assertEqual(old_count + 1, ButtonMenuItem.objects.count()) TestButton.id_ = Button.generate_id('creme_core', 'test_create_if_needed03_bis') with self.assertNoException(): # ButtonMenuItem.create_if_needed('creme_core-test_button', None, button, 15) ButtonMenuItem.create_if_needed('creme_core-test_button', None, TestButton, 15) self.assertEqual(old_count + 1, ButtonMenuItem.objects.count())
def test_button(self): self.login() ButtonMenuItem.create_if_needed(pk='vcfs-test_button', model=Contact, button=GenerateVcfButton, order=100, ) contact = self.create_contact() response = self.assertGET200(contact.get_absolute_url()) self.assertTemplateUsed(response, GenerateVcfButton.template_name)
def test_create_if_needed02(self): "Default config (content_type=None)" class TestButton(Button): id_ = Button.generate_id('creme_core', 'test_create_if_needed02') verbose_name = 'Testing purpose' old_count = ButtonMenuItem.objects.count() bmi = ButtonMenuItem.create_if_needed('creme_core-test_button', None, TestButton, 15) self.assertEqual(old_count + 1, ButtonMenuItem.objects.count()) self.assertIsNone(bmi.content_type)
def test_create_if_needed01(self): pk = 'creme_core-test_button' self.assertFalse(ButtonMenuItem.objects.filter(pk=pk)) class TestButton(Button): id_ = Button.generate_id('creme_core', 'test_create_if_needed01') verbose_name = 'Testing purpose' order = 10 ButtonMenuItem.create_if_needed(pk, FakeContact, TestButton, order) bmi = self.get_object_or_fail(ButtonMenuItem, pk=pk) self.assertEqual(FakeContact, bmi.content_type.model_class()) self.assertEqual(TestButton.id_, bmi.button_id) self.assertEqual(order, bmi.order) old_count = ButtonMenuItem.objects.count() bmi = ButtonMenuItem.create_if_needed(pk, FakeContact, TestButton, order + 5) self.assertEqual(order, bmi.order) self.assertEqual(old_count, ButtonMenuItem.objects.count())
def save(self): button_ids = self.cleaned_data['button_ids'] ct = self.ct BMI_objects = ButtonMenuItem.objects BMI_get = BMI_objects.get items_2_save = [] if not button_ids: # No pk to BMI objects --> can delete() on queryset directly BMI_objects.filter(content_type=ct).delete() # No button for this content type -> fake button_id items_2_save.append( ButtonMenuItem(content_type=ct, button_id='', order=1)) else: old_ids = {bmi.button_id for bmi in self.set_buttons} new_ids = set(button_ids) buttons_2_del = old_ids - new_ids buttons_2_add = new_ids - old_ids # No pk to BCI objects --> can delete() on queryset directly BMI_objects.filter(content_type=ct, button_id__in=buttons_2_del).delete() offset = 1 if ct is None else 1000 # Default conf before ct's conf for i, button_id in enumerate(button_ids): if button_id in buttons_2_add: items_2_save.append( ButtonMenuItem(content_type=ct, button_id=button_id, order=i + offset)) else: bmi = BMI_get(content_type=ct, button_id=button_id) if bmi.order != i + offset: bmi.order = i + offset bmi.save() generate_string_id_and_save(ButtonMenuItem, items_2_save, _PREFIX)
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 save(self, commit=True): bmi = ButtonMenuItem(content_type=self.cleaned_data['ctype'], button_id='', order=1) if commit: bmi.save() return bmi
def populate(self): already_populated = RelationType.objects.filter(pk=constants.REL_SUB_SOLD_BY).exists() Act = commercial.get_act_model() ActObjectivePattern = commercial.get_pattern_model() Strategy = commercial.get_strategy_model() Contact = persons.get_contact_model() Organisation = persons.get_organisation_model() RelationType.create((constants.REL_SUB_SOLD_BY, _(u'has sold')), (constants.REL_OBJ_SOLD_BY, _(u'has been sold by'))) RelationType.create((constants.REL_SUB_COMPLETE_GOAL, _(u'completes a goal of the commercial action')), (constants.REL_OBJ_COMPLETE_GOAL, _(u'is completed thanks to'), [Act])) # --------------------------- CremePropertyType.create(constants.PROP_IS_A_SALESMAN, _(u'is a salesman'), [Contact]) # --------------------------- MarketSegment.objects.get_or_create(property_type=None, defaults={'name': _(u'All the organisations')}, ) # --------------------------- for i, title in enumerate([_(u'Phone calls'), _(u'Show'), _(u'Demo')], start=1): create_if_needed(ActType, {'pk': i}, title=title, is_custom=False) # --------------------------- create_hf = HeaderFilter.create create_hf(pk=constants.DEFAULT_HFILTER_ACT, model=Act, name=_(u'Com Action view'), cells_desc=[(EntityCellRegularField, {'name': 'name'}), (EntityCellRegularField, {'name': 'expected_sales'}), (EntityCellRegularField, {'name': 'due_date'}), ], ) create_hf(pk=constants.DEFAULT_HFILTER_STRATEGY, model=Strategy, name=_(u"Strategy view"), cells_desc=[(EntityCellRegularField, {'name': 'name'})], ) create_hf(pk=constants.DEFAULT_HFILTER_PATTERN, model=ActObjectivePattern, name=_(u"Objective pattern view"), cells_desc=[(EntityCellRegularField, {'name': 'name'}), (EntityCellRegularField, {'name': 'segment'}), ] ) # --------------------------- create_searchconf = SearchConfigItem.create_if_needed create_searchconf(Act, ['name', 'expected_sales', 'cost', 'goal']) create_searchconf(Strategy, ['name']) create_searchconf(ActObjectivePattern, [], disabled=True) # --------------------------- SettingValue.objects.get_or_create(key_id=setting_keys.orga_approaches_key.id, defaults={'value': True}) # --------------------------- Job.objects.get_or_create(type_id=creme_jobs.com_approaches_emails_send_type.id, defaults={'language': settings.LANGUAGE_CODE, 'periodicity': date_period_registry.get_period('days', 1), 'status': Job.STATUS_OK, } ) # --------------------------- if not already_populated: ButtonMenuItem.create_if_needed(pk='commercial-complete_goal_button', model=None, button=buttons.CompleteGoalButton, order=60, ) create_bdl = BrickDetailviewLocation.create_if_needed TOP = BrickDetailviewLocation.TOP RIGHT = BrickDetailviewLocation.RIGHT LEFT = BrickDetailviewLocation.LEFT create_bdl(brick_id=bricks.ApproachesBrick.id_, order=10, zone=RIGHT) create_bdl(brick_id=bricks.ApproachesBrick.id_, order=10, zone=RIGHT, model=Contact) create_bdl(brick_id=bricks.ApproachesBrick.id_, order=10, zone=RIGHT, model=Organisation) BrickDetailviewLocation.create_4_model_brick( order=5, zone=LEFT, model=Act) create_bdl(brick_id=bricks.ActObjectivesBrick.id_, order=10, zone=LEFT, model=Act) create_bdl(brick_id=bricks.RelatedOpportunitiesBrick.id_, order=20, zone=LEFT, model=Act) create_bdl(brick_id=core_bricks.CustomFieldsBrick.id_, order=40, zone=LEFT, model=Act) create_bdl(brick_id=core_bricks.PropertiesBrick.id_, order=450, zone=LEFT, model=Act) create_bdl(brick_id=core_bricks.RelationsBrick.id_, order=500, zone=LEFT, model=Act) create_bdl(brick_id=core_bricks.HistoryBrick.id_, order=20, zone=RIGHT, model=Act) create_bdl(brick_id=bricks.PatternComponentsBrick.id_, order=10, zone=TOP, model=ActObjectivePattern) BrickDetailviewLocation.create_4_model_brick( order=5, zone=LEFT, model=ActObjectivePattern) create_bdl(brick_id=core_bricks.CustomFieldsBrick.id_, order=40, zone=LEFT, model=ActObjectivePattern) create_bdl(brick_id=core_bricks.PropertiesBrick.id_, order=450, zone=LEFT, model=ActObjectivePattern) create_bdl(brick_id=core_bricks.RelationsBrick.id_, order=500, zone=LEFT, model=ActObjectivePattern) create_bdl(brick_id=core_bricks.HistoryBrick.id_, order=20, zone=RIGHT, model=ActObjectivePattern) create_bdl(brick_id=bricks.SegmentDescriptionsBrick.id_, order=10, zone=TOP, model=Strategy) BrickDetailviewLocation.create_4_model_brick( order=5, zone=LEFT, model=Strategy) create_bdl(brick_id=core_bricks.CustomFieldsBrick.id_, order=40, zone=LEFT, model=Strategy) create_bdl(brick_id=bricks.EvaluatedOrgasBrick.id_, order=50, zone=LEFT, model=Strategy) create_bdl(brick_id=bricks.AssetsBrick.id_, order=60, zone=LEFT, model=Strategy) create_bdl(brick_id=bricks.CharmsBrick.id_, order=70, zone=LEFT, model=Strategy) create_bdl(brick_id=core_bricks.PropertiesBrick.id_, order=450, zone=LEFT, model=Strategy) create_bdl(brick_id=core_bricks.RelationsBrick.id_, order=500, zone=LEFT, model=Strategy) create_bdl(brick_id=core_bricks.HistoryBrick.id_, order=20, zone=RIGHT, model=Strategy) 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 assistants_bricks for model in (Act, ActObjectivePattern, Strategy): create_bdl(brick_id=assistants_bricks.TodosBrick.id_, order=100, zone=RIGHT, model=model) create_bdl(brick_id=assistants_bricks.MemosBrick.id_, order=200, zone=RIGHT, model=model) create_bdl(brick_id=assistants_bricks.AlertsBrick.id_, order=300, zone=RIGHT, model=model) create_bdl(brick_id=assistants_bricks.UserMessagesBrick.id_, order=400, zone=RIGHT, model=model) if apps.is_installed('creme.documents'): # logger.info("Documents app is installed => we use the documents blocks on Strategy's detail views") from creme.documents.bricks import LinkedDocsBrick for model in (Act, ActObjectivePattern, Strategy): create_bdl(brick_id=LinkedDocsBrick.id_, order=600, zone=RIGHT, model=model)
def save(self): bmi = ButtonMenuItem(content_type=self.cleaned_data['ctype'], button_id='', order=1) generate_string_id_and_save(ButtonMenuItem, [bmi], _PREFIX)