Ejemplo n.º 1
0
    def get(self, modelName, *args, **kwargs):
        package, aimModel = self.getModelByName(modelName)
        if aimModel == None:
            self._reason = '您所请求的模型不存在或者并未被注册'
            self._status_code = 404
            self.write_error(404)
            return None
        # show this model
        # get all valid field
        allValidField = self.getValidFieldByModel(aimModel)
        allFieldName = [
            getattr(aimModel, foo) for (foo, instance) in allValidField
        ]
        # set up query
        total_record_cnt = aimModel.select().count()
        query = (aimModel.select(*allFieldName))
        #for foo in query:
        #    for attrName in [f o for (fo,instance) in allValidField]:
        #        print attrName,getattr(foo,attrName)

        modelsFinder = modelFinder()
        # a tuple containing three element : app,className,class
        modelsList = modelsFinder.getInstalledModel()

        args = locals()
        args.pop('self')
        self.render('contrib/admin/tableData.html', **args)
Ejemplo n.º 2
0
 def render(self, *args, **kwargs):
     from contrib.admin.appModel import modelFinder
     modelsFinder = modelFinder()
     # a tuple containing three element : app,className,class
     modelsList = modelsFinder.getInstalledModel()
     args = locals()
     args.pop('self')
     return self.render_string('contrib/admin/leftSideBar.html',**args)
Ejemplo n.º 3
0
    def getModelByName(self, modelName):
        '''
        get model by model's name
        :param modelName: model class
        :return:model class or None object
        '''
        modelFinderInstance = modelFinder()
        packageModels = modelFinderInstance.getInstalledModel()
        # traverse all list then find it

        for package, list in packageModels:
            for name, model in list:
                if name == modelName:
                    return package, model
        return None
Ejemplo n.º 4
0
    def get(self, *args, **kwargs):
        import psutil
        import platform
        # cpu info
        logicalCPU = psutil.cpu_count(logical=True)
        physicsCPU = psutil.cpu_count(logical=False)

        # platform uname
        (system, node, release, version, machine, processor) = platform.uname()

        # cpu usage
        usedCPURate = psutil.cpu_percent(interval=1, percpu=False)

        # memory info
        mem = psutil.virtual_memory()

        # start time
        startTime = psutil.boot_time()

        # network statistics
        network = psutil.net_io_counters(pernic=False)

        from conf.urls import urlPackage
        from conf import setting
        Setting = setting()
        Setting._setup()

        logFileExist = getattr(Setting._wrapped, 'LOGFILE', False)

        modelsFinder = modelFinder()
        # a tuple containing three element : app,className,class
        modelsList = modelsFinder.getInstalledModel()

        # fill render parameter
        args = locals()
        args.pop('self')
        self.render('contrib/admin/manage.html', **args)
Ejemplo n.º 5
0
__author__ = 'kidozh'
# -*- coding: UTF-8 -*-
import os
from conf import ENVIRONMENT_VARIABLE
os.environ[ENVIRONMENT_VARIABLE] = 'setting'

from contrib.admin.appModel import modelFinder
from db import database

import sys

if len(sys.argv) != 2:
    print('''Only one argv is supported''')
else:
    if sys.argv[1] == 'migrate':
        modelsFinder = modelFinder()
        # a tuple containing three element : app,className,class
        modelsList = modelsFinder.getInstalledModel()
        models = [model for name,package in modelsList for dname,model in package if model!= []]
        print 'These models are searched : ', models
        print database.create_tables(models,safe=True)
    elif sys.argv[1] == 'createsuperuser':
        from db import database
        from contrib.admin.models import admin

        database.connect()
        try:
            database.create_tables([admin])
        except:
            pass
        print '''  TJANGO Create administrator '''