Commit 17657deb authored by ibuler's avatar ibuler

[Bugfix] 和Master分支合并后,修复冲突,DRF 新版本要求 fields和exclude

parent 49861b6a
......@@ -27,7 +27,7 @@ class TerminalRegisterView(ListCreateAPIView):
serializer = self.serializer_class(data={'name': name, 'remote_addr': remote_addr})
if get_object_or_none(Terminal, name=name):
return Response({'msg': 'Registed, Need admin active it'}, status=200)
return Response({'msg': 'Already register, Need administrator active it'}, status=200)
if serializer.is_valid():
terminal = serializer.save()
......@@ -54,6 +54,12 @@ class TerminalViewSet(viewsets.ModelViewSet):
def create(self, request, *args, **kwargs):
return Response({'msg': 'Use register view except that'}, status=404)
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
if instance.user is not None:
instance.user.delete()
return super(TerminalViewSet, self).destroy(request, *args, **kwargs)
class TerminalHeatbeatViewSet(viewsets.ModelViewSet):
queryset = TerminalHeatbeat.objects.all()
......
......@@ -32,18 +32,12 @@
{% csrf_token %}
<h3>{% trans 'Info' %}</h3>
{{ form.name|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.remote_addr|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.url|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<h3>{% trans 'Other' %}</h3>
<div class="form-group">
<label for="{{ form.is_active.id_for_label }}" class="col-sm-2 control-label">{% trans 'Active' %}</label>
<div class="col-sm-8">
{{ form.is_active}}
</div>
</div>
{{ form.comment|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
......
......@@ -13,7 +13,7 @@ class AssetGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta:
model = AssetGroup
list_serializer_class = BulkListSerializer
fields = ['id', 'name', 'comment', 'assets_amount']
fields = ['id', 'name', 'comment', 'assets_amount', 'assets']
@staticmethod
def get_assets_amount(obj):
......@@ -68,6 +68,7 @@ class TagSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta:
model = Tag
list_serializer_class = BulkListSerializer
fields = '__all__'
@staticmethod
def get_assets_amount(obj):
......@@ -79,6 +80,7 @@ class AdminUserSerializer(serializers.ModelSerializer):
class Meta:
model = AdminUser
fields = '__all__'
def get_field_names(self, declared_fields, info):
fields = super(AdminUserSerializer, self).get_field_names(declared_fields, info)
......@@ -127,7 +129,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta(object):
model = Asset
list_serializer_class = BulkListSerializer
fields = ['__all__']
fields = '__all__'
@staticmethod
def get_hardware(obj):
......@@ -170,6 +172,7 @@ class IDCSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta:
model = IDC
fields = '__all__'
@staticmethod
def get_assets_amount(obj):
......
......@@ -16,18 +16,13 @@ __all__ = ['UserGroup']
class UserGroup(NoDeleteModelMixin, Group):
comment = models.TextField(blank=True, verbose_name=_('Comment'))
date_created = models.DateTimeField(auto_now_add=True)
date_created = models.DateTimeField(auto_now_add=True, null=True)
created_by = models.CharField(max_length=100)
def __unicode__(self):
return self.name
def has_member(self, user):
if user in self.users.all():
return True
return False
def delete(self):
def delete(self, using=None, keep_parents=False):
if self.name != 'Default':
self.users.clear()
return super(UserGroup, self).delete()
......
......@@ -56,6 +56,7 @@ class UserGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta:
model = UserGroup
list_serializer_class = BulkListSerializer
fields = '__all__'
@staticmethod
def get_user_amount(obj):
......
......@@ -27,7 +27,6 @@
<span class="help-block ">{{ form.date_expired.errors }}</span>
</div>
</div>
{{ form.date_expired|bootstrap_horizontal }}
<div class="form-group">
<label for="{{ form.enable_otp.id_for_label }}" class="col-sm-2 control-label">{% trans 'Enable OTP' %}</label>
<div class="col-sm-8">
......
......@@ -346,7 +346,7 @@ $(document).ready(function() {
});
}).on('click', '#btn_reset_pk', function() {
function doReset() {
var the_url = '{% url "api-users:user-reset-pk" pk=user.id %}';
var the_url = '{% url "api-users:user-public-key-reset" pk=user.id %}';
var body = {};
var success = function() {
var msg = "{% trans 'The reset-ssh-public-key E-mail has been sent successfully. Please inform the user to update his new ssh public key.' %}";
......@@ -372,7 +372,7 @@ $(document).ready(function() {
}).on('click', '#btn_user_update_pk', function(){
var $this = $(this);
var pk = $('#txt_pk').val();
var the_url = '{% url "api-users:user-update-pk" pk=user.id %}';
var the_url = '{% url "api-users:user-public-key-reset" pk=user.id %}';
var body = {'_public_key': pk};
var success = function() {
$('#txt_pk').val('');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment