我是django的新手.
我想创建一个自定义小部件.
forms.py:
from project.widgets import MultiChoiceFilterWidget
class CustomSearchForm(FacetedSearchForm):
TEST_COLORS = [
u"Blau", u"Rot", u"Gelb"
]
color = forms.MultipleChoiceField(
label=_("Color"), choices=[(x, x) for x in TEST_COLORS],
widget=MultiChoiceFilterWidget, required=False)
Run Code Online (Sandbox Code Playgroud)
widget.py:
class MultiChoiceFilterWidget(forms.widgets.CheckboxSelectMultiple):
template_name = 'project/widgets/filter.html'
option_template_name = 'ptoject/widgets/filter_option.html'
Run Code Online (Sandbox Code Playgroud)
项目/部件/ filter.html:
<h1>TEST</h1>
Run Code Online (Sandbox Code Playgroud)
但它不会渲染新模板,相反它仍然呈现旧方式.
你能给我一些提示吗?
我创建了一个UI5主 - 详细信息页面:
<List items="{som>/Users}">
<StandardListItem
type="Navigation"
press="onItemPress"
title="{som>UserName}"
/>
</List>
Run Code Online (Sandbox Code Playgroud)
onItemPress: function(oEvent) {
var oUserContext = oEvent.getSource().getBindingContext("som");
var oUser = oUserContext.getObject();
this.getRouter().navTo("userDetails", {userId: oUser.Id});
}
Run Code Online (Sandbox Code Playgroud)
onInit: function () {
var route = this.getRouter().getRoute("userDetails");
route.attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var sUserId = oEvent.getParameter("arguments").userId;
this.getView().bindElement({
path: "som>/Users('"+sUserId+"')",
model: "som"
});
},
reload: function() {
this.getView().getModel("som").refresh();
},
Run Code Online (Sandbox Code Playgroud)
<fLayout:SimpleForm id="userForm">
<Button text="reload" press="reload"/>
<Label text="{i18n>settings.user.id}"/>
<Input editable="false" value="{som>Id}"/>
<Label text="{i18n>settings.user.username}"/>
<Input value="{som>UserName}"/>
<Label text="{i18n>settings.user.email}"/>
<Input value="{som>Email}"/>
<Label text="{i18n>settings.user.firstname}"/>
<Input …
Run Code Online (Sandbox Code Playgroud) 我尝试将Entity-Framework实现到我的项目中!我的项目是基于插件的,所以我不知道我必须保存到数据库的哪个对象.
我已经实现了它:
public class DatabaseContext : DbContext
{
public DatabaseContext() : base()
{
Database.Initialize(true);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
foreach( PluginDto plugin in BackendContext.Current.PluginManager._plugins) {
foreach(Type obj in plugin.plugin.getPluginDatabaseObjects())
{
Type typ = typeof(EntityTypeConfiguration<>).MakeGenericType(obj);
List<MethodInfo> l = modelBuilder.GetType().GetMethods().ToList<MethodInfo>();
MethodInfo m_Entitiy = modelBuilder.GetType().GetMethod("Entity").MakeGenericMethod(new Type[] { obj });
var configObj = m_Entitiy.Invoke(modelBuilder, null);
MethodInfo m_ToTable = configObj.GetType().GetMethod("ToTable", new Type[] { typeof(String) });
m_ToTable.Invoke(configObj, new object [] { obj.Name });
}
}
base.OnModelCreating(modelBuilder);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我做出改变时,我得到了这个例外:
自创建数据库以来,支持"DatabaseContext"上下文的模型已更改.请考虑使用"代码优先迁移"来更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269).
此错误完全符合逻辑.数据库不同步,但我将如何获得更新?我读过这个:
var …
Run Code Online (Sandbox Code Playgroud) 我实现了我的自定义 AuthorizationHandler。对此,我检查用户可以解决并处于活动状态。
如果用户不活跃,那么我想返回 403 状态。
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, ValidUserRequirement requirement)
{
var userId = context.User.FindFirstValue( ClaimTypes.NameIdentifier );
if (userId != null)
{
var user = await _userManager.GetUserAsync(userId);
if (user != null)
{
_httpContextAccessor.HttpContext.AddCurrentUser(user);
if (user.Active)
{
context.Succeed(requirement);
return;
}
else
{
_log.LogWarning(string.Format("User ´{1}´ with id: ´{0} isn't active", userId, user.UserName), null);
}
}
else
{
_log.LogWarning(string.Format("Can't find user with id: ´{0}´", userId), null);
}
} else
{
_log.LogWarning(string.Format("Can't get user id from token"), null);
}
context.Fail();
var …
Run Code Online (Sandbox Code Playgroud) 我尝试在我的应用程序上进行Facebook登录!而且效果很好。
但是我想获得一个用户或应用程序唯一的字符串或数字。这样我就可以在自己的服务器上对其进行授权...
我的实际方法是:
但是,对于最后一步,我希望获得一个唯一的值,比如数字或字符串。每次用户登录时UserAccesToken都会更改...
谢谢你的想法
您好,我想从中间件类中的控制器方法检查注释。
我的配置:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, BackendDbContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseStaticFiles();
app.UseMiddleware<AuthMiddleware>();
app.UseMvc();
BackendDbInitializer.Init(context);
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
Route("api/[controller]")]
public class UserController : Controller
{
private readonly BackendDbContext _context;
public UserController(BackendDbContext context)
{
_context = context;
}
// GET api/values
[HttpGet]
[NoAuth]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
Run Code Online (Sandbox Code Playgroud)
我的中间件:
public class AuthMiddleware
{
private readonly RequestDelegate _next;
public AuthMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context) …
Run Code Online (Sandbox Code Playgroud) 您好,我尝试从由 or 组合的列表中生成单个 Func。
var funcs = new List<Func<User, bool>>()
{
(u) => u.Id.Equals(entityToFind.Id),
(u) => u.UserName == entityToFind.UserName,
(u) => u.Email == entityToFind.Email
};
//TODO: Some magic that funs is euqaly to that:
Func<User, bool> func = (u) => u.Id.Equals(entityToFind.Id) || u.UserName == entityToFind.UserName || u.Email == entityToFind.Email;
Run Code Online (Sandbox Code Playgroud)
我也用表达式尝试过,就像这样:
private Dictionary<string, Expression<Func<User, bool>>> private Dictionary<string, Expression<Func<User, bool>>> test(User entityToFind)
{
return new Dictionary<string, Expression<Func<User, bool>>>() {
{"Id", (u) => u.Id.Equals(entityToFind.Id) },
{"Name", (u) => u.UserName == entityToFind.UserName },
{"Email", …
Run Code Online (Sandbox Code Playgroud) 我可以快速创建协议实例吗?
像Java中的接口实例一样?
Java:
public interface test {
void test();
}
new test() {
@Override
public void test() {
//...
}
}
Run Code Online (Sandbox Code Playgroud)
迅速:
protocol ITransmitter {
func onExecuteSuccess(data:String)
}
//instance???
Run Code Online (Sandbox Code Playgroud) 我尝试创建类似的东西:
<Label Text="{Binding oResult.hi, StringFormat='Hallo: {0}'}" />
Run Code Online (Sandbox Code Playgroud)
它工作正常!但我希望String"Hallo"应该从resx文件中获取.
像这样:
<Entry Placeholder="{i18n:TranslateExtension Text=password}" IsPassword="true" />
Run Code Online (Sandbox Code Playgroud)
我也将两者结合起来.
谢谢!
好像我没理解flexbox吧.
但我认为flexboxitem中div的含义被忽略了.
喜欢这个小提琴:https://jsfiddle.net/34f9awsk/6/
CSS:
.wrapper {
width: 200px;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
flex-direction: row;
}
.ele {
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
flex-direction: row;
flex: 3;
}
.ele1 {
flex: 1;
}
.ele input {
display: inline;
max-width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="wrapper">
<div class="ele ele3" style="background-color: red;">
<input type="number" size="4" value="9999" />
</div>
<div class="ele ele1" style="background-color: green;">
2
</div>
<div …
Run Code Online (Sandbox Code Playgroud) asp.net-core ×3
.net-core ×2
android ×1
api ×1
binding ×1
c# ×1
css ×1
css3 ×1
django ×1
dynamic ×1
facebook ×1
flexbox ×1
func ×1
generics ×1
html ×1
input ×1
interface ×1
ios ×1
ipad ×1
jwt ×1
linq ×1
login ×1
middleware ×1
odata ×1
plugins ×1
protocols ×1
python ×1
sapui5 ×1
security ×1
swift ×1
translation ×1
widget ×1
xamarin ×1