예제 #1
0
    def test_get_bulk_or_404_07(self):
        "Duplicated."
        s1, s2 = FakeSector.objects.all()[:2]

        bulk = get_bulk_or_404(FakeSector, [s1.id, s2.id, str(s1.id)])
        self.assertDictEqual({s1.id: s1, s2.id: s2}, bulk)

        with self.assertRaises(Http404) as cm:
            get_bulk_or_404(FakeSector, [s1.id, str(s1.id), 2048])

        self.assertEqual('These IDs cannot be found: 2048',
                         cm.exception.args[0])
예제 #2
0
    def test_get_bulk_or_404_06(self):
        "Inr ID as strings."
        s1, s2 = FakeSector.objects.all()[:2]

        bulk = get_bulk_or_404(FakeSector, [str(s1.id), str(s2.id)])
        self.assertDictEqual({s1.id: s1, s2.id: s2}, bulk)

        with self.assertRaises(Http404) as cm:
            get_bulk_or_404(FakeSector, [str(s1.id), f'{self.UNUSED_PK}'])

        self.assertEqual(f'These IDs cannot be found: {self.UNUSED_PK}',
                         cm.exception.args[0])
예제 #3
0
    def test_get_bulk_or_404_01(self):
        "Argument is a model."
        s1, s2 = FakeSector.objects.all()[:2]

        bulk = get_bulk_or_404(FakeSector, [s1.id, s2.id])
        self.assertDictEqual({s1.id: s1, s2.id: s2}, bulk)

        with self.assertRaises(Http404) as cm:
            get_bulk_or_404(FakeSector, [s1.id, self.UNUSED_PK])

        self.assertEqual(f'These IDs cannot be found: {self.UNUSED_PK}',
                         cm.exception.args[0])

        # Invalid argument for IDs
        with self.assertRaises(ValueError):
            get_bulk_or_404([s1, s2], [s1.id])
예제 #4
0
파일: views.py 프로젝트: mrjmad/creme_crm
    def create_related_phonecall(self):
        user = self.request.user
        users = [user]
        entity = self.get_related_entity()

        pcall = self.build_phonecall()
        pcall.save()

        # If the entity is a contact with related user, should add the phone call to his calendar
        if isinstance(entity, Contact) and entity.is_user:
            users.append(entity.is_user)

        pcall.calendars.add(*Calendar.objects.get_default_calendars(users).values())

        # TODO: link credentials
        caller_rtype = act_constants.REL_SUB_PART_2_ACTIVITY
        entity_rtype = (
            act_constants.REL_SUB_PART_2_ACTIVITY
            if isinstance(entity, Contact) else
            act_constants.REL_SUB_LINKED_2_ACTIVITY
        )
        rtypes_map = get_bulk_or_404(RelationType, id_list=[caller_rtype, entity_rtype])

        user_contact = user.linked_contact
        create_rel = partial(Relation.objects.create, object_entity=pcall, user=user)

        if entity.pk != user_contact.pk:
            create_rel(subject_entity=user_contact, type=rtypes_map[caller_rtype])
        create_rel(subject_entity=entity, type=rtypes_map[entity_rtype])

        return pcall
예제 #5
0
파일: mail.py 프로젝트: mrjmad/creme_crm
    def post(self, request, *args, **kwargs):
        ids = self.get_email_ids(request)

        if ids:
            for email in get_bulk_or_404(self.model, ids).values():
                email.send()

        return HttpResponse()
예제 #6
0
    def test_get_bulk_or_404_04(self):
        "Argument <field_name>."
        create_cat = FakeFolderCategory.objects.create
        cat1 = create_cat(name='Pix')
        cat2 = create_cat(name='Music')
        ___ = create_cat(name='Video')

        bulk = get_bulk_or_404(FakeFolderCategory.objects,
                               [cat1.name, cat2.name],
                               field_name='name')
        self.assertDictEqual({cat1.name: cat1, cat2.name: cat2}, bulk)
예제 #7
0
    def test_get_bulk_or_404_05(self):
        "id_list=None."
        create_cat = FakeFolderCategory.objects.create
        cat1 = create_cat(name='Pix')
        cat2 = create_cat(name='Music')
        cat3 = create_cat(name='Video')

        bulk = get_bulk_or_404(FakeFolderCategory.objects)
        self.assertDictEqual({
            cat1.id: cat1,
            cat2.id: cat2,
            cat3.id: cat3
        }, bulk)
예제 #8
0
    def test_get_bulk_or_404_03(self):
        "Argument is a manager."
        p1, p2 = FakePosition.objects.all()[:2]

        bulk = get_bulk_or_404(FakePosition.objects, [p1.id, p2.id])
        self.assertDictEqual({p1.id: p1, p2.id: p2}, bulk)
예제 #9
0
    def test_get_bulk_or_404_02(self):
        "Argument is a queryset."
        s1, s2 = FakeSector.objects.all()[1:3]

        bulk = get_bulk_or_404(FakeSector.objects.all(), [s1.id, s2.id])
        self.assertDictEqual({s1.id: s1, s2.id: s2}, bulk)
예제 #10
0
파일: actions.py 프로젝트: mrjmad/creme_crm
 def get_actions(self, request) -> Iterator[WaitingAction]:
     return iter(
         get_bulk_or_404(WaitingAction,
                         self.get_action_ids(request)).values())