Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from .serializers import AddressSerializer, MailboxSerializer
class AddressViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Address.objects.select_related('domain').prefetch_related('mailboxes').all()
serializer_class = AddressSerializer
filter_fields = ('domain', 'mailboxes__name')
class MailboxViewSet(LogApiMixin, SetPasswordApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Mailbox.objects.prefetch_related('addresses__domain').all()
serializer_class = MailboxSerializer
router.register(r'mailboxes', MailboxViewSet)
router.register(r'addresses', AddressViewSet)
serializer_class = WebAppSerializer
filter_fields = ('name',)
def metadata(self, request):
ret = super(WebAppViewSet, self).metadata(request)
names = [
'WEBAPPS_BASE_ROOT', 'WEBAPPS_TYPES', 'WEBAPPS_WEBAPP_OPTIONS',
'WEBAPPS_PHP_DISABLED_FUNCTIONS', 'WEBAPPS_DEFAULT_TYPE'
]
ret['settings'] = {
name.lower(): getattr(settings, name, None) for name in names
}
return ret
router.register(r'webapps', WebAppViewSet)
from .models import PaymentSource, Transaction
from .serializers import PaymentSourceSerializer, TransactionSerializer
class PaymentSourceViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
serializer_class = PaymentSourceSerializer
queryset = PaymentSource.objects.all()
class TransactionViewSet(LogApiMixin, viewsets.ModelViewSet):
serializer_class = TransactionSerializer
queryset = Transaction.objects.all()
router.register(r'payment-sources', PaymentSourceViewSet)
router.register(r'transactions', TransactionViewSet)
class WebsiteViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Website.objects.prefetch_related('domains', 'content_set__webapp', 'directives').all()
serializer_class = WebsiteSerializer
filter_fields = ('name', 'domains__name')
def options(self, request):
metadata = super(WebsiteViewSet, self).options(request)
names = ['WEBSITES_OPTIONS', 'WEBSITES_PORT_CHOICES']
metadata.data['settings'] = {
name.lower(): getattr(settings, name, None) for name in names
}
return metadata
router.register(r'websites', WebsiteViewSet)
class DatabaseViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Database.objects.prefetch_related('users').all()
serializer_class = DatabaseSerializer
filter_fields = ('name',)
class DatabaseUserViewSet(LogApiMixin, AccountApiMixin, SetPasswordApiMixin, viewsets.ModelViewSet):
queryset = DatabaseUser.objects.prefetch_related('databases').all()
serializer_class = DatabaseUserSerializer
filter_fields = ('username',)
router.register(r'databases', DatabaseViewSet)
router.register(r'databaseusers', DatabaseUserViewSet)
class WebsiteViewSet(AccountApiMixin, viewsets.ModelViewSet):
model = Website
serializer_class = WebsiteSerializer
filter_fields = ('name',)
def metadata(self, request):
ret = super(WebsiteViewSet, self).metadata(request)
names = ['WEBSITES_OPTIONS', 'WEBSITES_PORT_CHOICES']
ret['settings'] = {
name.lower(): getattr(settings, name, None) for name in names
}
return ret
router.register(r'websites', WebsiteViewSet)
from rest_framework import viewsets
from orchestra.api import router, LogApiMixin
from orchestra.contrib.accounts.api import AccountApiMixin
from .models import Contact
from .serializers import ContactSerializer
class ContactViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Contact.objects.all()
serializer_class = ContactSerializer
router.register(r'contacts', ContactViewSet)
qs = super(TicketViewSet, self).get_queryset()
qs = qs.select_related('creator', 'queue')
qs = qs.prefetch_related('messages__author')
return qs.filter(creator=self.request.user)
class QueueViewSet(LogApiMixin,
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
viewsets.GenericViewSet):
queryset = Queue.objects.all()
serializer_class = QueueSerializer
router.register(r'tickets', TicketViewSet)
router.register(r'ticket-queues', QueueViewSet)
from .models import Address, Mailbox
from .serializers import AddressSerializer, MailboxSerializer
class AddressViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Address.objects.select_related('domain').prefetch_related('mailboxes').all()
serializer_class = AddressSerializer
filter_fields = ('domain', 'mailboxes__name')
class MailboxViewSet(LogApiMixin, SetPasswordApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Mailbox.objects.prefetch_related('addresses__domain').all()
serializer_class = MailboxSerializer
router.register(r'mailboxes', MailboxViewSet)
router.register(r'addresses', AddressViewSet)