예제 #1
0
class GenerateVcfButton(Button):
    id_ = Button.generate_id('vcfs', 'generate_vcf')
    verbose_name = _('Generate a VCF')
    template_name = 'vcfs/buttons/generate.html'

    def get_ctypes(self):
        return (get_contact_model(), )
예제 #2
0
    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())
예제 #3
0
class AddRelatedActivityButton(Button):
    id_ = Button.generate_id('activities', 'add_activity')
    template_name = 'activities/buttons/add-related.html'
    # permission = build_creation_perm(Activity)
    permissions = build_creation_perm(Activity)
    verbose_name = _('Create a related activity')
    description = _(
        'This button displays the creation form for activities (meetings, phone calls…). '
        'The current entity is pre-selected to be linked to the created activity.\n'
        'App: Activities')
    activity_type: Optional[str] = None  # None means type is not fixed

    def render(self, context):
        context['activity_type'] = self.activity_type
        context['verbose_name'] = self.verbose_name

        icon_info = constants.ICONS.get(self.activity_type)
        if icon_info:
            name, label = icon_info
        else:
            name = 'calendar'
            label = Activity._meta.verbose_name

        theme = get_current_theme_from_context(context)
        context['icon'] = get_icon_by_name(
            name=name,
            label=label,
            theme=theme,
            size_px=get_icon_size_px(theme=theme, size='instance-button'),
        )

        return super().render(context)
예제 #4
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class EntityEmailLinkButton(Button):
    id_ = Button.generate_id('emails', 'entity_email_link')
    verbose_name = _('Link this email to')
    description = _(
        'This button links the current entity with a selected email, '
        'using a relationship type in:\n'
        ' - «sent the email».\n'
        ' - «received the email».\n'
        ' - «related to the email».\n'
        'App: Emails')
    template_name = 'emails/buttons/entityemail-link.html'
    # permission = build_link_perm(EntityEmail)
    permissions = build_link_perm(EntityEmail)

    rtype_ids = [
        constants.REL_SUB_MAIL_SENDED,
        constants.REL_SUB_MAIL_RECEIVED,
        constants.REL_SUB_RELATED_TO,
    ]

    def get_ctypes(self):
        return (EntityEmail, )

    def render(self, context):
        context['rtypes'] = self.rtype_ids

        return super().render(context)
예제 #5
0
class AddRelatedActivityButton(Button):
    id_ = Button.generate_id('activities', 'add_activity')
    # template_name = 'activities/templatetags/button_add_related.html'
    template_name = 'activities/buttons/add-related.html'
    permission = cperm(Activity)
    verbose_name = _(u'Create a related activity')
    activity_type = None  # None means type is not fixed

    def render(self, context):
        context['activity_type'] = self.activity_type
        context['verbose_name'] = self.verbose_name

        icon_info = constants.ICONS.get(self.activity_type)
        if icon_info:
            name, label = icon_info
        else:
            name = 'calendar'
            label = Activity._meta.verbose_name

        theme = get_current_theme_from_context(context)
        context['icon'] = get_icon_by_name(
            name=name,
            label=label,
            theme=theme,
            size_px=get_icon_size_px(theme=theme, size='instance-button'),
        )

        # return super(AddRelatedActivityButton, self).render(context)
        return super().render(context)
예제 #6
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class BecomeSupplierButton(CrmButton):
    id_ = Button.generate_id('persons', 'become_supplier')
    verbose_name = _('Transform into a supplier')
    description = _(
        'This button links the current entity to an Organisation managed by Creme, '
        'using the relationship type «is a supplier of».\n'
        'App: Accounts and Contacts')
    relation_type_id = constants.REL_OBJ_CUSTOMER_SUPPLIER
예제 #7
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class BecomeProspectButton(CrmButton):
    id_ = Button.generate_id('persons', 'become_prospect')
    verbose_name = _('Transform into a prospect')
    description = _(
        'This button links the current entity to an Organisation managed by Creme, '
        'using the relationship type «is a prospect of».\n'
        'App: Accounts and Contacts')
    relation_type_id = constants.REL_SUB_PROSPECT
예제 #8
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class BecomeInactiveButton(CrmButton):
    id_ = Button.generate_id('persons', 'become_inactive')
    verbose_name = _('Transform into an inactive customer')
    description = _(
        'This button links the current entity to an Organisation managed by Creme, '
        'using the relationship type «is an inactive customer of».\n'
        'App: Accounts and Contacts')
    relation_type_id = constants.REL_SUB_INACTIVE
예제 #9
0
class AddTaskButton(AddRelatedActivityButton):
    id_ = Button.generate_id('activities', 'add_task')
    verbose_name = _('Create a related task')
    description = _(
        'This button displays the creation form for tasks (kind of activity). '
        'The current entity is pre-selected to be linked to the created task.\n'
        'App: Activities')
    activity_type = constants.ACTIVITYTYPE_TASK
예제 #10
0
class AddPhoneCallButton(AddRelatedActivityButton):
    id_ = Button.generate_id('activities', 'add_phonecall')
    verbose_name = _('Create a related phone call')
    description = _(
        'This button displays the creation form for phone calls (kind of activity). '
        'The current entity is pre-selected to be linked to the created phone call.\n'
        'App: Activities')
    activity_type = constants.ACTIVITYTYPE_PHONECALL
예제 #11
0
class LinkedOpportunityButton(Button):
    id_           = Button.generate_id('opportunities', 'linked_opportunity')
    verbose_name  = _('Create a linked opportunity')
    template_name = 'opportunities/buttons/linked-opp.html'
    permission    = cperm(get_opportunity_model())

    def get_ctypes(self):
        from creme import persons
        return (persons.get_organisation_model(), persons.get_contact_model())
예제 #12
0
    def test_button_registry01(self):
        class TestButton1(Button):
            id_ = Button.generate_id('creme_core', 'test_button_registry_1')

        class TestButton2(Button):
            id_ = Button.generate_id('creme_core', 'test_button_registry_2')

            def ok_4_display(self, entity):
                return False

        class TestButton3(Button):
            id_ = Button.generate_id('creme_core', 'test_button_registry_3')

        class TestButton4(Button):
            id_ = Button.generate_id('creme_core', 'test_button_registry_4')

        registry = ButtonsRegistry()
        registry.register(TestButton1, TestButton2, TestButton3, TestButton4)

        class DuplicatedTestButton(Button):
            id_ = TestButton1.id_

        with self.assertRaises(ButtonsRegistry.RegistrationError):
            registry.register(DuplicatedTestButton)

        get = registry.get_button
        self.assertIsInstance(get(TestButton1.id_), TestButton1)
        self.assertIsInstance(get(TestButton2.id_), TestButton2)
        self.assertIsNone(
            get(
                Button.generate_id('creme_core',
                                   'test_button_registry_invalid')))

        c = FakeContact(first_name='Casca', last_name='Mylove')
        buttons = [
            *registry.get_buttons(
                [
                    TestButton3.id_,
                    TestButton2.id_,  # No because ok_4_display() returns False
                    'test_button_registry_invalid',
                    TestButton1.id_,
                ],
                entity=c,
            ),
        ]
        self.assertIsInstance(buttons, list)
        self.assertEqual(2, len(buttons))
        self.assertIsInstance(buttons[0], TestButton3)
        self.assertIsInstance(buttons[1], TestButton1)

        all_button_items = [*registry]
        self.assertEqual(4, len(all_button_items))

        button_item = all_button_items[0]
        self.assertIsInstance(button_item[1], Button)
        self.assertEqual(button_item[0], button_item[1].id_)
예제 #13
0
class ConvertToSalesOrderButton(_ConvertToButton):
    id_ = Button.generate_id('billing', 'convert_to_salesorder')
    verbose_name = _('Convert to Salesorder')
    description = _(
        'This button converts automatically the current entity into an salesorder. '
        'Notice that the current entity is kept unchanged, a new order is created.\n'
        'App: Billing'
    )
    target_model = SalesOrder
    target_modelname = 'sales_order'
예제 #14
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class GenerateVcfButton(Button):
    id_ = Button.generate_id('vcfs', 'generate_vcf')
    verbose_name = _('Generate a VCF file')
    description = _(
        'This button generates a VCF file from the current contact.\n'
        'App: VCF')
    template_name = 'vcfs/buttons/generate.html'

    def get_ctypes(self):
        return (get_contact_model(), )
예제 #15
0
class ConvertToQuoteButton(_ConvertToButton):
    id_ = Button.generate_id('billing', 'convert_to_quote')
    verbose_name = _('Convert to Quote')
    description = _(
        'This button converts automatically the current entity into an quote. '
        'Notice that the current entity is kept unchanged, a new quote is created.\n'
        'App: Billing'
    )
    target_model = Quote
    target_modelname = 'quote'
예제 #16
0
class CompleteGoalButton(Button):
    id_ = Button.generate_id('commercial', 'complete_goal')
    verbose_name = _('Completes a goal (Commercial action)')
    template_name = 'commercial/buttons/complete-goal.html'
    permission = 'commercial'

    def render(self, context):
        context['predicate_id'] = REL_SUB_COMPLETE_GOAL
        context['act_ct'] = ContentType.objects.get_for_model(get_act_model())

        return super().render(context)
예제 #17
0
class AddSalesOrderButton(_AddBillingDocumentButton):
    model_to_create = SalesOrder
    id_ = Button.generate_id('billing', 'add_salesorder')
    verbose_name = _('Create a related salesorder')
    description = _(
        'This button displays the creation form for salesorders. '
        'The current entity is pre-selected to be the target of the created order.\n'
        'App: Billing'
    )
    # permission = cperm(SalesOrder)
    permissions = cperm(SalesOrder)
    url_name = 'billing__create_related_order'
예제 #18
0
class AddInvoiceButton(_AddBillingDocumentButton):
    model_to_create = Invoice
    id_ = Button.generate_id('billing', 'add_invoice')
    verbose_name = _('Create a related invoice')
    description = _(
        'This button displays the creation form for invoices. '
        'The current entity is pre-selected to be the target of the created invoice.\n'
        'App: Billing'
    )
    # permission = cperm(Invoice)
    permissions = cperm(Invoice)
    url_name = 'billing__create_related_invoice'
예제 #19
0
class GenerateInvoiceNumberButton(Button):
    id_ = Button.generate_id('billing', 'generate_invoice_number')
    verbose_name = _('Generate the number of the Invoice')
    template_name = 'billing/buttons/generate-invoice-number.html'

    def get_ctypes(self):
        return (Invoice, )

    def has_perm(self, context):
        return context['user'].has_perm_to_change(context['object'])

    def ok_4_display(self, entity):
        return not bool(entity.number)
예제 #20
0
class AddLinkedContactButton(Button):
    id_ = Button.generate_id('persons', 'add_linked_contact')
    verbose_name = _('Create a related contact')
    template_name = 'persons/buttons/add-linked-contact.html'
    permission = cperm(Contact)  # TODO: 'persons.addrelated_contact' ??

    def get_ctypes(self):
        return (Organisation, )

    def render(self, context):
        context['contact_link_perm'] = context['user'].has_perm_to_link(
            Contact)

        return super().render(context)
예제 #21
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class Linked2TicketButton(Button):
    id_ = Button.generate_id('tickets', 'linked2ticket')
    verbose_name = _('Is linked to a ticket')
    description = _(
        'This button links the current entity to a selected ticket, '
        'using the relationship type «is linked to the ticket».\n'
        'App: Tickets')
    template_name = 'tickets/buttons/linked.html'
    # permission = 'tickets'
    permissions = 'tickets'

    def render(self, context):
        context['rtype_id'] = REL_SUB_LINKED_2_TICKET

        return super().render(context)
예제 #22
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class CompleteGoalButton(Button):
    id_ = Button.generate_id('commercial', 'complete_goal')
    verbose_name = _('Completes a goal (Commercial action)')
    description = _(
        'This button links the current entity with a selected commercial action, '
        'using the relationship type «completes a goal of the commercial action».\n'
        'App: Commercial')
    template_name = 'commercial/buttons/complete-goal.html'
    # permission = 'commercial'
    permissions = 'commercial'

    def render(self, context):
        context['predicate_id'] = REL_SUB_COMPLETE_GOAL
        context['act_ct'] = ContentType.objects.get_for_model(get_act_model())

        return super().render(context)
예제 #23
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class LinkedOpportunityButton(Button):
    id_ = Button.generate_id('opportunities', 'linked_opportunity')
    verbose_name = _('Create a linked opportunity')
    description = _(
        'This button displays the creation form for opportunities. '
        'The current entity is pre-selected to be the target of the created opportunity.\n'
        'App: Opportunities')
    template_name = 'opportunities/buttons/linked-opp.html'
    # permission = cperm(get_opportunity_model())
    permissions = cperm(get_opportunity_model())

    def get_ctypes(self):
        from creme import persons
        return (
            persons.get_organisation_model(),
            persons.get_contact_model(),
        )
예제 #24
0
class EntityEmailLinkButton(Button):
    id_ = Button.generate_id('emails', 'entity_email_link')
    verbose_name = _('Link this email to')
    template_name = 'emails/buttons/entityemail-link.html'
    permission = build_link_perm(EntityEmail)

    rtype_ids = [
        constants.REL_SUB_MAIL_SENDED,
        constants.REL_SUB_MAIL_RECEIVED,
        constants.REL_SUB_RELATED_TO,
    ]

    def get_ctypes(self):
        return (EntityEmail, )

    def render(self, context):
        # context['entity_email_ct_id'] = ContentType.objects.get_for_model(EntityEmail).id
        context['rtypes'] = self.rtype_ids

        return super().render(context)
예제 #25
0
파일: buttons.py 프로젝트: mrjmad/creme_crm
class AddLinkedContactButton(Button):
    id_ = Button.generate_id('persons', 'add_linked_contact')
    verbose_name = _('Create a related contact')
    description = _(
        'This button displays the creation form for contacts. '
        'The current organisation is pre-selected to be linked to the created contact.\n'
        'It is useful to create employees for example '
        '(it can be done through the employees block too).\n'
        'App: Accounts and Contacts')
    template_name = 'persons/buttons/add-linked-contact.html'
    # permission = cperm(Contact)
    permissions = cperm(Contact)  # TODO: 'persons.addrelated_contact' ??

    def get_ctypes(self):
        return (Organisation, )

    def render(self, context):
        context['contact_link_perm'] = context['user'].has_perm_to_link(
            Contact)

        return super().render(context)
예제 #26
0
def _uninstall_buttons(sender, **kwargs):
    # Remove the button of the app (ie the classes of the buttons are defined in the app)
    # Button related to the app's model should be removed when the ContentTypes are removed.
    prefix = Button.generate_id(app_name=sender.label, name='')
    ButtonMenuItem.objects.filter(button_id__startswith=prefix).delete()
예제 #27
0
class TestButton05(_TestButton):
    id_ = Button.generate_id('creme_core', 'test_ttags_creme_menu05')
    action_id = 'creme_core-tests-dosomethingawesome05'
예제 #28
0
 class TestButton4(Button):
     id_ = Button.generate_id('creme_core', 'test_button_registry_4')
예제 #29
0
        class TestButton2(Button):
            id_ = Button.generate_id('creme_core', 'test_button_registry_2')

            def ok_4_display(self, entity):
                return False
예제 #30
0
 class TestButton(Button):
     id_ = Button.generate_id('creme_core',
                              'test_manager_create_if_needed03')
     verbose_name = 'Testing purpose'