def handle(self, **options): SERVERS = getattr(settings, 'SERVERS', {}) if not SERVERS: raise CommandError('There are no SERVERS in your settings file') server = options.get('server', None) if not server: raise CommandError('Provide a server key.') if not server in SERVERS: raise CommandError( 'Server key "%(server)s" does not exist in your settings.' % {'server': server}) objects = DeployObjectLog.objects.filter(deployed=False, server=server) try: response, count = deploytoserver(objects, server) if response is None and count == 0: print 'There are no pending objects to publish in the %(server)s server' % { 'server': server } return elif count > 0 and response: if response.status_code != 200: print 'Error %(message)s with %(object)s' % response.json elif response: print response.reason else: raise ValueError('Unknown error') except Exception, e: raise CommandError(unicode(e))
def deploytoserver_action(modeladmin, request, queryset): for server in set(queryset.values_list('server', flat=True)): try: objects = queryset.filter(server=server) response, count = deploytoserver(objects, server, request.user) if response is None and count == 0: messages.error( request, _('There are no pending objects to publish in the %(server)s server' % {'server': server})) continue elif response and count == 0: messages.error(request, response.reason) elif response and count > 0: if response.status_code != 200: messages.error( request, _('Error %(message)s with %(object)s' % response.json)) else: raise ValueError('Unknown error') log = DeployObjectLog(server=server) messages.success( request, _('%(count)s objects was sent to %(server)s' % { 'count': count, 'server': log.get_server_display() })) except Exception, e: messages.error(request, unicode(e))
def handle(self, **options): SERVERS = getattr(settings, 'SERVERS', {}) if not SERVERS: raise CommandError('There are no SERVERS in your settings file') server = options.get('server', None) if not server: raise CommandError('Provide a server key.') if not server in SERVERS: raise CommandError('Server key "%(server)s" does not exist in your settings.' % {'server': server}) objects = DeployObjectLog.objects.filter(deployed=False, server=server) try: response, count = deploytoserver(objects, server) if response is None and count == 0: print 'There are no pending objects to publish in the %(server)s server' % {'server': server} return elif count > 0 and response: if response.status_code != 200: print 'Error %(message)s with %(object)s' % response.json elif response: print response.reason else: raise ValueError('Unknown error') except Exception, e: raise CommandError(unicode(e))
def deploytoserver_action(modeladmin, request, queryset): for server in set(queryset.values_list('server', flat=True)): try: objects = queryset.filter(server=server) response, count = deploytoserver(objects, server, request.user) if response is None and count == 0: messages.error(request, _('There are no pending objects to publish in the %(server)s server' % {'server': server})) continue elif response and count == 0: messages.error(request, response.reason) elif response and count > 0: if response.status_code != 200: messages.error(request, _('Error %(message)s with %(object)s' % response.json)) else: raise ValueError('Unknown error') log = DeployObjectLog(server=server) messages.success(request, _('%(count)s objects was sent to %(server)s' % {'count': count, 'server': log.get_server_display()})) except Exception, e: messages.error(request, unicode(e))