2014-08-22 15:31:44 +00:00
|
|
|
from rest_framework import viewsets
|
|
|
|
|
2015-04-05 18:02:36 +00:00
|
|
|
from orchestra.api import router, SetPasswordApiMixin, LogApiMixin
|
2015-04-05 10:46:24 +00:00
|
|
|
from orchestra.contrib.accounts.api import AccountApiMixin
|
2014-08-22 15:31:44 +00:00
|
|
|
|
|
|
|
from .models import Address, Mailbox
|
|
|
|
from .serializers import AddressSerializer, MailboxSerializer
|
|
|
|
|
|
|
|
|
2015-04-05 18:02:36 +00:00
|
|
|
class AddressViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
|
2015-04-23 19:46:23 +00:00
|
|
|
queryset = Address.objects.select_related('domain').prefetch_related('mailboxes').all()
|
2014-08-22 15:31:44 +00:00
|
|
|
serializer_class = AddressSerializer
|
2015-05-25 19:16:07 +00:00
|
|
|
filter_fields = ('domain', 'mailboxes__name')
|
2014-08-22 15:31:44 +00:00
|
|
|
|
|
|
|
|
2015-04-05 18:02:36 +00:00
|
|
|
class MailboxViewSet(LogApiMixin, SetPasswordApiMixin, AccountApiMixin, viewsets.ModelViewSet):
|
2015-04-23 19:46:23 +00:00
|
|
|
queryset = Mailbox.objects.prefetch_related('addresses__domain').all()
|
2014-08-22 15:31:44 +00:00
|
|
|
serializer_class = MailboxSerializer
|
|
|
|
|
|
|
|
|
|
|
|
router.register(r'mailboxes', MailboxViewSet)
|
|
|
|
router.register(r'addresses', AddressViewSet)
|