You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.1 KiB
91 lines
3.1 KiB
from pydoc import pager |
|
|
|
from rest_framework import viewsets |
|
from rest_framework.response import Response |
|
|
|
from product.serializers import * |
|
from django_filters.rest_framework import DjangoFilterBackend |
|
from rest_framework.decorators import action |
|
from product.utils.pagination import PageNumberPagination, CustomPageNumberPagination |
|
import pymysql |
|
from pymysql.cursors import DictCursor |
|
from dingxin_toolbox_drf.settings import CONFIG |
|
from env import * |
|
|
|
|
|
# Create your views here. |
|
class ProjectViewSet(viewsets.ModelViewSet): |
|
# 字段注释 |
|
""" |
|
id: 数据id |
|
project_name: 项目名称 |
|
is_delete: 删除标记 |
|
""" |
|
queryset = Project.objects.filter(is_delete=False).all() |
|
serializer_class = ProjectSerializer |
|
|
|
|
|
class PrdItemViewSet(viewsets.ModelViewSet): |
|
# 字段注释 |
|
""" |
|
id: 数据id |
|
project: 项目名称 |
|
prd_version: 版本 |
|
prd_doc_link: 产品文档链接 json格式 |
|
prd_comment: 产品文档说明 |
|
is_delete: 删除标记 |
|
""" |
|
queryset = PrdItem.objects.filter(is_delete=False).order_by('-id').all() |
|
serializer_class = PrdItemSerializer |
|
filter_backends = (DjangoFilterBackend,) |
|
# http://127.0.0.1:8000/prd/prd_list?project=上影联合院线 |
|
filterset_fields = ('project',) |
|
pagination_class = CustomPageNumberPagination |
|
|
|
@action(methods=['get'], detail=False, url_path='ax_cloud') |
|
def get_ax_cloud_time(self, request): |
|
# 获取数据 |
|
queryset = self.get_queryset() |
|
|
|
if queryset is not None: |
|
# 获取项目时间 |
|
db_config = CONFIG[ENV]['AX_CLOUD_DB'] |
|
db = { |
|
'host': db_config['HOST'], |
|
'port': db_config['PORT'], |
|
'user': db_config['USER'], |
|
'password': db_config['PASSWORD'], |
|
'db': db_config['NAME'], |
|
} |
|
print(db) |
|
db_conn = pymysql.Connect(**db) |
|
db_cursor = db_conn.cursor(cursor=DictCursor) |
|
sql = "select Shortcut, ModifiedOn from axshare.axshare_ShortcutKey;" |
|
db_cursor.execute(sql) |
|
ax_cloud_data = db_cursor.fetchall() |
|
db_conn.close() |
|
# 遍历数据 |
|
for data in queryset: |
|
shortcut_key = data.prd_doc_link.split(r'/')[-1] |
|
for item in ax_cloud_data: |
|
if item['Shortcut'].lower() == shortcut_key.lower(): |
|
data.update_at = item['ModifiedOn'] |
|
page = self.paginate_queryset(queryset) |
|
serializer = self.get_serializer(page, many=True) |
|
return self.get_paginated_response(serializer.data) |
|
return Response(None) |
|
|
|
class PrdHistoryViewSet(viewsets.ModelViewSet): |
|
# 字段注释 |
|
""" |
|
id: 数据id |
|
prd_id: 版本id |
|
history_doc_link: 历史产品原型链接 |
|
update_at: 最后更新日期 |
|
is_delete: 删除标记 |
|
""" |
|
queryset = PrdHistory.objects.filter(is_delete=False).order_by('-update_at').all() |
|
serializer_class = PrdHistorySerializer |
|
filter_backends = (DjangoFilterBackend,) |
|
# http://127.0.0.1:8000/prd/prd_history?prd_id=1 |
|
filterset_fields = ('prd_id',)
|
|
|