online adaptation
authorHongyuan Ma <CS_MaleicAcid@163.com>
Mon, 6 Aug 2018 18:25:37 +0000 (02:25 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Mon, 6 Aug 2018 18:25:37 +0000 (02:25 +0800)
17 files changed:
front-end/src/page/machine/index.jsx
front-end/src/page/portal/index.jsx
front-end/src/service/machine-service.jsx
front-end/src/service/record-service.jsx
front-end/src/service/user-service.jsx
front-end/src/util/machine-record-table/index.jsx
front-end/src/util/machine-table/index.jsx
web/apps/user_operation/filters.py
web/apps/user_operation/views.py
web/apps/users/admin.py
web/apps/users/views.py
web/extra_apps/pg_auth/__init__.py [moved from web/extra_apps/auth/__init__.py with 100% similarity]
web/extra_apps/pg_auth/auth.py [moved from web/extra_apps/auth/auth.py with 100% similarity]
web/pgperffarm/settings.py
web/pgperffarm/urls.py
web/templates/admin/login.html [deleted file]
web/templates/admin_bak/login.html [new file with mode: 0644]

index be5914fdf2f9a704740f03679b75f50c9b59a6d9..6e0edb8d5645c66596aade591449de689ff28034 100644 (file)
@@ -17,18 +17,15 @@ class Machine extends React.Component {
             total: 3,
             machines: [],
         },
-
-        // this.onPageChange = this.onPageChange.bind(this);
-
-        this.loadMachineList = this.loadMachineList.bind(this);
+            this.loadMachineList = this.loadMachineList.bind(this);
     }
 
-    componentDidMount(){
+    componentDidMount() {
         this.loadMachineList();
     }
 
-    loadMachineList(page=1){
-        _machine.getMachineList().then(res => {
+    loadMachineList(page = 1) {
+        _machine.getMachineList(page).then(res => {
             this.setState({
                 machines: res.results,
                 total: res.count,
@@ -50,7 +47,8 @@ class Machine extends React.Component {
                     Use the farm member link for history of that member on the relevant branch.
                 </p>
 
-                <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>
+                <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage}
+                              loadfunc={this.loadMachineList}/>
 
             </div>
         )
index e6c968bed301d3b76b77cf09f4aa9c74f43c4c22..b730709699078280a9da13f6544398c9ed58faf5 100644 (file)
@@ -16,25 +16,27 @@ class Portal extends React.Component {
         super(props);
         this.state = {
             username: '',
-            isLoading: false,
             machines:[],
             userinfo: {}
         }
-
+        this.loadUserMachineManageList = this.loadUserMachineManageList.bind(this);
     }
     componentDidMount(){
 
         let user = _util.getStorage('userInfo')
         this.setState({
             username: user.username,
+        },()=>{
+            this.loadUserPortalInfo()
+            this.loadUserMachineManageList();
         });
         console.log(user.token)
-        this.loadUserPortalInfo()
-        this.loadUserMachineManageList();
+
     }
 
     loadUserPortalInfo(){
-        _user.getUserPortalInfo().then(res => {
+        let username = this.state.username
+        _user.getUserPortalInfo(username).then(res => {
             this.setState({
                 userinfo: res.results,
             });
@@ -44,11 +46,14 @@ class Portal extends React.Component {
     }
 
     loadUserMachineManageList(page=1){
-        _user.getUserMachineManageList().then(res => {
+
+        let listParam = {};
+        listParam.page = page;
+        listParam.machine_owner__username = this.state.username;
+        _user.getUserMachineManageList(listParam).then(res => {
             this.setState({
                 machines: res.results,
                 total: res.count,
-                isLoading: false
             });
         }, errMsg => {
             _util.errorTips(errMsg);
@@ -98,7 +103,7 @@ class Portal extends React.Component {
                         <h2 >Welcome Back, {this.state.username}</h2>
                     </div>
 
-                    <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>
+                    <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadUserMachineManageList}/>
                 </div>
             </div>
 
index 9b5188bd65bd1ef0c741ec241a790d53afa3b3b3..7278665a0f85068e831bde8a713ca84c7fe4cd3f 100644 (file)
@@ -4,13 +4,13 @@ import PGConstant from 'util/constant.jsx'
 const _util       = new PGUtil();
 
 class MachineService{
-    getMachineList(pageNum){
+    getMachineList(page){
         let url = PGConstant.base_url + '/machines';
         return _util.request({
             type    : 'get',
             url     : url,
             data    : {
-                pageNum : pageNum
+                page : page
             }
         });
     }
index 3aa81c4b6404af85c4d4f26765ef8ccbfe9971e0..62ff12ac6f7c18e285eb2d210abbf2c6afa8eaea 100644 (file)
@@ -75,8 +75,8 @@ class Record{
         let data = {};
         data = listParam;
 
-        console.log('final data')
-        console.dir(listParam);
+        // console.log('final data')
+        // console.dir(listParam);
         return _util.request({
             type    : 'get',
             url     : url,
index f12395e2023d890a7665da057023b8f6c66dffb0..b6971429444f584833c76f868aa64aeb1d2364c8 100644 (file)
@@ -45,23 +45,25 @@ class User{
         return true;
     }
 
-    getUserMachineManageList(pageNum){
+    getUserMachineManageList(listParam){
         let url = PGConstant.base_url + '/my-machine';
         return _util.request({
             type    : 'get',
             url     : url,
-            data    : {
-                pageNum : pageNum
-            }
+            data    : listParam
+        //     listParam.page = page;
+        //     listParam.username = this.state.username;
         });
     }
 
-    getUserPortalInfo(){
+    getUserPortalInfo(username=''){
         let url = PGConstant.base_url + '/portal/';
         return _util.request({
             type    : 'get',
             url     : url,
-            data    : {}
+            data    : {
+                username : username
+            }
         });
     }
 
index c8b999adc51f633432aecf80f3ee9fc5db8c2a51..91ef3d33f7d3e79717640bd2f6dfed78d3d5cbd9 100644 (file)
@@ -29,12 +29,12 @@ class MachineRecordTable extends React.Component {
         }
     }
 
-
     onPageNumChange(current) {
+        let _this = this
         this.setState({
             currentPage: current
         }, () => {
-            this.props.loadfunc(current);
+            _this.props.loadfunc(current);
         });
         console.log('current:' + this.state.currentPage)
     }
index e18001f57a8e03024bc97a1949d789f3ec32a372..21ec17f706e1a2b38becdc09df77f476f5ecaf94 100644 (file)
@@ -33,10 +33,11 @@ class MachineTable extends React.Component {
 
 
     onPageNumChange(current) {
+        let _this = this
         this.setState({
             currentPage: current
         }, () => {
-            this.props.loadfunc(current);
+            _this.props.loadfunc(current);
         });
         console.log('current:' + this.state.currentPage)
     }
@@ -129,7 +130,7 @@ class MachineTable extends React.Component {
                     <Table.Row>
                         <Table.HeaderCell colSpan='10'>
 
-                            <Pagination style={style} onChange={(current) => this.onPageNumChange(current)} pageSize={15}
+                            <Pagination style={style} onChange={(current) => this.onPageNumChange(current)} pageSize={40}
                                         current={this.state.currentPage} total={this.props.total}/>
                         </Table.HeaderCell>
 
index 7208055bd0a6b94459a0381cdeb1e7d770228678..d429d96f22f5c1806a644d6925035e82e85ebfb8 100644 (file)
@@ -3,6 +3,7 @@
 import django_filters
 from django.db.models import Q
 
+from models import UserMachine
 from test_records.models import TestRecord
 
 
@@ -15,4 +16,16 @@ class MachineRecordListFilter(django_filters.rest_framework.FilterSet):
 
     class Meta:
         model = TestRecord
-        fields = ['branch__id', 'test_machine__machine_sn']
\ No newline at end of file
+        fields = ['branch__id', 'test_machine__machine_sn']
+
+
+class UserMachineListFilter(django_filters.rest_framework.FilterSet):
+    """
+    UserMachineListFilter
+    """
+
+    # machine_owner__username = django_filters.CharFilter()
+
+    class Meta:
+        model = UserMachine
+        fields = ['machine_owner__username', ]
\ No newline at end of file
index ab38fc029247661ceb22952c5d779f4a3aac278c..c006723e72f9bd63043b3b858c9a4009bf15ee36 100644 (file)
@@ -2,26 +2,29 @@
 from __future__ import unicode_literals
 
 import django_filters
-from django.shortcuts import render
-from rest_framework import mixins, viewsets, permissions, status
+from rest_framework import mixins, viewsets, permissions
 
 from rest_framework import authentication
 from rest_framework.pagination import PageNumberPagination
-from rest_framework.response import Response
-from rest_framework.views import APIView
 from rest_framework_jwt.authentication import JSONWebTokenAuthentication
 
-from filters import MachineRecordListFilter
+from filters import MachineRecordListFilter, UserMachineListFilter
 from test_records.models import TestRecord
-from util.response import PGJsonResponse
 from users.models import UserMachine, UserProfile
-from serializer import UserMachineManageSerializer, UserPortalInfoSerializer, TestRecordListSerializer
+from serializer import UserMachineManageSerializer, UserPortalInfoSerializer, TestRecordListSerializer, \
+    UserMachineSerializer
+
 
 class StandardResultsSetPagination(PageNumberPagination):
     page_size = 2
     page_size_query_param = 'page_size'
     max_page_size = 100
 
+class MiddleResultsSetPagination(PageNumberPagination):
+    page_size = 40
+    page_size_query_param = 'page_size'
+    max_page_size = 100
+
 
 class UserMachineRecordByBranchListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     """
@@ -34,8 +37,6 @@ class UserMachineRecordByBranchListViewSet(mixins.ListModelMixin, viewsets.Gener
     filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
     filter_class = MachineRecordListFilter
 
-
-
 class UserMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     """
     List test records
@@ -44,7 +45,21 @@ class UserMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     permission_classes = (permissions.IsAuthenticated, )
     queryset = UserMachine.objects.all().order_by('add_time')
     serializer_class = UserMachineManageSerializer
-    # pagination_class = StandardResultsSetPagination
+    pagination_class = MiddleResultsSetPagination
+    filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
+    filter_class = UserMachineListFilter
+
+    # def perform_create(self, serializer):
+    #     shop_cart = serializer.save()
+    #     goods = shop_cart.goods
+    #     goods.goods_num -= shop_cart.nums
+    #     goods.save()
+
+    # def get_serializer_class(self):
+    #     if self.action == 'create':
+    #         return UserMachineSerializer
+    #     else:
+    #         return UserMachineManageSerializer
 
 class PublicMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     """
@@ -52,14 +67,16 @@ class PublicMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     """
     queryset = UserMachine.objects.all().order_by('add_time')
     serializer_class = UserMachineManageSerializer
+    pagination_class = MiddleResultsSetPagination
 
-class UserPortalInfoViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
+class UserPortalInfoViewSet( mixins.RetrieveModelMixin, viewsets.GenericViewSet):
     """
      user info
     """
     # authentication_classes = (JSONWebTokenAuthentication, authentication.SessionAuthentication )
     # permission_classes = (permissions.IsAuthenticated, )
-    queryset = UserProfile.objects.all().order_by('date_joined')
+    lookup_field = 'username'
+    queryset = UserProfile.objects.all()
     serializer_class = UserPortalInfoSerializer
 
 class UserMachinePermission(permissions.BasePermission):
index bf81a3e6e0acff3b878a197a96dd0907a379795b..f9224ff85046d58f5afdf5a11f16c8177b24dcf2 100644 (file)
@@ -6,8 +6,14 @@ from asynchronous_send_mail import send_mail
 from django.conf import settings
 # Register your models here.
 from serializer import UserMachineSerializer
-from .models import UserMachine
+from .models import UserMachine, UserProfile
 
+class UserProfileAdmin(admin.ModelAdmin):
+    list_display = ('id', 'username', 'email', 'is_active', 'last_login', )
+    list_filter = ('is_active',)
+
+
+admin.site.register(UserProfile, UserProfileAdmin)
 
 class UserMachineAdmin(admin.ModelAdmin):
     list_display = ('id', 'alias', 'state', 'machine_sn', 'machine_secret', )
@@ -58,3 +64,6 @@ PG PERF FARM" % (ret['alias'], ret['secret'], ret['system'], ret['compiler'])
 
 
 admin.site.register(UserMachine, UserMachineAdmin)
+
+
+
index 6ba4b36029924481cbeaf370a66e95ba4003fb7e..5a4457fbb73628fb76c9d7206e2041d4de3583e3 100644 (file)
@@ -14,6 +14,7 @@ class CustomBackend(ModelBackend):
     """
     custom user auth
     """
+    # todo use auth.py
     def authenticate(self, username=None, password=None, **kwargs):
         try:
             user = UserProfile.objects.get(Q(username=username))
index 76e784519255375258a0b9699bcdfb61664bad14..f5b3385178d5d500d223cbf4d26dd18bd3e61a5d 100644 (file)
@@ -38,8 +38,8 @@ ALLOWED_HOSTS = []
 # Application definition
 
 INSTALLED_APPS = (
-    'corsheaders',
     'django.contrib.admin',
+    'corsheaders',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
index 110a62f4187e98a7bafe98e1f85d3c5405e1d199..245faec6e9abaf10064db473aecca06921733bd1 100644 (file)
@@ -45,11 +45,11 @@ router.register(r'machine-records-by-branch', UserMachineRecordByBranchListViewS
 # user's machine manage list
 router.register(r'my-machine', UserMachineListViewSet, base_name="my-machine")
 # get userinfo on portal page
-router.register(r'portal', UserPortalInfoViewSet, base_name="portal")
+router.register(r'^portal/', UserPortalInfoViewSet, base_name="portal")
 
 urlpatterns = [
-    url(r'^admin/', admin.site.urls),
-
+    url(r'^perf_farm_admin/', admin.site.urls),
+    # url(r'^admin/', include(admin.site.urls)),
     url(r'^api-auth/', include('rest_framework.urls')),
 
 
@@ -60,14 +60,8 @@ urlpatterns = [
 
     url(r'^machine-token-auth/', MachineAuthToken.as_view()),
     url(r'^', include(router.urls)),
-    # url(r'status/$', test_record_list, name='test-list'),
-    # url(r'status/$', TestListView.as_view(), name='test-list'),
-    # url(r'detail', TestRecordDetailViewSet ,name="detail"),
-    url(r'upload/$', TestRecordCreate, name='test-upload'),
-    # url(r'status-records/$', GetStatusRecordList, name='status-records'),
 
-    # url(r'portal/$', UserPortalInfoViewSet, name='portal'),
-    # url(r'my-machine/$', UserMachineList.as_view(), name='my-machine'),
+    url(r'upload/$', TestRecordCreate, name='test-upload'),
 
     url(r'docs/', include_docs_urls(title='pgperffarm')),
     # Static pages
diff --git a/web/templates/admin/login.html b/web/templates/admin/login.html
deleted file mode 100644 (file)
index e9e7257..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url={% url 'pgperffarm.auth.login' %}/?next=/admin/"></meta>
-</head>
-<body>
-<h1>Redirect</h1>
-<p>
-Redirect <a href="{% url 'pgperffarm.auth.login' %}/?next=/admin/">here</a>
-</p>
-</body>
-</html>
\ No newline at end of file
diff --git a/web/templates/admin_bak/login.html b/web/templates/admin_bak/login.html
new file mode 100644 (file)
index 0000000..224d856
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0;url={% url 'login' %}/?next=/admin/"></meta>
+</head>
+<body>
+<h1>Redirect</h1>
+<p>
+Redirect <a href="{% url login' %}/?next=/admin/">here</a>
+</p>
+</body>
+</html>
\ No newline at end of file