user 4 年之前
当前提交
a9d6d98b11
共有 40 个文件被更改,包括 538 次插入0 次删除
  1. 8 0
      .idea/.gitignore
  2. 11 0
      .idea/dataSources.xml
  3. 6 0
      .idea/inspectionProfiles/profiles_settings.xml
  4. 7 0
      .idea/misc.xml
  5. 8 0
      .idea/modules.xml
  6. 28 0
      .idea/testthree.iml
  7. 6 0
      .idea/vcs.xml
  8. 15 0
      Pipfile
  9. 77 0
      Pipfile.lock
  10. 二进制
      __pycache__/manage.cpython-37.pyc
  11. 0 0
      db.sqlite3
  12. 二进制
      lvsh_django
  13. 21 0
      manage.py
  14. 0 0
      testthree/__init__.py
  15. 二进制
      testthree/__pycache__/__init__.cpython-37.pyc
  16. 二进制
      testthree/__pycache__/settings.cpython-37.pyc
  17. 二进制
      testthree/__pycache__/urls.cpython-37.pyc
  18. 二进制
      testthree/__pycache__/wsgi.cpython-37.pyc
  19. 16 0
      testthree/asgi.py
  20. 138 0
      testthree/settings.py
  21. 24 0
      testthree/urls.py
  22. 16 0
      testthree/wsgi.py
  23. 0 0
      workreport/__init__.py
  24. 二进制
      workreport/__pycache__/__init__.cpython-37.pyc
  25. 二进制
      workreport/__pycache__/admin.cpython-37.pyc
  26. 二进制
      workreport/__pycache__/models.cpython-37.pyc
  27. 二进制
      workreport/__pycache__/serializer.cpython-37.pyc
  28. 二进制
      workreport/__pycache__/urls.cpython-37.pyc
  29. 二进制
      workreport/__pycache__/views.cpython-37.pyc
  30. 3 0
      workreport/admin.py
  31. 5 0
      workreport/apps.py
  32. 32 0
      workreport/migrations/0001_initial.py
  33. 0 0
      workreport/migrations/__init__.py
  34. 二进制
      workreport/migrations/__pycache__/0001_initial.cpython-37.pyc
  35. 二进制
      workreport/migrations/__pycache__/__init__.cpython-37.pyc
  36. 15 0
      workreport/models.py
  37. 13 0
      workreport/serializer.py
  38. 3 0
      workreport/tests.py
  39. 31 0
      workreport/urls.py
  40. 55 0
      workreport/views.py

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/

+ 11 - 0
.idea/dataSources.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
+    <data-source source="LOCAL" name="lvsh_django" uuid="1cf7baaa-17de-45bd-bf83-b3ac5cb35cb2">
+      <driver-ref>sqlite.xerial</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>org.sqlite.JDBC</jdbc-driver>
+      <jdbc-url>jdbc:sqlite:E:\python\test\testthree\lvsh_django</jdbc-url>
+    </data-source>
+  </component>
+</project>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 7 - 0
.idea/misc.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptSettings">
+    <option name="languageLevel" value="ES6" />
+  </component>
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (lvshihai-w2fUPLQ-)" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/testthree.iml" filepath="$PROJECT_DIR$/.idea/testthree.iml" />
+    </modules>
+  </component>
+</project>

+ 28 - 0
.idea/testthree.iml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="django" name="Django">
+      <configuration>
+        <option name="rootFolder" value="$MODULE_DIR$" />
+        <option name="settingsModule" value="testthree/settings.py" />
+        <option name="manageScript" value="$MODULE_DIR$/manage.py" />
+        <option name="environment" value="&lt;map/&gt;" />
+        <option name="doNotUseTestRunner" value="false" />
+        <option name="trackFilePattern" value="migrations" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="jdk" jdkName="Python 3.7 (lvshihai-w2fUPLQ-)" jdkType="Python SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TemplatesService">
+    <option name="TEMPLATE_CONFIGURATION" value="Django" />
+    <option name="TEMPLATE_FOLDERS">
+      <list>
+        <option value="$MODULE_DIR$/../testthree\templates" />
+      </list>
+    </option>
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
+  </component>
+</project>

+ 15 - 0
Pipfile

@@ -0,0 +1,15 @@
+[[source]]
+name = "pypi"
+url = "https://mirrors.aliyun.com/pypi/simple"
+verify_ssl = true
+
+[dev-packages]
+
+[packages]
+djangorestframework = "*"
+mysqlclient = "*"
+djangorestframework-bulk = "*"
+django-filter = "*"
+
+[requires]
+python_version = "3.7"

+ 77 - 0
Pipfile.lock

@@ -0,0 +1,77 @@
+{
+    "_meta": {
+        "hash": {
+            "sha256": "a82a50f1ac082a5c593ae284fef3ad41c1207d45234dae53e38582c753d012eb"
+        },
+        "pipfile-spec": 6,
+        "requires": {
+            "python_version": "3.7"
+        },
+        "sources": [
+            {
+                "name": "pypi",
+                "url": "https://mirrors.aliyun.com/pypi/simple",
+                "verify_ssl": true
+            }
+        ]
+    },
+    "default": {
+        "asgiref": {
+            "hashes": [
+                "sha256:7e51911ee147dd685c3c8b805c0ad0cb58d360987b56953878f8c06d2d1c6f1a",
+                "sha256:9fc6fb5d39b8af147ba40765234fa822b39818b12cc80b35ad9b0cef3a476aed"
+            ],
+            "markers": "python_version >= '3.5'",
+            "version": "==3.2.10"
+        },
+        "django": {
+            "hashes": [
+                "sha256:31a5fbbea5fc71c99e288ec0b2f00302a0a92c44b13ede80b73a6a4d6d205582",
+                "sha256:5457fc953ec560c5521b41fad9e6734a4668b7ba205832191bbdff40ec61073c"
+            ],
+            "markers": "python_version >= '3.6'",
+            "version": "==3.0.8"
+        },
+        "djangorestframework": {
+            "hashes": [
+                "sha256:05809fc66e1c997fd9a32ea5730d9f4ba28b109b9da71fccfa5ff241201fd0a4",
+                "sha256:e782087823c47a26826ee5b6fa0c542968219263fb3976ec3c31edab23a4001f"
+            ],
+            "index": "pypi",
+            "version": "==3.11.0"
+        },
+        "djangorestframework-bulk": {
+            "hashes": [
+                "sha256:39230d8379acebd86d313df6c9150cafecb636eae1d097c30a26389ab9fee5b1"
+            ],
+            "index": "pypi",
+            "version": "==0.2.1"
+        },
+        "mysqlclient": {
+            "hashes": [
+                "sha256:3f39855a4ad22805361e782cc4d1010ac74796225fa2d1c03cc16673ccdc983a",
+                "sha256:a6b5648f648b16335e3b1aaec93dc3fcc81a9a661180e306936437cc522c810b",
+                "sha256:edd42ccaa444b00702d5374b2f5f7585c9d0ce201917f15339f1c3cf91c1b1ed",
+                "sha256:fb2f75aea14722390d2d8ddf384ad99da708c707a96656210a7be8af20a2c5e5"
+            ],
+            "index": "pypi",
+            "version": "==2.0.1"
+        },
+        "pytz": {
+            "hashes": [
+                "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed",
+                "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"
+            ],
+            "version": "==2020.1"
+        },
+        "sqlparse": {
+            "hashes": [
+                "sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e",
+                "sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548"
+            ],
+            "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
+            "version": "==0.3.1"
+        }
+    },
+    "develop": {}
+}

二进制
__pycache__/manage.cpython-37.pyc


+ 0 - 0
db.sqlite3


二进制
lvsh_django


+ 21 - 0
manage.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testthree.settings')
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError as exc:
+        raise ImportError(
+            "Couldn't import Django. Are you sure it's installed and "
+            "available on your PYTHONPATH environment variable? Did you "
+            "forget to activate a virtual environment?"
+        ) from exc
+    execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+    main()

+ 0 - 0
testthree/__init__.py


二进制
testthree/__pycache__/__init__.cpython-37.pyc


二进制
testthree/__pycache__/settings.cpython-37.pyc


二进制
testthree/__pycache__/urls.cpython-37.pyc


二进制
testthree/__pycache__/wsgi.cpython-37.pyc


+ 16 - 0
testthree/asgi.py

@@ -0,0 +1,16 @@
+"""
+ASGI config for testthree project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testthree.settings')
+
+application = get_asgi_application()

+ 138 - 0
testthree/settings.py

@@ -0,0 +1,138 @@
+"""
+Django settings for testthree project.
+
+Generated by 'django-admin startproject' using Django 3.0.8.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.0/ref/settings/
+"""
+
+import os
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'u5!o3szyjs=vxm(%vb)6qj73nfw9!_l7ed@%9(h10b#m=k8gku'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+# Application definition
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'rest_framework',
+    'django_filters',
+    'workreport',
+]
+
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'testthree.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = 'testthree.wsgi.application'
+
+# Database
+# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': "lvsh_django",
+        'USER': 'root',
+        'PASSWORD': 'abc.123',
+        'HOST': 'srv.test.linkerplus.com',
+        'PORT': '3310'
+    }
+}
+
+# Password validation
+# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.0/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.0/howto/static-files/
+
+STATIC_URL = '/static/'
+
+REST_FRAMEWORK = {
+    'DEFAULT_AUTHENTICATION_CLASSES': (
+        'rest_framework.authentication.BasicAuthentication',
+        'rest_framework.authentication.SessionAuthentication'
+    ),
+    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
+    'PAGE_SIZE': 10,
+    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
+    'DEFAULT_PERMISSION_CLASSES': [
+        'rest_framework.permissions.IsAuthenticated'
+    ]
+}
+
+# AUTHENTICATION_BACKENDS = (
+#     'django.contrib.auth.backends.ModelBackend'
+# )

+ 24 - 0
testthree/urls.py

@@ -0,0 +1,24 @@
+"""testthree URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/3.0/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.urls import include, path
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
+"""
+from django.conf.urls import url
+from django.contrib import admin
+from django.urls import path, include
+
+urlpatterns = [
+    path('admin/', admin.site.urls),
+    url(r'^api-auth/', include('rest_framework.urls')),
+    url(r'^report/', include('workreport.urls'))
+]

+ 16 - 0
testthree/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for testthree project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testthree.settings')
+
+application = get_wsgi_application()

+ 0 - 0
workreport/__init__.py


二进制
workreport/__pycache__/__init__.cpython-37.pyc


二进制
workreport/__pycache__/admin.cpython-37.pyc


二进制
workreport/__pycache__/models.cpython-37.pyc


二进制
workreport/__pycache__/serializer.cpython-37.pyc


二进制
workreport/__pycache__/urls.cpython-37.pyc


二进制
workreport/__pycache__/views.cpython-37.pyc


+ 3 - 0
workreport/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 5 - 0
workreport/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class WorkreportConfig(AppConfig):
+    name = 'workreport'

+ 32 - 0
workreport/migrations/0001_initial.py

@@ -0,0 +1,32 @@
+# Generated by Django 3.0.8 on 2020-07-16 03:36
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='DailyRreport',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(max_length=50)),
+                ('content', models.TextField()),
+                ('create_at', models.DateTimeField(auto_now=True)),
+                ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+            ],
+            options={
+                'verbose_name': '工作汇报',
+                'verbose_name_plural': '工作汇报表',
+                'db_table': 'workreport_daily',
+            },
+        ),
+    ]

+ 0 - 0
workreport/migrations/__init__.py


二进制
workreport/migrations/__pycache__/0001_initial.cpython-37.pyc


二进制
workreport/migrations/__pycache__/__init__.cpython-37.pyc


+ 15 - 0
workreport/models.py

@@ -0,0 +1,15 @@
+from django.contrib.auth.models import User
+from django.db import models
+
+# Create your models here.
+class DailyRreport(models.Model):
+    title = models.CharField(max_length=50)
+    content = models.TextField()
+    create_at = models.DateTimeField(auto_now=True)
+    create_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
+
+    class Meta:
+        app_label = 'workreport'
+        db_table = 'workreport_daily'
+        verbose_name = '工作汇报'
+        verbose_name_plural = '工作汇报表'

+ 13 - 0
workreport/serializer.py

@@ -0,0 +1,13 @@
+
+from rest_framework import serializers
+from rest_framework.serializers import ListSerializer
+
+from workreport.models import DailyRreport
+
+
+class DailyReportSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = DailyRreport
+        # fields = ['url', 'username', 'email', 'is_staff']
+        list_serializer = ListSerializer
+        fields = '__all__'

+ 3 - 0
workreport/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 31 - 0
workreport/urls.py

@@ -0,0 +1,31 @@
+"""testthree URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/3.0/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.urls import include, path
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
+"""
+from django.conf.urls import url
+from rest_framework_bulk.routes import BulkRouter
+
+from workreport.views import DailyReportView, ReportView, LogoutView, LoginView
+
+router = BulkRouter()
+# router = routers.DefaultRouter()
+router.register(r'dailyreport', DailyReportView)
+
+# urlpatterns = router.urls
+urlpatterns = router.urls
+urlpatterns += [
+    url(r'^report/', ReportView.as_view()),
+    url(r'^login/', LoginView.as_view()),
+    url(r'^logout/', LogoutView.as_view())
+]

+ 55 - 0
workreport/views.py

@@ -0,0 +1,55 @@
+from django.contrib.auth import login, logout
+from django.contrib.auth.backends import ModelBackend
+# Create your views here.
+from rest_framework import status, permissions
+from rest_framework.decorators import permission_classes
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from rest_framework.viewsets import ModelViewSet
+
+from workreport.models import DailyRreport
+from workreport.serializer import DailyReportSerializer
+
+
+class ReportView(APIView):
+    def get(self, request):
+        data = DailyRreport .objects.values('title', 'content', 'create_at', 'create_by', 'id')
+        return Response(data=data, status=status.HTTP_200_OK)
+
+    def post(self, request):
+        # pass
+        data = request.data
+        dailyRreport = DailyRreport(title = data['title'],
+                            content = data['content'],
+                            create_by_id = data['create_by_id'])
+        dailyRreport.save()
+        return Response(status = status.HTTP_201_CREATED)
+
+    def delete(self, request):
+        pass
+
+class DailyReportView(ModelViewSet):
+    queryset = DailyRreport.objects.all()
+    serializer_class = DailyReportSerializer
+    filter_fields = {'title': ['exact']}
+    def update(self, request, *args, **kwargs):
+        kwargs['partial'] = True
+        return super().update(request, *args, **kwargs)
+
+@permission_classes((permissions.AllowAny,))
+class LoginView(APIView):
+    def post(self, request):
+        data = request.data
+        user = ModelBackend().authenticate(username=data['username'], password=data['password'],request=request)
+        # user = authenticate(username=data['username'], password=data['password'], request=request)
+        if user is None:
+            return Response(data={'msg': '用户名或密码不正确'}, status=status.HTTP_404_NOT_FOUND)
+        else:
+            login(request, user=user, backend='django.contrib.auth.backends.ModelBackend')
+            # login(request, user=user)
+        return Response(status=status.HTTP_200_OK, data={'user_id': user.id})
+
+class LogoutView(APIView):
+    def post(self, request):
+        logout(request)
+        return Response(data={'msg': 'logout success!'}, status=status.HTTP_200_OK)