Example #1
0
def getree(request):
    '''get the dir or files'''

    dirs = request.GET.get("dir",None)
    url = request.GET.get("url","")
    tid = request.GET.get("tid","J_system_dir_root")
    pattern = "\.pyc$|^\.|\.py$|_import\.html|^font$|.*footer\.html$|Thumbs\.db$"
    dirHtml = dirTree(dirs, url, pattern,tid = tid)
    return HttpResponse(dirHtml)
Example #2
0
def v(request,t = "", tid = ""):
    '''user view'''

    uid = request.session.get("uid",0)

    if uid:
        cuser = sm.User.objects.get(id = uid)
    else:
        cuser = None


    WEIGHT_KEYS = WEIGHT.keys()
    WEIGHT_KEYS.sort()
    icon_guide_html = ""
    for key in WEIGHT_KEYS:
        icon_guide_html += '''<i class="item ''' + key + '''">&nbsp;</i>''' + WEIGHT[key]

    if t == "user" and tid == str(uid):
        pfix = "gallery"
        uname = u"我"
    else:
        pfix = t
        try:
            uname = sm.User.objects.get(id = tid).name_zh
        except sm.User.DoesNotExist:
            pass

    if t:
        try:
            model = sm.__dict__[t.capitalize()]
        except KeyError:
            return HttpResponse(u"404 page")
        allProjects = sm.Project.objects.all()
        allUsers    = sm.User.objects.all()
        allTasks    = sm.Task.objects.all()
        allGroups   = sm.Group.objects.all()
        allRights   = sm.Rights.objects.all()
    if not t and not tid:
        return HttpResponseRedirect("/")
    elif t and not tid:
        templates = "system/list_" + t + ".html"
        return render_to_response(templates,locals())
    else:
        templates = "system/details_" + t + ".html"
        obj = model.objects.get(id = tid)
        if t == "project":
            related_tasks = sm.Task.objects.filter(pid = tid).order_by("-id")
            related_users = sm.User_Project.objects.filter(pid = tid).order_by("-id")
            pattern = "\.pyc$|^\.|\.py$|_import.html|.*footer.*"
            path = sc.P_PROJECT_PATH + "/" + obj.name_en
            dirHtml = dirTree(path, "/p/", pattern)
            static_dir = sc.P_STATIC_PATH + "/" + obj.name_en

            psd_dir = sc.P_STATIC_PATH + "/" + obj.name_en + "/_psd"

            try:
                psd_prefix_file = open(psd_dir + "/.filelist")
                psd_prefix = cp.load(psd_prefix_file).get("prefix","")
                psd_prefix_file.close()
            except:
                psd_prefix = ""


            staticHtml = dirTree(sc.P_STATIC_PATH + "/" + obj.name_en,'/s/static/',"\.pyc$|^\.|\.py$|^font$|^_psd$",tid = "J_static_dir")
            #----ry code
            dirHtml = dirHtml
            #----ry code
        elif t == "task":
            related_users = sm.User_Task.objects.filter(tid = tid).order_by("-id")
        elif t == "user":
            related_tasks = sm.User_Task.objects.filter(uid = tid).order_by("-id")
            related_projects = sm.User_Project.objects.filter(uid = tid).order_by("-id")
        return render_to_response(templates,locals())
Example #3
0
def p(request,p = "", tpl = ""):
    '''view page'''

    import time

    src = request.SRC
    static = request.STATIC

    pfix = p

    pdir = sc.P_PROJECT_PATH

    stamp = "?v=" + str(time.time())
    if p:
        static_path = sc.P_STATIC_PATH + "/" + p
        tpl_path = sc.P_PROJECT_PATH + "/" + p

        pattern = "\.pyc$|^\.|\.py$|_import.html|.*footer.*"
        dirHtml = dirTree(tpl_path, "/p/", pattern)
        dirHtml = re.sub("\n","",dirHtml)

        try:
            pobj = sm.Project.objects.get(name_en = p)
        except sm.Project.DoesNotExist:
            pobj = None

    if not p and not tpl:
        return HttpResponseRedirect("/v/project/")
    elif p and not tpl:
        if pobj:
            dirHtml = dirTree(tpl_path, "/p/", pattern)
            return render_to_response("system/dir.html",locals())
        else:
            return HttpResponse(u"404 page")
    else:
        css_reg = re.compile("\w+\.css$")
        js_reg = re.compile("\w+\.js$")
        less_reg = re.compile("\w+\.less$")
        tpl_filter = re.compile("^(.*\/)?_.*\.html$")
        merge_reg = re.compile("_merge.html$")
        import_reg = re.compile("_import.html$")
        if tpl.find("/") != -1:
            subDir = tpl[0:tpl.find("/")]
        else:
            subDir = None
        if os.path.exists(static_path):
            files = []
            for item in sc.STATIC_TYPE:
                files.extend([item + "/" +f for f in os.listdir(static_path + "/" + item) if not os.path.isdir(static_path + "/" + item + "/" + f)])
                if subDir:
                    subFiles = walkDir([static_path + "/" + item + "/" + subDir],formats = "relative")["files"]
                    files.extend(item + "/" + subDir + "/" + f for f in subFiles)
            files.sort()
            files.reverse()
        if os.path.exists(tpl_path):
            tplfiles = [f for f in os.listdir(tpl_path) if not os.path.isdir(tpl_path + "/" + f)]
            if subDir:
                subFiles = walkDir([tpl_path + "/" + subDir],formats = "relative")["files"]
                tplfiles.extend(subDir + "/" + f for f in subFiles)

            tpls = [f for f in tplfiles if tpl_filter.search(f)]
            tpls.sort()

       
        #如果是目录,则显示目录树
        if os.path.isdir(tpl_path + "/" + tpl):
            dirHtml = dirTree(tpl_path + "/" + tpl, "/p/", pattern)
            return render_to_response("system/dir.html",locals())
        #否则显示相应页面
        else:
            try:
                return render_to_response("system/view.html",locals())
            except:
                return HttpResponse(sys.exc_info()[0])