Update some api

pull/530/head
ibuler 8 years ago
parent 70da177ed7
commit 301e02bcd8

@ -64,10 +64,3 @@ class TerminalHeatbeatViewSet(viewsets.ModelViewSet):
terminal = request.user.terminal
TerminalHeatbeat.objects.create(terminal=terminal)
return Response({'msg': 'Success'}, status=201)
class TestHeatbeat(APIView):
permission_classes = (IsAppUser,)
def post(self, request):
return Response({'hello': 'world'})

@ -122,12 +122,10 @@ $(document).ready(function(){
}).on('click', '#btn_terminal_accept', function () {
var $form = $('#form_terminal_accept');
function success (data, textStatus, jqXHR) {
if (data.success === false) {
console.log(data.msg);
if (data.success === true) {
window.location.reload()
} else {
console.log(data.msg);
$('#modal-error').html(data.msg).css('display', 'block');
}
}
$form.ajaxSubmit({success: success});

@ -1,26 +0,0 @@
{% extends '_modal.html' %}
{% load static %}
{% load bootstrap %}
{% load i18n %}
{% block modal_body %}
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
{{ form.name|bootstrap_horizontal }}
{{ form.remote_addr|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.url|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-default" type="reset"> {% trans 'Reset' %}</button>
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
</div>
</div>
</form>
{% endblock %}
{% block custom_foot_js %}
{% endblock %}

@ -7,6 +7,7 @@
{% load bootstrap %}
<form action="{% url 'applications:terminal-modal-accept' pk="99991937" %}" method="post" class="form-horizontal" id="form_terminal_accept">
{% csrf_token %}
<p class="alert alert-danger" id="modal-error" style="display: none"></p>
{{ form.name|bootstrap_horizontal }}
{{ form.remote_addr|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}

@ -2,6 +2,7 @@
#
from django.views.generic import ListView, UpdateView, DeleteView, FormView
from django.views.generic.edit import BaseUpdateView
from django.utils.translation import ugettext as _
from django.urls import reverse_lazy
@ -44,10 +45,14 @@ class TerminalDeleteView(DeleteView):
success_url = reverse_lazy('applications:applications-list')
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView):
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, BaseUpdateView):
model = Terminal
form_class = TerminalForm
def post(self, request, *args, **kwargs):
print(request.POST)
return super(TerminalModelAccept, self).post(request, *args, **kwargs)
def form_valid(self, form):
terminal = form.save()
terminal.is_accepted = True
@ -57,14 +62,13 @@ class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView)
'success': True,
'msg': 'success'
}
print('Valid')
return self.render_json_response(data)
def form_invalid(self, form):
print(form.errors)
print('form.data')
data = {
'success': False,
'msg': ','.join(form.errors)
'msg': str(form.errors),
}
return self.render_json_response(data)

@ -65,8 +65,6 @@ class AccessKeyAuthentication(authentication.BaseAuthentication):
raise exceptions.AuthenticationFailed(_('Invalid signature.'))
access_key_secret = access_key.secret
print(request_date)
try:
request_unix_time = http_to_unixtime(request_date)
except ValueError:

Loading…
Cancel
Save