dry

ASP.NET MVC - How to achieve reusable user controls and maintain DRY?

我们两清 提交于 2019-12-03 06:38:15
First post so please be gentle :) When creating user controls in ASP.NET MVC, what is the best way to structure the code so that the controllers that invoke views that use the user controls do not all have to know so much about the controls? I would like to know a good way to maintain DRY while using user controls in ASP.NET MVC. Please note, this question only pertain to user controls that require special handling and logic on a postback. I have no problem creating nice DRY code for user controls that are either view only (using RenderPartial) or that require some pre-processing to create the

Django cross-site reverse URLs

為{幸葍}努か 提交于 2019-12-03 06:02:49
问题 Probably simple question and I'm just missing something, but I'm stuck out of ideas. I have Django project serving several sites with distinct sessions.py and completely different ROOT_URLCONF s. One site handles user registration, authentication and profile settings, other site (on another domain) acts as file manager and so on. Sites are sharing the same DB, media and templates. All sites are sharing the same userbase, implementing sort of transparent single-sign-on/single-sign-off

Django - use reverse url mapping in settings

痞子三分冷 提交于 2019-12-03 04:32:52
问题 A few of the options in the django settings file are urls, for example LOGIN_URL and LOGIN_REDIRECT_URL . Is it possible to avoid hardcoding these urls, and instead use reverse url mapping? At the moment this is really the only place where I find myself writing the same urls in multiple places. 回答1: Django 1.5 and later As of Django 1.5, LOGIN_URL and LOGIN_REDIRECT_URL accept named URL patterns. That means you don't need to hardcode any urls in your settings. LOGIN_URL = 'login' # name of

DDD Invariants Business Rules and Validation

﹥>﹥吖頭↗ 提交于 2019-12-03 03:49:28
问题 I am looking for advice on where to add validation rules for domain entities, and best practices for implementation. I did search and did not find what i was looking for, or i missed it. I would like to know what the recommended way is for validating that properties are not null, in a certain range, or length, etc... I have seen several ways using an IsValid() and other discussions about enforcing in the constructor so the entity is never in an invalid state, or using preprocessing and

How can I avoid repeating myself when creating a C++ enum and a dependent data structure? [duplicate]

倖福魔咒の 提交于 2019-12-03 02:55:48
Possible Duplicate: Enum to string : return the enum integer value if invalid / not found In brief, the (working) definition code that I have is something like this: enum Gadget { First, Second, }; const char* gadget_debug_names[] = { "First", "Second", // note: strings are same as enum tokens here, but bonus points if // they can optionally be given different values }; However, it's error prone that the information is in multiple separate places that have to be maintained manually. (And in some cases in the code base I'm working with those two--or more--places aren't even currently in the

What's the least redundant way to make a site with JavaScript-generated HTML crawlable?

眉间皱痕 提交于 2019-12-03 02:55:26
问题 After reading Google's policy on making Ajax-generated content crawlable, along with many developers' blog posts and Stackoverflow Q&A threads on the subject, I'm left with the conclusion that there is no way to make a site with only JavaScript/Ajax-generated HTML crawlable. A site I'm currently working isn't getting a fair amount of its content indexed. All of the presentation layer for our non-indexed content is built in JavaScript by generating HTML from JSON returned from Ajax-based web

DRY URLs in Django Javascript

自作多情 提交于 2019-12-03 02:13:37
问题 I'm using Django on Appengine. I'm using the django reverse() function everywhere, keeping everything as DRY as possible. However, I'm having trouble applying this to my client-side javascript. There is a JS class that loads some data depending on a passed-in ID. Is there a standard way to not-hardcode the URL that this data should come from? var rq = new Request.HTML({ 'update':this.element, }).get('/template/'+template_id+'/preview'); //The part that bothers me. 回答1: There is another method

How to extend or override BeginForm to include a AntiForgeryToken field

戏子无情 提交于 2019-12-03 00:46:26
I was reading this article ( http://weblogs.asp.net/dixin/archive/2010/05/22/anti-forgery-request-recipes-for-asp-net-mvc-and-ajax.aspx ) about how to prevent CSRF attacks. It seems like the solution is to create a tag inside each form. <%: this.Html.AntiForgeryToken(Constants.AntiForgeryTokenSalt)%> However, I really don't want to copy and paste that code inside of each form. I would like to extend or override the BeginForm to create a BeginSecureForm that automatically adds the AntiForgeryToken. I am not sure how to add content inbetween of the BeginForm and EndForm. Any ideas? You should

DRY user-input validation (clientside, serverside) using JSON-schema

删除回忆录丶 提交于 2019-12-02 23:52:09
As part of a extensive test-case, I'm building an ajax-based CMS-like application which provides CRUD-functionality on various documenttypes, e.g: articles, tags, etc. on the server and client-side I'm considering to use JSON-schema ( http://json-schema.org/ ) as a way to do user input validation in a DRY way (i.e: 1 validation-schema, to be used both on the server and client-side, no duplicate-code and all that) . This seems great, because: JSON-schema is both implemented in JS and Java, so one schema could in theory handle client-side and server-side validation all CUD-operations requests

sed command in dry run

别来无恙 提交于 2019-12-02 20:00:06
I am not able to find out if and how it is possible to make a dry run with sed. So i have this command: find ./ -type f | xargs sed -i 's/string1/string2/g' But before I really substitute in all the files, i want to check what it WOULD substitute. Copying the whole directory structure to check is no option! Thanks for any feedback (negative or positive :) ) Remove the -i and pipe it to less to paginate though the results. Alternatively, you can redirect the whole thing to one large file by removing the -i and appending > dryrun.out I should note that this script of yours will fail miserably