Posts

Override a Django generic class-based view widget -

say have basic createview form, this, allow new users register on site: from django.contrib.auth import get_user_model django.http import httpresponse django.views.generic import createview user = get_user_model() class signup(createview): model = user fields = ['first_name', 'last_name', 'email', 'password'] i tried this, , found password field rendered in plain text; how go overriding view uses forms.passwordinput() instead? (i realise it's easiest define form hand, i'm curious how you'd that.) you override get_form() , , modify form change widget on password field: from django import forms class signup(createview): model = user fields = ['first_name', 'last_name', 'email', 'password'] def get_form(self, form_class): form = super(signup, self).get_form(form_class) form.fields['password'].widget = forms.passwordinput() return form b...

asp.net mvc - request a javascript variable into razor -

i have problem, request function not working here code razor @{ int = 0; list<abono> ab = model.tolist(); int inicio = convert.toint32(request["inic"]); int fin = convert.toint32(request["ffin"]); var xx = ab.skip(inicio).take(fin); } script var inic=0; var ffin=20; function siguiente() { //debugger; var ini = @html.raw(json.encode(@viewbag.inicio)); var fi=@html.raw(json.encode(@viewbag.fin)); $.post("/reportes/getsiguiente", { fin: fi }, function (data) { var dato = data.dias; //alert(dato); debugger; var inic=dato[0]; var ffin=dato[1]; }); } i traying change razors values. thanks remove @viewbag front of variables.

java - Injecting properties into Spring Rest Controller via XML -

right have spring based restful web-app. i'm new rest , followed tutorials online. built web.xml, rest-servlet.xml uses component-scan tag , loads restcontroller class uses @restcontroller annotation. (all of code posted below) my issue none of these tutorials show me how inject beans controller via applicationcontext.xml. i've found ways inject using annotations, want use xml configuration. in example below have 3 database clients want wired in restcontroller when starts up. any suggestions on how load applicationcontext.xml on startup restcontroller servlet receives correct instances of database clients? web.xml <servlet> <servlet-name>rest</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>rest</servlet-name> <url-pattern>/*</url-pattern> </servlet-m...

java - How should a custom Guice scope be integrated with TestNG? -

we use custom guice scope, @testscoped , of our junit tests lasts single test method, , junit @rule enter , exit scope appropriately. looks this: public class myjunittest { @rule public customrule customrule = new customrule(mymodule.class); @inject private thing thing; @test public void test1() { // use "thing" } @test public void test2() { // assuming "thing" @testscoped, we'll have new instance } } we're starting use testng of our tests in other projects, , we'd have similar pattern. far we've come this: @listeners(customtestnglistener.class) @guice(modules = mymodule.class) public class mytestngtest { @inject private provider<thing> thingprovider; @test public void test1() { thing thing = thingprovider.get(); // use "thing" } @test public void test2() { thing thing = thingprovider.get(); // assuming "thing...

php - How to keep logs of your users in Laravel 4? -

i have users table in database lay out : id username firstname lastname email photo as of now, since admin user have admin right , , can create, update, , delete. want allow users have same right me later on. before release feature, want keep track on edit - things doesn't lost, , it's keep history of things. what best practice feature ? know have programming logic in update function in controller function. know have create logs table on database store user_id : make change created_at : when change made old_data: string new_data: string for someone, had experiences feature, can please give me advice ? appreciate concern. thank you. i think best approach problem each action user takes want log should fire event. event::fire('some.event', array(auth::user())); then can register listeners each event , log appropriately. event::listen('some.event', function($user) { // create new item in logs table here. });

node.js - supertest: test the redirection url -

with supertest, can test redirection code 302 var request = require('supertest'); var app = require('../server').app; describe('test route', function(){ it('return 302', function(done){ request(app) .get('/fail_id') .expect(302, done); }); it('redirect /'); }); how can test url objetive redirect ? it('redirect /', function(done){ request(app) .get('/fail_id') .expect('location', /\//, done); });

c# - Linq query from IEnumerable of integers -

i have logical problem within asp.net mvc project. i'm developing social media app looks facebook. got work except 1 thing. the application has table called follow , contains loggedinuser_id , usertofollow_id . have ienumerable of integers contains list of userstofollow_id logged in user, method looks like: public ienumerable<post> postsforflow(int userid, string username) { ienumerable<int> usertofollowid = db.follow.where(a => a.loggedinuser.id == userid).select(b => b.usertofollow.id); return null; } how foreach on integers of posts loggedinuser want follow? can resolve linq query? would work? assuming user has 1 many relationship posts : public ienumerable<post> postsforflow(int userid) { var useridstofollow = db.follow.where(a => a.loggedinuser.id == userid).select(b => b.usertofollow.id); return db.users .where(u => useridstofollow.contains(u.id)) .selectmany(u =...