自定义元排序

时间:2018-03-12 22:02:40

标签: django python-3.x

这是我的元模型信息(Django 2)。

# Powershell script for Document Generation
#
# This generates an XML schema per c# class and combines them in to a unified Trace.xsd file
# We use this in Adobe AEM.  See JIRA:TLAE-38.

# To run this:
# 1. Generate the $DLL - In Visual Studio open a file in Daff.Lae.TraceCommon
# 2. Run Build (menu) > Build Daff.Lae.TraceCommon
#    The file built is $DLL listed below
# 3. Open a powershell in this directory
# 4. .\xsdSchemaAllClasses.ps1 to run this
#    The output will be the $TRACEOUTFILE 
#
# Requirements:
#   1. xsd.exe should be in the $env:Path
# NOTES:
#    This will overwrite $TRACEOUTFILE so make sure that you have copied it elsewhere if you care
# about the previous version and worry that this script may fail.

$OUTDIR="./xsds"
$TRACEOUTFILE = "./trace.xsd"
$TraceCommon="..\..\Src2\Projects\Daff.Lae.TraceCommon"
$DLL = $TraceCommon+"\bin\Debug\Daff.Lae.TraceCommon.dll"
$sourceFilesDir = $TraceCommon+"\ValueObjects"
$encoding = "ASCII"

function setup {
    if ($OUTDIR | Test-Path){
        Remove-Item -Recurse -Force $OUTDIR
    }
    #  | out-null is to prevent the annoying dir listing output
    New-Item -ItemType "directory" $OUTDIR | out-null
    if($TRACEOUTFILE | Test-Path){
        Remove-Item $TRACEOUTFILE
    }
}

function moveFile([string] $inFile, [string] $outFile) {
    if ($inFile | Test-Path) {
        Write-Output "Move file - $inFile to $outFile"
        Move-Item -Path $inFile $outFile
    } else {
        Write-Output "Move file - $inFile to $outFile - INFILE doesnt exist"
    }
}

# Run the SQL Query for each TRACE table and produce clean well-formed and valid XML Schema output
function processFiles {
    $CSFiles = Get-ChildItem -Path $sourceFilesDir  -Recurse -ErrorAction SilentlyContinue *cs #| Select-Object -Property FullName

    $i = 99999; # Debug - Set to max number of files to process
    foreach($item in $CSFiles){
        Write-Output "------------------------------------------------------------------"
        Write-Output "Item: $item"
        $file = Split-Path -Path $item -leaf
        $class = $file.Replace(".cs", "")
        xsd $DLL /t:$class | Out-Null
        $outFile = $OUTDIR+"/"+$class+".xsd"
        moveFile "./schema0.xsd" $outFile
        if (--$i -le 0) {
            break;
        }

    }
}

# We want one Trace XML Schema file made up of all the ones for each table
function combineFiles {
    $SchemaFiles = Get-ChildItem $OUTDIR -Filter *.xsd
    $firstFile = 1
    foreach($sfile in $SchemaFiles) {
        $fname = $sfile | Select-Object -expandproperty name
        $fPath = $OUTDIR+"/"+$fname
        Write-Output "file: $fPath"
        Write-Output "<!-- file: $fPath -->" | Out-File -Append $TRACEOUTFILE -Encoding $encoding
        if ($firstFile) {   # If its the first file
            # Include the XSD header from the first file (and exclude it from all others)
            (Get-Content $fPath |
                    Select-String -Pattern "</xs:schema>" -SimpleMatch -NotMatch |
                    Out-String) |
                    Out-File -Append $TRACEOUTFILE -Encoding $encoding
            $firstFile = 0
        } else {
            Get-Content $fPath |
                Select-String -Pattern "<?xml version" -SimpleMatch -NotMatch |
                Select-String -Pattern "<xs:schema" -SimpleMatch -NotMatch |
                Select-String -Pattern "<xs:import" -SimpleMatch -NotMatch |
                Select-String -Pattern "</xs:schema>" -SimpleMatch -NotMatch |
                Out-File -Append $TRACEOUTFILE -Encoding $encoding
        }
    }
    Write-Output "</xs:schema>" | Out-File -Append $TRACEOUTFILE -Encoding $encoding
}

function main {
    setup
    processFiles
    combineFiles
    Write-Output "------------------------------------------------------------------"
    Write-Output "Output XML Schema file is: $TRACEOUTFILE"
}

main

我想知道我是否可以动态评估class Meta: managed = True db_table = 'mydb' ordering = ['in_stock', '-type', 'sale_price', 'name'] 属性。

例如: 如果是in_stock,则为in_stock=0,否则为in_stock=50。我的模型应该按照条件的结果排序。

这甚至可能吗?

0 个答案:

没有答案