Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

python - Automatic class decoration (or validation) upon derivation -



have base class derive multiple subclasses.
each subclass defines class constants, , wish enforce limitations on them. example:

class base(object):     # define these in sub-class, , make sure (nom % denom == 0)     nominator = none     denominator = none  class subclass_good(base):     nominator = 6     denominator = 3  class subclass_bad(base):     nominator = 7     denominator = 5 

i want able enforce rule (nom % denom == 0).
class decorator:

def nom_denom_validator(cls):     assert(cls.nominator % cls.denominator == 0)     return cls  # , decorate each subclass, e.g.: @nom_denom_validator class subclass_another(base):     nominator = 9     denominator = 12 

but don't fact need decorate each subclass (i have plenty). i'm interested whether can done manipulation on base class directly.

any advice?

ok, funny. thinking while, after posting question - when choosing tags, , adding "metaclass" there - did realize may have answer myself.
so, submitted review , future knowledge, here goes:

class base_metaclass(type):     def __new__(meta, classname, bases, class_dict):         new_type = type.__new__(meta, classname, bases, class_dict)         if not (new_type.nominator % new_type.denominator) == 0:             raise exception("invalid subclass created - validation failed")         return new_type  # have base , descendants enforced: class base(object):     __metaclass__ = base_metaclass     # must pass validation myself, no none's anymore...     nominator = 1     denominator = 1 

and children should auto-enforced.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -