我创建了一个 Click 命令,它将文件从源复制到目标
该命令接受 3 个参数:
1 - 文件来源
2 - 文件的目的地
3 - 传输模式(本地,ftp)
import click
@click.group()
def cli():
pass
@cli.command()
@click.argument('source')
@click.argument('destination')
@click.option('--mode', required = True)
def copy(source, destination, mode):
print("copying files from " + source + " to " + destination + "using " + mode + " mode")
if __name__ == '__main__':
cli()
Run Code Online (Sandbox Code Playgroud)
当我使用这个调用脚本时: command.py copy "C:/" "D:/" --mode=network
我得到以下输出: copying files from C:/ to D:/using network mode
如您所见,我将网络指定为模式,但我只需要两个选项:本地或 ftp
那么如何使用 Click 来设置选项的允许值呢?
我创建了一个简单的android活动,用作拨号。它具有电话号码的编辑文本和呼叫按钮,这是代码:(android 6.0 marshmallow)
public class Main2Activity extends AppCompatActivity {
EditText num;
Button call;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
num = (EditText) findViewById(R.id.num);
call = (Button) findViewById(R.id.call);
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
// request permission if not granted
if (ActivityCompat.checkSelfPermission(Main2Activity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(Main2Activity.this, new String[]{Manifest.permission.CALL_PHONE}, 123);
// i suppose that the user has granted the permission
Intent in = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + num.getText().toString()));
startActivity(in);
// if the permission is …Run Code Online (Sandbox Code Playgroud) 我创建了一个登录中间件,如果用户未经过身份验证,它将重定向到登录页面。
using FileManager.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FileManager.Middleware
{
public class LoginRequiredMiddleware
{
private readonly RequestDelegate _next;
public LoginRequiredMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
Console.WriteLine("Middleware");
User user = Models.User.getCurrentUser(httpContext);
if(user == null)
{
Console.WriteLine("Redirecting");
httpContext.Response.Redirect("/login/");
}
await _next.Invoke(httpContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将其添加到Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSession();
app.UseMiddleware<LoginRequiredMiddleware>();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 Flask 和 Materialize 显示 PDF 文件列表
<table class="highlight responsive-table">
<thead>
<th class="left-align"><i class="material-icons">call</i></th>
<th class="left-align"><i class="material-icons">email</i></th>
<th class="center-align"><i class="material-icons">picture_as_pdf</i></th>
</thead>
<tbody>
{% for doc in docs %}
<tr>
<td>{{doc.phone if doc.phone}}</td>
<td>{{doc.email if doc.email}}</td>
<td>
<a href="#modal{{loop.index}}" class="modal-trigger"><i class="material-icons">open</i> Ouvrir</a>
</td>
</tr>
<div class="modal" id="modal{{loop.index}}">
<iframe src="/cv/{{doc.name}}" scrolling="no" width="100%" height="100%"></iframe>
</div>
{% endfor %}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
PDF 使用 iframe 显示在模式窗口中。
当我在移动设备中打开页面时,它会提示我下载 pdf,而不是在模态中显示 PDF,就像我试图直接下载它一样。当我for在 Flask 中使用循环时,我会收到每个 PDF 的下载提示。我想知道是否有办法检查用户代理是否是移动的,如果是这种情况,那么我将显示指向 pdf 的链接而不是模式窗口。
我想禁用特定模型实例的删除
我重写delete_model如下ModelAdmin:
def delete_model(self, request, client):
if client.schema_name == 'public':
messages.set_level(request, messages.ERROR)
messages.error(request, 'Suppression interdite pour la racine')
else:
super().delete_model(request, client)
Run Code Online (Sandbox Code Playgroud)
当我单击更改视图上的删除按钮时它起作用
但不能使用批量删除,因为实例被删除而不会阻止
我怎样才能解决这个问题 ?我还意识到这delete_model不是通过批量删除来调用的,这有点奇怪。
python ×2
android ×1
asp.net ×1
asp.net-core ×1
c# ×1
css ×1
django ×1
django-admin ×1
flask ×1
grant ×1
iframe ×1
javascript ×1
mobile ×1
option ×1
permissions ×1
python-click ×1
runtime ×1