桌子:
categories = Table("categories", metadata,
Column("id", Integer, primary_key=True),
Column("name", String),
Column("parent_id", Integer, ForeignKey("categories.id"),
CheckConstraint('id!=parent_id'), nullable=True),
)
Run Code Online (Sandbox Code Playgroud)
一个类别可以有很多孩子,但只有一个孩子.我使用CTE得到了如下字典值列表:例如.对于id:14,parent是13并且从父8-> 10-> 12-> 13-> 14遍历,其中父8没有父id.
[
{
"id": 14,
"name": "cat14",
"parent_id": 13,
"path_info": [
8,
10,
12,
13,
14
]
},
{
"id": 15,
"name": "cat15",
"parent_id": 13,
"path_info": [
8,
10,
12,
13,
15
]
}
]
Run Code Online (Sandbox Code Playgroud)
我想将父类的属性也嵌入到列表中作为子类别:
{
"id": 14,
"name": "cat14",
"parent_id": 13,
"subcats": [
{
"id: 8",
"name": "cat8",
"parent_id":null
},
{
"id: 10",
"name": "cat10",
"parent_id":8
},
{ …Run Code Online (Sandbox Code Playgroud) 我想在用户登录/注销时记录用户操作,并添加,编辑,删除我的站点模型中的对象.这是最好的方法吗?另外,我想显示旧数据和使用wtfforms进行的新修改数据.我正在使用flask和Flask-SQLAlchemy.我想要类似于Django框架在关联对象的" 历史 "链接中提供的内容.
我正在使用带有带有属性值的html表单的POST方法和curl命令。我正在使用flask框架。我的内容类型不是application-json。
我在标头中给出的命令如下:
curl -b cookies.txt -F "description=description" -F "file_name=@curl_commands.md" -X POST http://localhost:5000/api/v1.0/upload_doc
-H 'workflow_id:1' -H 'change_workflow:Y'
Run Code Online (Sandbox Code Playgroud)
我应该为Content-type指定什么?这是js ajax调用所必需的。
我希望从我的PC 迁移现有文件和文件夹结构,无论操作系统如Windows/Linux到Plone 4.1.
我已经阅读了有关Mr.migrator,transmogrifier,Enfold桌面,FTP等的文档.但我希望有一个批处理过程,它将遍历文件夹结构并创建与其中的文件相同的内容并上传到Plone 而不进行任何操作干预.文件结构应与最初指定的文件结构相同,作为服务器路径.目标是在上传新文件之前将遗留内容上传到Plone,并进一步定制以满足要求.
这样的产品是否存在,可以直接在buildout.cfg中使用?
buildout.cfg片段的一部分现在使用funnelweb for plone 4.1,在linux debian上
parts =
instance
zopepy
zopeskel
unifiedinstaller
repozo
backup
chown
funnelweb
[funnelweb]
recipe = funnelweb
crawler-site_url=file:///home/xyz/Desktop/MassMail/mm_files
ploneupload-target=http://admin:admin@localhost:8081/VAGroup
Run Code Online (Sandbox Code Playgroud)
需要将url中的文件上载到文件夹中的plone实例中/mysore.如果
url=file:///home/xyz/Desktop/MassMail/mm_files
Run Code Online (Sandbox Code Playgroud)
用来代替网页,来自我本地系统的文件夹MassMail中的文件应该自动上传到指定目标文件夹的VAGroup网站吗?
究竟应该怎么做?文件可以包含需要上传到站点的.doc,.xls,.img,.png,.pdf等.我看到/ var/funnelwebcache /中的所有文件以及带有file.metadata的文件.为什么不上传到网站?我是否必须指定其他内容.此外,我只需要文件夹中的文件:mm_files不是来自父/祖父母,即不是来自home/xyz/Desktop/MassMail我在缓存中看到的子目录.
我希望显示pdf文件的完整路径及其在浏览器上显示的内容.我的脚本有一个输入html,用户将输入文件名并提交表单.该脚本将搜索该文件,如果在子目录中找到该文件,则将文件内容输出到浏览器中并显示其名称.我能够显示内容,但也无法同时显示完整的名字.如果我显示文件名,我会看到内容的垃圾字符显示.请指导.
脚本a.py:
import os
import cgi
import cgitb
cgitb.enable()
import sys
import webbrowser
def check_file_extension(display_file):
input_file = display_file
nm,file_extension = os.path.splitext(display_file)
return file_extension
form = cgi.FieldStorage()
type_of_file =''
file_nm = ''
nm =''
not_found = 3
if form.has_key("file1"):
file_nm = form["file1"].value
type_of_file = check_file_extension(file_nm)
pdf_paths = [ '/home/nancy/Documents/',]
# Change the path while executing on the server , else it will throw error 500
image_paths = [ '/home/nancy/Documents/']
if type_of_file == '.pdf':
search_paths = pdf_paths
else:
# .jpg
search_paths …Run Code Online (Sandbox Code Playgroud) 我在彼此之间有2个for循环.对于loop1中的每一行'A','B','C',我需要访问分层树以找到loop2中组'X'的所有父项.这使我使用CTE,我需要分别找到每一行的路径.在循环中使用CTE不是确定我可以匹配每个组ID的解决方案.提到这个链接,但无法做出很多循环层次CTE
使用flask框架的cron作业的代码片段:
s = select([rt_issues]).\
where(
and_(
rt_issues.c.status !='Closed',
rt_issues.c.assigned_to != None
))
rs = conn.execute(s)
if rs.rowcount > 0:
s4 = text('with recursive rec_grp as(select id, parent_id, name, head, 1 as level, array[id] as path_info from groups union all select grp1.id, grp1.parent_id, grp1.name, grp1.head, rc.level + 1, rc.path_info||grp1.id from groups grp1 join rec_grp rc on grp1.id = rc.parent_id) select distinct id, parent_id, name, head, path_info from rec_grp order by id')
rs4 = conn.execute(s4)
for r in rs:
head_list …Run Code Online (Sandbox Code Playgroud) 如何在处理请求后使用 after_request 装饰器关闭连接?我使用 before_request 为每个 api 请求打开连接,如下所示:使用 sqlalchemy core 1.0.8 和 postgresql 9.5:
#engine = create_engine(os.environ.get("DB_URL"))
DB_URL="postgresql://mowner:passwd@localhost/mydb"
@app.before_request
def before_request():
engine = create_engine(DB_URL, strategy='threadlocal')
conn = engine.connect()
@app.after_request
def after_request(conn):
if conn is not None:
print 'closing connection'
conn.close()
Run Code Online (Sandbox Code Playgroud)
示例api调用:
@app.route('/api/v1.0/categories', methods=['GET'])
def categories_list():
'''
Return categories list
'''
if 'id' in session:
categories_list = []
s = select([categories])
rs = conn.execute(s)
if rs.rowcount > 0:
for r in rs:
categories_list.append(dict(r))
rs.close()
# print 'this doesnt execute'
return jsonify({'categories list': …Run Code Online (Sandbox Code Playgroud) 我有一个名为 products 的 postgresql(v.9.5) 表,使用 sqlalchemy 核心定义为:
products = Table("products", metadata,
Column("id", Integer, primary_key=True),
Column("name", String, nullable=False, unique=True),
Column("description", String),
Column("list_price", Float),
Column("xdata", JSON))
Run Code Online (Sandbox Code Playgroud)
假设表中的日期添加如下:
id | name | description | list_price | xdata
----+------------+---------------------------+------------+--------------------------------
24 | Product323 | description of product332 | 6000 | [{"category": 1, "uom": "kg"}]
Run Code Online (Sandbox Code Playgroud)
使用API编辑代码如下:
def edit_product(product_id):
if 'id' in session:
exist_data = {}
mkeys = []
s = select([products]).where(products.c.id == product_id)
rs = g.conn.execute(s)
if rs.rowcount == 1:
data = request.get_json(force=True)
for r in …Run Code Online (Sandbox Code Playgroud) 在plone中,如果修改了4次,文件(或任何内容)的实际副本数量是多少?我正在使用plone 4.1,其中文件和图像存储在文件系统中.
我想知道我是如何安排生成报告并在特定时间每天作为访问者详细信息日志表的电子邮件发送的.访问者的详细信息,如姓名,进出时间,访问目的需要作为电子邮件发送.在linux上使用django 1.6.5.
我知道cron Django - 设置预定的工作? https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ 但似乎并没有将这些东西放在一起.
我可以使用所有模型管理选项在django admin gui中创建模板和视图.我还可以使用管理面板中的操作生成csv.但我希望每天自动生成报告并以电子邮件形式发送,而无需登录django.我需要完整的代码解决方案,因为我不清楚如何做到这一点.请帮忙
python ×10
flask ×5
postgresql ×3
sqlalchemy ×3
plone ×2
ajax ×1
cgi ×1
content-type ×1
cron ×1
curl ×1
django ×1
email ×1
html ×1
json ×1
zope ×1