forked from mtianyan/OnlineMooc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8,771 changed files
with
794,715 additions
and
1,455 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
FROM centos/python-36-centos7 | ||
USER root | ||
FROM python:3.7 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN yum -y install httpd* | ||
MAINTAINER mtianyan <[email protected]> | ||
|
||
ADD ./requirements.txt /tmp/requirements.txt | ||
|
||
RUN pip install -r /tmp/requirements.txt -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com \ | ||
&& pip install mod_wsgi -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com \ | ||
&& pip install uwsgi -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
RUN mod_wsgi-express install-module | ||
EXPOSE 8000 | ||
|
||
ADD ./conf/django.conf /etc/httpd/conf.d/django.conf | ||
|
||
EXPOSE 80 | ||
|
||
WORKDIR /Mxonline3 | ||
WORKDIR /ProjectPath |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import requests | ||
|
||
route_full = input("路由信息:") | ||
base_url = "http://localhost:8000/" | ||
head = { | ||
"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJjNmMzNjhiMTdlMGQ0ZGI5YTllZGYzMWNmNzhiMDhkNSIsImF1dGgiOiJhZG1pbiIsInN1YiI6ImFkbWluIn0.9YIDwVrwZ3nFtUrM4S1aWt8qLkexF3Ia-Sc3l3WPy0YbgNsyzAUBnViZiwLkejSJtU4ScgLYa7JFLK7B9fI3nw" | ||
} | ||
res = requests.get(base_url + route_full, headers=head).json() | ||
route = route_full.split("/")[-1] | ||
txt = f""" | ||
@action(methods=['get'], detail=False, url_path="{route}/?") | ||
def {route}(self, request, pk=None): | ||
return Response({res}) | ||
""" | ||
|
||
print(txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
model_name = input("模型名称:") | ||
txt = f""" | ||
children = serializers.SerializerMethodField() | ||
@staticmethod | ||
def get_children(obj): | ||
children_serializer = {model_name}Serializer({model_name}.objects.filter(parent_id=obj.id), many=True) | ||
return children_serializer.data | ||
pagination_class = TreePagination | ||
def get_queryset(self): | ||
if self.action == "list": | ||
queryset = {model_name}.objects.filter(parent_id=None) | ||
elif self.action == "retrieve": | ||
queryset = {model_name}.objects.all() | ||
else: | ||
queryset = {model_name}.objects.all() | ||
return queryset | ||
""" | ||
print(txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
model_name = input("输入模型名称:") | ||
txt = f""" | ||
def retrieve(self, request, *args, **kwargs): | ||
pk = kwargs["pk"] | ||
data = SysUserSerializer({model_name}.objects.get(user_id=pk)).data | ||
postIds = [cur_user.post_id] | ||
roleIds = [cur_user.role_id] | ||
return Response({ | ||
"code": 200, | ||
"data": data, | ||
"postIds": postIds, | ||
"roleIds": roleIds, | ||
"posts": SysPostSerializer(SysPost.objects.all(), many=True).data, | ||
"roles": SysRoleSerializer(SysRole.objects.all(), many=True).data, | ||
}) | ||
def put(self, request, *args, **kwargs): | ||
change_key(request) | ||
if "post_ids" in request.data.keys(): | ||
request.data["post_id"] = request.data.pop("post_ids") | ||
if "role_ids" in request.data.keys(): | ||
request.data["role_id"] = request.data.pop("role_ids") | ||
SysUser(**request.data).save() | ||
return Response({'code': 200, 'msg': '修改成功'}) | ||
def destroy(self, request, *args, **kwargs): | ||
instance = self.get_object() | ||
self.perform_destroy(instance) | ||
return Response({'code': 200}, status=status.HTTP_200_OK) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from urllib import parse | ||
|
||
# url = input("输入完整url") | ||
from utils import get_lower_case_name | ||
|
||
url = input("请输入完整地址:") | ||
model = input("请输入模型名称:") | ||
qs = parse.parse_qs(parse.urlsplit(url).query).keys() | ||
# qs = parse.parse_qs(parse.urlsplit(url).query).keys() | ||
remove_list = ["pageIndex", "pageSize"] | ||
|
||
remain_qs = [one for one in qs if one not in remove_list] | ||
|
||
row_list = [] | ||
for one in remain_qs: | ||
# if get_lower_case_name(one) != one: | ||
one = f""" {one} = filters.CharFilter(field_name="{get_lower_case_name(one)}", lookup_expr='icontains')\n""" | ||
row_list.append(one) | ||
txt = f""" | ||
class {model}Filter(filters.FilterSet): | ||
{"".join(row_list)} | ||
class Meta: | ||
model = {model} | ||
fields = {remain_qs} | ||
filter_class = {model}Filter | ||
""" | ||
|
||
print(txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
import requests | ||
|
||
|
||
def gen(base_url, url, data): | ||
view_name = "".join([one.title() for one in url.split("/")]) + "View" | ||
url_txt = f""" | ||
path('{url}', {view_name}.as_view()), | ||
""" | ||
|
||
exe_request = input("请求敲回车,不执行输入0:") | ||
if exe_request != "0": | ||
full_url = base_url + url | ||
print(full_url) | ||
headers = { | ||
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhc2NvcGUiOiIiLCJleHAiOjE1OTMyODE1MDAsImlkZW50aXR5IjoxLCJuaWNlIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU5MzI3NzkwMCwicm9sZWlkIjoxLCJyb2xla2V5IjoiYWRtaW4iLCJyb2xlbmFtZSI6Iuezu-e7n-euoeeQhuWRmCJ9.imH7I3zN6KgyNCjgquJ4frxPmh-FK6IvBDKBid73Szo" | ||
} | ||
res = requests.post(full_url, data=data, headers=headers).json() | ||
print(res) | ||
else: | ||
res = input("请输入返回值:") | ||
txt_list = [] | ||
for key, value in json.loads(data).items(): | ||
txt = f"""\t\t{key} = request.data["{key}"]\n""" | ||
txt_list.append(txt) | ||
|
||
api_txt = f""" | ||
class {view_name}(APIView): | ||
def post(self, request): | ||
{"".join(txt_list)} | ||
\t\treturn Response({res}) | ||
""".replace("null", 'None').replace("true", "True").replace("false", "False") | ||
|
||
print(url_txt) | ||
print(api_txt) | ||
|
||
|
||
if __name__ == '__main__': | ||
base_url = "http://localhost:8000/" | ||
url = input("输入route:") | ||
data = input("请输入payload:") | ||
gen(base_url, url, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import requests | ||
|
||
|
||
def gen(base_url, url): | ||
view_name = "".join([one.title().replace(".","") for one in url.split("/")]) + "View" | ||
url_txt = f""" | ||
path('{url}', {view_name}.as_view()), | ||
""" | ||
exe_request = input("请求敲回车,不执行输入0:") | ||
if exe_request != "0": | ||
head = { | ||
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhc2NvcGUiOiIiLCJleHAiOjE1OTMyNzc2NDMsImlkZW50aXR5IjoxLCJuaWNlIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU5MzI3NDA0Mywicm9sZWlkIjoxLCJyb2xla2V5IjoiYWRtaW4iLCJyb2xlbmFtZSI6Iuezu-e7n-euoeeQhuWRmCJ9._8gIv32Z6fz1dhlltTvC_bxLtKnbKDlNj6h8bXtPAhk" } | ||
full_url = base_url+url | ||
print(full_url) | ||
res = requests.get(full_url, headers=head).json() | ||
print(res) | ||
else: | ||
res = input("输入") | ||
api_txt = f""" | ||
class {view_name}(APIView): | ||
def get(self, request): | ||
return Response({res}) | ||
""".replace("null",'None').replace("true", "True").replace("false", "False") | ||
|
||
print(url_txt) | ||
print(api_txt) | ||
|
||
|
||
if __name__ == '__main__': | ||
base_url = "http://localhost:8000/api/v1/" | ||
url = input("输入route:") | ||
gen(base_url, url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import os | ||
import re | ||
from pathlib import Path | ||
|
||
|
||
def get_lower_case_name(text): | ||
lst = [] | ||
for index, char in enumerate(text): | ||
if char.isupper() and index != 0: | ||
lst.append("_") | ||
lst.append(char) | ||
|
||
return "".join(lst).lower() | ||
|
||
|
||
app_name = "users" | ||
with open(Path(__file__).parent.parent.resolve().joinpath(f"{app_name}/models.py")) as fr: | ||
code_content = fr.read() | ||
|
||
model_list = re.findall('class (.*)\(models.Model\):', code_content) | ||
serializers_txt = f""" | ||
from rest_framework import serializers | ||
from {app_name}.models import {", ".join(model_list)} | ||
""" | ||
for model in model_list: | ||
serializers_txt += f""" | ||
class {model}Serializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = {model} | ||
fields = "__all__" | ||
""" | ||
|
||
if os.path.exists('serializers.py'): | ||
print("已存在serializers跳过") | ||
else: | ||
with open('serializers.py', 'w') as fw: | ||
fw.write(serializers_txt) | ||
|
||
serializers_list = [one + "Serializer" for one in model_list] | ||
viewset_txt = f""" | ||
from rest_framework import viewsets | ||
from {app_name}.models import {", ".join(model_list)} | ||
from {app_name}.serializers import {", ".join(serializers_list)} | ||
""" | ||
|
||
for model_name in model_list: | ||
viewset_txt += f""" | ||
class {model_name}ViewSet(viewsets.ModelViewSet): | ||
serializer_class = {model_name}Serializer | ||
queryset = {model_name}.objects.all() | ||
""" | ||
if os.path.exists('api_views.py'): | ||
print("已存在views跳过") | ||
else: | ||
with open('api_views.py', 'w') as fw: | ||
fw.write(viewset_txt) | ||
|
||
url_txt = f"""from {app_name} import views | ||
from django.urls import re_path, include, path | ||
from rest_framework.routers import DefaultRouter | ||
router = DefaultRouter(trailing_slash=False) | ||
""" | ||
|
||
for model_name in model_list: | ||
url_txt += f""" | ||
router.register('{get_lower_case_name(model_name)}/?', views.{model_name}ViewSet) | ||
""" | ||
|
||
url_txt += """ | ||
urlpatterns = [ | ||
re_path('^', include(router.urls)), | ||
] | ||
""" | ||
|
||
if os.path.exists('urls.py'): | ||
print("已存在urls跳过") | ||
else: | ||
with open('urls.py', 'w') as fw: | ||
fw.write(url_txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from users import views | ||
from django.urls import re_path, include, path | ||
from rest_framework.routers import DefaultRouter | ||
|
||
router = DefaultRouter(trailing_slash=False) | ||
|
||
router.register('email_verify_record/?', views.EmailVerifyRecordViewSet) | ||
|
||
router.register('banner/?', views.BannerViewSet) | ||
|
||
urlpatterns = [ | ||
re_path('^', include(router.urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
from rest_framework import viewsets | ||
|
||
from operation.models import UserAsk, CourseComments, UserFavorite, UserMessage, UserCourse | ||
from operation.serializers import UserAskSerializer, CourseCommentsSerializer, UserFavoriteSerializer, UserMessageSerializer, UserCourseSerializer | ||
|
||
|
||
class UserAskViewSet(viewsets.ModelViewSet): | ||
serializer_class = UserAskSerializer | ||
queryset = UserAsk.objects.all() | ||
|
||
|
||
class CourseCommentsViewSet(viewsets.ModelViewSet): | ||
serializer_class = CourseCommentsSerializer | ||
queryset = CourseComments.objects.all() | ||
|
||
|
||
class UserFavoriteViewSet(viewsets.ModelViewSet): | ||
serializer_class = UserFavoriteSerializer | ||
queryset = UserFavorite.objects.all() | ||
|
||
|
||
class UserMessageViewSet(viewsets.ModelViewSet): | ||
serializer_class = UserMessageSerializer | ||
queryset = UserMessage.objects.all() | ||
|
||
|
||
class UserCourseViewSet(viewsets.ModelViewSet): | ||
serializer_class = UserCourseSerializer | ||
queryset = UserCourse.objects.all() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
from rest_framework import serializers | ||
|
||
from operation.models import UserAsk, CourseComments, UserFavorite, UserMessage, UserCourse | ||
|
||
|
||
class UserAskSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = UserAsk | ||
fields = "__all__" | ||
|
||
|
||
class CourseCommentsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CourseComments | ||
fields = "__all__" | ||
|
||
|
||
class UserFavoriteSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = UserFavorite | ||
fields = "__all__" | ||
|
||
|
||
class UserMessageSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = UserMessage | ||
fields = "__all__" | ||
|
||
|
||
class UserCourseSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = UserCourse | ||
fields = "__all__" | ||
|
Oops, something went wrong.