我有两个表,ProductGroup和ProductBrand,这些是我的模型
import os
from datetime import datetime, date, timedelta
import subprocess
import pyjq
import pandas as pd
# Initializes the variables for the directories
HomeDir = "Users/kiya/Downloads/"
ScriptDir = HomeDir + "pan-python-0.12.0 2"
ResultDir = HomeDir + "techscroll/"
# Create the dates
ToDay = datetime.now().strftime('%Y%m%d')
# checkDATE = (date.today() - timedelta(1)).strfttime('%Y%m%d')
ResultFile = "Test"
CheckDATE = "Test"
NOWDATE = "TEST"
# Run the panafpi
subprocess.check_output('python ' + ScriptDir + '/bin/panafapi.py -K secretkey --samples -j -r "{\"query\":{\"operator\":\"all\",\"children\":[{\"field\":\"alias.ip_address\",\"operator\":\"contains\",\"value\":\"' + ResultFile + '\"},{\"operator\":\"any\",\"children\":[{\"field\":\"sample.update_date\",\"operator\":\"is in the range\",\"value\":[\"' + CheckDATE + 'T00:00:00\",\"$' + NOWDATE + 'T23:59:59\"]},{\"field\":\"sample.create_date\",\"operator\":\"is in the range\",\"value\":[\"' + CheckDATE + 'T00:00:00\",\"' + NOWDATE + 'T23:59:59\"]},{\"operator\":\"any\",\"children\":[{\"field\":\"sample.malware\",\"operator\":\"is\",\"value\":1},{\"field\":\"sample.malware\",\"operator\":\"is\",\"value\":4}]}]}]},\"scope\":\"global\",\"size\":1,\"from\":0,\"sort\":{\"create_date\":{\"order\":\"desc\"}}}" > ' + ResultDir + 'srciplist-' + ToDay + '.json', shell=True)
# Using pyjq to filter
filteredResultData = pyjq.all('.hits[]._source | .create_date + "," + .sha256')
# Save the JSON file to comma-separated file
pd.to_csv(ResultDir + "/srciplist-" + ToDay + ".csv", sep=",")
和
/bin/sh: Users/kiya/Downloads/techscroll/srciplist-20180125.json: No such file or directory
Traceback (most recent call last):
File "/Users/mani/Downloads/tester (1).py", line 22, in <module>
subprocess.check_output('python ' + ScriptDir + '/bin/panafapi.py -K secretkey --samples -j -r "{\"query\":{\"operator\":\"all\",\"children\":[{\"field\":\"alias.ip_address\",\"operator\":\"contains\",\"value\":\"' + ResultFile + '\"},{\"operator\":\"any\",\"children\":[{\"field\":\"sample.update_date\",\"operator\":\"is in the range\",\"value\":[\"' + CheckDATE + 'T00:00:00\",\"$' + NOWDATE + 'T23:59:59\"]},{\"field\":\"sample.create_date\",\"operator\":\"is in the range\",\"value\":[\"' + CheckDATE + 'T00:00:00\",\"' + NOWDATE + 'T23:59:59\"]},{\"operator\":\"any\",\"children\":[{\"field\":\"sample.malware\",\"operator\":\"is\",\"value\":1},{\"field\":\"sample.malware\",\"operator\":\"is\",\"value\":4}]}]}]},\"scope\":\"global\",\"size\":1,\"from\":0,\"sort\":{\"create_date\":{\"order\":\"desc\"}}}" > ' + ResultDir + 'srciplist-' + ToDay + '.json', shell=True)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'python Users/kiya/Downloads/pan-python-0.12.0 2/bin/panafapi.py -K secret key --samples -j -r "{"query":{"operator":"all","children":[{"field":"alias.ip_address","operator":"contains","value":"Test"},{"operator":"any","children":[{"field":"sample.update_date","operator":"is in the range","value":["TestT00:00:00","$TESTT23:59:59"]},{"field":"sample.create_date","operator":"is in the range","value":["TestT00:00:00","TESTT23:59:59"]},{"operator":"any","children":[{"field":"sample.malware","operator":"is","value":1},{"field":"sample.malware","operator":"is","value":4}]}]}]},"scope":"global","size":1,"from":0,"sort":{"create_date":{"order":"desc"}}}" > Users/kiya/Downloads/techscroll/srciplist-20180125.json' returned non-zero exit status 1.
这是我的部分视图,显示了动态的大型菜单
public partial class ProductBrand
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public ProductBrand()
{
this.ProductGroup = new HashSet<ProductGroup>();
}
public int ProductBrandID { get; set; }
public string ProductBrandTitle { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ProductGroup> ProductGroup { get; set; }
}
这是控制器
public partial class ProductGroup
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public ProductGroup()
{
this.Products = new HashSet<Products>();
}
public int ProductGroupID { get; set; }
public int ProductBrandID { get; set; }
public string ProductGroupTitle { get; set; }
public virtual ProductBrand ProductBrand { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Products> Products { get; set; }
}
我希望展示具有特殊productbrandid的productgroup,并在其productbrand下显示每个产品组,但它显示每个产品品牌下的所有产品组
答案 0 :(得分:0)
@using BehinFaraz.Models
@model Tuple<IEnumerable<ProductBrand>, IEnumerable<ProductGroup>>
<li class="dropdown dropdown-mm" dir="rtl">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <b class="caret"></b></a>
<!-- Dropdown Menu -->
<ul class="dropdown-menu dropdown-menu-mm dropdown-menu-persist">
<li class="row" dir="rtl">
<ul class="col-md-6">
@foreach (var item1 in Model.Item1)
{
<li class="dropdown-header "><font color='#01747b'><strong> @item1.ProductBrandTitle</strong></font></li>
foreach (var item2 in Model.Item2.Where(model=>model.ProductBrandID==model.ProductBrand.ProductBrandID) )
{
<li>@Html.ActionLink(item2.ProductGroupTitle,"ShowProductByGroup","Product",new {id=item2.ProductGroupID})</li>
}
}
</ul>
</li>
</ul>
答案 1 :(得分:0)
我认为这应该是正确的,假设您正确地从数据库中撤回数据,遗憾的是您没有显示。
您已经有IEnumerable<ProductGroup>
作为ProductBrand的属性(查看您的ProductBrand类的属性!)。这定义了品牌与集团之间的关系。所以模型可以只是一个IEnumerable<ProductBrand>
。您可以遍历品牌,并为每个品牌,然后遍历品牌内的所有产品。
隐含哪些ProductGroup对象属于哪个ProductBrand,因为它们已经被列为ProductBrand特定实例的属性:
@using BehinFaraz.Models
@model IEnumerable<ProductBrand>
<li class="dropdown dropdown-mm" dir="rtl">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <b class="caret"></b></a>
<!-- Dropdown Menu -->
<ul class="dropdown-menu dropdown-menu-mm dropdown-menu-persist">
<li class="row" dir="rtl">
<ul class="col-md-6">
@foreach (ProductBrand brand in Model)
{
<li class="dropdown-header "><font color='#01747b'><strong> @brand.ProductBrandTitle</strong></font></li>
foreach (ProductGroup group in brand.ProductGroup )
{
<li>@Html.ActionLink(group.ProductGroupTitle,"ShowProductByGroup","Product",new {id=group.ProductGroupID})</li>
}
}
</ul>
</li>
</ul>