Пример #1
0
    def decode_users(cls, data):
        """
        Decode a list of users. Uses mail.decode_recipient_list.

        :param data:        the encoded data
        """
        try:
            user_data = decode_recipient_list(data)
        except (TypeError, ValueError):
            raise ValueError("Wrong format")

        users = []
        for u in user_data:
            try:
                kls = Prestataire if u["type"] == "Prestataire" else Famille
                users.append(kls.objects.get(pk=u["pk"]))
            except (KeyError, kls.DoesNotExist):
                raise ValueError("Wrong format")
        return users
Пример #2
0
 def test_decode_recipient_list(self):
     data = [{"type": "Prestataire", "pk": 1}, {"type": "Famille", "pk": 2}]
     encoded = "---".join([base64.urlsafe_b64encode(json.dumps(d)) for d in data])
     self.assertEqual(mail.decode_recipient_list(encoded), data)