dry

How to avoid repetitions / use constants in Facelets page?

一个人想着一个人 提交于 2019-12-02 18:52:05
问题 In a Facelets page, I have various <h:inputText> and <h:outputText> components, which all need the same converter. I'd like to avoid repeating the converter with all its parameters, like this: <h:inputText id="bla" value="#{mybean.val}" > <f:convertNumber locale="en" maxFractionDigits="3" minFractionDigits="3"/> </h:inputText> [...] <h:outputText id="bla2" value="#{mybean.val2}" > <f:convertNumber locale="en" maxFractionDigits="3" minFractionDigits="3"/> </h:outputText> [...] <h:inputText id=

Django cross-site reverse URLs

纵然是瞬间 提交于 2019-12-02 18:35:25
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 mechanism. It is just like one big site, spanning across several domains. The problem is, I have a lot of {%

Django - use reverse url mapping in settings

扶醉桌前 提交于 2019-12-02 17:54:14
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. 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 url pattern For Django 1.5 - 1.9, you can also use the view function name, but this is not recommended because

DDD Invariants Business Rules and Validation

泄露秘密 提交于 2019-12-02 17:15:26
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 postprocessing, and others using FluentValidation api, how invariants impact DRY and SRP. Can someone give me

Dynamically pass app_label and model_name to the url in Python Django

Deadly 提交于 2019-12-02 16:52:02
问题 I'm curious, why aren't more people talking about code consolidation by dynamically passing app_label and model_name as arguments to the URL. In building generic CRUD actions for 'non-staff' users I've been searching for the most 'DRY' method. I started out trying to extend the Django Admin for 'non-staff' users. Later I came across Django-Generic-Scaffold, which is awesome, but scaffolds models up front rather than dynamically on-demand. After digging through the Django Admin source code I

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

送分小仙女□ 提交于 2019-12-02 16:45:41
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 service calls, and we believe Google is not indexing the content because of that. Is that correct? The

DRY URLs in Django Javascript

情到浓时终转凉″ 提交于 2019-12-02 15:43:54
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. There is another method, which doesn't require exposing the entire url structure or ajax requests for resolving each url. While it

Dynamically pass app_label and model_name to the url in Python Django

橙三吉。 提交于 2019-12-02 09:03:14
I'm curious, why aren't more people talking about code consolidation by dynamically passing app_label and model_name as arguments to the URL. In building generic CRUD actions for 'non-staff' users I've been searching for the most 'DRY' method. I started out trying to extend the Django Admin for 'non-staff' users. Later I came across Django-Generic-Scaffold, which is awesome, but scaffolds models up front rather than dynamically on-demand. After digging through the Django Admin source code I discovered this technique and have it working well but I wonder why is this technique isn't discussed

How to avoid repetitions / use constants in Facelets page?

不羁的心 提交于 2019-12-02 08:59:25
In a Facelets page, I have various <h:inputText> and <h:outputText> components, which all need the same converter. I'd like to avoid repeating the converter with all its parameters, like this: <h:inputText id="bla" value="#{mybean.val}" > <f:convertNumber locale="en" maxFractionDigits="3" minFractionDigits="3"/> </h:inputText> [...] <h:outputText id="bla2" value="#{mybean.val2}" > <f:convertNumber locale="en" maxFractionDigits="3" minFractionDigits="3"/> </h:outputText> [...] <h:inputText id="bla3" value="#{mybean.val3}" > <f:convertNumber locale="en" maxFractionDigits="3" minFractionDigits="3

DRYing up Rock Paper Scissors

左心房为你撑大大i 提交于 2019-12-02 04:16:34
I'm a novice ruby programmer and although this code works, I'm wondering how I can improve it. I have very limited knowledge on lambdas and procs and the like, but any advice would be great. Is there any way to simplify the if else statements in each case? Also, is there any alternative way to the case statement skipped instead of making almost the entirety of the code one big if else statement? def rps(roll) roll_ops = ["rock", "paper", "scissors"] pick = roll_ops.sample result = nil if roll == pick result = "tie" else case roll when "scissors" then if pick == "paper" result = "win" else