Skip to content

Commit

Permalink
'修改timeline装饰器模块规划接口监控'
Browse files Browse the repository at this point in the history
  • Loading branch information
YoLoveLife committed Jul 8, 2018
1 parent beb8c50 commit 4663181
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 190 deletions.
5 changes: 0 additions & 5 deletions apps/_timeline/decorator/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions apps/_timeline/decorator/manager.py

This file was deleted.

48 changes: 0 additions & 48 deletions apps/_timeline/models.py

This file was deleted.

14 changes: 0 additions & 14 deletions apps/_timeline/urls.py

This file was deleted.

64 changes: 0 additions & 64 deletions apps/_timeline/views.py

This file was deleted.

6 changes: 6 additions & 0 deletions apps/authority/permission/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from rest_framework.permissions import BasePermission
from timeline.decorator import decorator_api
from django.conf import settings

__all__ = [
"GroupAPIRequiredMixin", "GroupCreateRequiredMixin", "GroupChangeRequiredMixin",
Expand All @@ -7,6 +9,7 @@


class GroupAPIRequiredMixin(BasePermission):

def has_permission(self, request, view):
perms = self.permission_required
perm_list=list(request.user.get_all_permissions())
Expand All @@ -25,6 +28,9 @@ class GroupListRequiredMixin(GroupAPIRequiredMixin):
class GroupCreateRequiredMixin(GroupAPIRequiredMixin):
permission_required = u'authority.yo_create_pmngroup'

@decorator_api(settings.TIMELIME_PMNGROUP_CREATE)
def has_permission(self, request, view):
return request, super(GroupCreateRequiredMixin, self).has_permission(request, view)

class GroupUpdateRequiredMixin(GroupAPIRequiredMixin):
permission_required = u'authority.yo_update_pmngroup'
Expand Down
25 changes: 0 additions & 25 deletions apps/manager/api/dashboard.py

This file was deleted.

1 change: 1 addition & 0 deletions apps/manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def update(self, instance, validated_data):
return super(HostSerializer,self).update(instance,validated_data)



class HostPasswordSerializer(serializers.ModelSerializer):
passwd = serializers.CharField(source='password', read_only=True)

Expand Down
6 changes: 0 additions & 6 deletions apps/manager/urls/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,4 @@
path(r'v1/host/<uuid:pk>/update/', HostAPI.ManagerHostUpdateAPI.as_view()),
path(r'v1/host/<uuid:pk>/delete/', HostAPI.ManagerHostDeleteAPI.as_view()),
path(r'v1/host/<uuid:pk>/<int:qrcode>/passwd/', HostAPI.ManagerHostPasswordAPI.as_view()),
#
# Resource dashboard api
# path(r'v1/host/<uuid:pk>/')
# # Resource storage api
# path(r'v1/storage/', api.ManagerStorageListAPI.as_view()),
# path(r'v1/storage/(?P<pk>[0-9]+)/remove/', api.ManagerStorageRemoveAPI.as_view()),
]
2 changes: 1 addition & 1 deletion apps/ops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Meta:
# 執行內容
results = models.CharField(default='', max_length=5000)
# 关联文件
files = models.ManyToManyField(FILE, related_name='pushs', blank=True)
files = models.ManyToManyField(FILE, related_name='pushmission', blank=True)

@property
def status(self):
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions apps/timeline/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 18-3-19
# Author Yo
# Email [email protected]
import models, serializers
from rest_framework import generics
from rest_framework.pagination import PageNumberPagination
from rest_framework.views import Response, status
from rest_framework.permissions import IsAuthenticated,AllowAny
from deveops.api import WebTokenAuthentication

__all__ = [
'TimeLineListByPageAPI',
]

class TimeLinePagination(PageNumberPagination):
page_size = 10


class TimeLineListByPageAPI(WebTokenAuthentication,generics.ListAPIView):
module = models.History
serializer_class = serializers.HistorySerializer
permission_classes = [IsAuthenticated, ]
pagination_class = TimeLinePagination
queryset = models.History.objects.all()
File renamed without changes.
17 changes: 17 additions & 0 deletions apps/timeline/decorator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-16
# Author Yo
# Email [email protected]
from timeline.models import History
def decorator_api(timeline_type,):
def wrapper(func):
def inner_wrapper(*args, **kwargs):
request, is_validated= func(*args, **kwargs)
history = History(type=timeline_type, )
history.is_validated = is_validated
history.info = request.data
history.save()
return is_validated #DOT TOUCH it's magic
return inner_wrapper
return wrapper
16 changes: 16 additions & 0 deletions apps/timeline/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from authority.models import ExtendUser
from execute.models import Callback
import uuid


class History(models.Model):
id = models.AutoField(primary_key=True)
uuid = models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(ExtendUser, blank=True, null=True, default=1, related_name='user',)
type = models.IntegerField(default=0)#历史类型
is_validated = models.BooleanField(default=False,)
info = models.TextField(default='')#信息
time = models.DateTimeField(auto_now_add=True,)#历史时间
24 changes: 24 additions & 0 deletions apps/timeline/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding:utf-8 -*-
from manager import models
from rest_framework import serializers
from authority.models import ExtendUser

__all__ = [
"HistorySerializer",
]


class HistorySerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = models.History
fields = (
'id', 'uuid', 'name', 'info', '_status', 'users', '_framework', 'pmn_groups', 'key', 'jumper', 'framework',
)
read_only_fields = (
'id', 'uuid', 'framework'
)
write_only_fields = (
'_framework'
)

File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions apps/timeline/urls/api_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from timeline import api as TimeLineAPI
urlpatterns=[
# Resource position api
path(r'v1/bypage/', TimeLineAPI.TimeLineListByPageAPI.as_view()),
]
16 changes: 15 additions & 1 deletion apps/utils/api/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
# Email [email protected]
from .. import models, serializers
from django.conf import settings
from django.db.models import Q
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated,AllowAny
from rest_framework.pagination import PageNumberPagination
from rest_framework.views import Response, status
from utils.permission import file as FilePermission
import datetime
from deveops.api import WebTokenAuthentication

__all__ = [
Expand All @@ -30,7 +32,11 @@ class UtilsFileListAPI(WebTokenAuthentication,generics.ListAPIView):

def get_queryset(self):
user = self.request.user
query_set = models.FILE.objects.filter(user=user,)
end_time = datetime.datetime.now().strftime('%Y-%m-%d')
start_time = (datetime.datetime.now() - datetime.timedelta(days=2)).strftime('%Y-%m-%d')
query_set = models.FILE.objects.filter(user=user,
pushmission__isnull=False,
create_time__range=(start_time, end_time))
return query_set


Expand All @@ -46,6 +52,7 @@ def get_queryset(self):
return query_set



class UtilsFileCreateAPI(WebTokenAuthentication, generics.CreateAPIView):
module = models.FILE
serializer_class = serializers.FileSerializer
Expand All @@ -60,3 +67,10 @@ class UtilsFileDeleteAPI(WebTokenAuthentication, generics.DestroyAPIView):
lookup_field = 'uuid'
lookup_url_kwarg = 'pk'

def delete(self, request, *args, **kwargs):
obj = self.get_object()
if not obj.pushmission.exists():
return super(UtilsFileDeleteAPI, self).delete(request, *args, **kwargs)
else:
return Response({'detail': '该文件已经属于某个任务无法被删除'}, status=status.HTTP_406_NOT_ACCEPTABLE)

7 changes: 7 additions & 0 deletions apps/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class Meta:
('yo_delete_file', u'删除文件'),
)

@property
def mission_used(self):
if self.pushmission is None:
return '未使用'
else:
return self.pushmission.works.get().uuid


class IMAGE(models.Model):
id = models.AutoField(primary_key=True)
Expand Down
Loading

0 comments on commit 4663181

Please sign in to comment.