Skip to content

Commit

Permalink
Model.get_safe_attributes_names and Model.get_attributes_description …
Browse files Browse the repository at this point in the history
…is removed
  • Loading branch information
jifeon committed Apr 30, 2012
1 parent c649977 commit fbd9996
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 60 deletions.
12 changes: 3 additions & 9 deletions demos/blog/models/comment.js
Expand Up @@ -12,17 +12,11 @@ Comment.prototype.get_table_name = function () {
};


Comment.prototype.get_safe_attributes_names = function () {
return [ 'text' ];
};


Comment.prototype.attributes = function(){
return {
'user_id' : [ 'required' ],
'post_id' : [ 'required' ],
'text' : [
'required',
'user_id post_id' : 'required',
'text' : [
'safe required',
{ max_length : 1024 }
]
};
Expand Down
13 changes: 3 additions & 10 deletions demos/blog/models/post.js
Expand Up @@ -22,22 +22,15 @@ Post.prototype.relations = function () {
};


Post.prototype.get_safe_attributes_names = function () {
return ['name', 'description'];
};


Post.prototype.attributes = function(){
return {
user_id : [
'required'
],
user_id : 'required',
name : [
'required',
'safe required',
{ "max_length" : 256 }
],
description : [
'required',
'safe required',
{ "max_length" : 4096 }
]
};
Expand Down
9 changes: 2 additions & 7 deletions demos/blog/models/user.js
Expand Up @@ -11,17 +11,12 @@ User.prototype.get_table_name = function(){
}


User.prototype.get_safe_attributes_names = function () {
return ['login', 'pass'];
};


User.prototype.attributes = function(){
return {
login : [
'required',
'safe required',
{ range_length : [4, 30] }
],
pass : 'required md5'
pass : 'safe required md5'
};
}
27 changes: 5 additions & 22 deletions framework/base/model.js
Expand Up @@ -82,6 +82,11 @@ Model.prototype.create_attribute = function( attr, description ){
};


Model.prototype.remove_attribute = function(){

};


Model.prototype.set_attribute = function ( name, value, do_filters ) {
var descriptor = this._[name];
descriptor.value = do_filters !== false
Expand Down Expand Up @@ -215,28 +220,6 @@ Model.prototype.remove = function ( callback ) {
};


Model.prototype.get_safe_attributes_names = function () {
if ( !this._safe_attributes ) this._process_attributes();

this.get_safe_attributes_names = function(){
return this._safe_attributes;
}

return this.get_safe_attributes_names();
};


Model.prototype.get_attributes_description = function(){
if ( !this._attr_description ) this._process_attributes();

this.get_attributes_description = function(){
return this._attr_description;
}

return this.get_attributes_description();
};


Model.prototype.equals = function ( model ) {
if ( this.constructor != model.constructor ) return false;

Expand Down
8 changes: 5 additions & 3 deletions tests/applications/ar_app/models/post.js
Expand Up @@ -10,9 +10,11 @@ Post.prototype.get_table_name = function(){
}


Post.prototype.get_safe_attributes_names = function(){
return [ 'title' ];
}
Post.prototype.attributes = function(){
return {
title : 'safe'
}
};


Post.prototype.relations = function(){
Expand Down
8 changes: 5 additions & 3 deletions tests/applications/ar_app/models/post_ext.js
Expand Up @@ -20,9 +20,11 @@ PostExt.prototype.get_table_name = function(){
}


PostExt.prototype.get_safe_attributes_names = function(){
return [ 'title' ];
}
PostExt.prototype.attributes = function(){
return {
title : 'safe'
}
};


PostExt.prototype.relations = function () {
Expand Down
10 changes: 6 additions & 4 deletions tests/applications/normal_app/models/test_model.js
@@ -1,16 +1,18 @@
module.exports = TestModel.inherits( autodafe.Model );

TestModel.prototype.get_safe_attributes_names = function(){
return [ 'param1', 'param2' ];
}

function TestModel( params ) {
this._init( params );

this.param = params.param || 42;
this.param1 = 33;
}

TestModel.prototype.attributes = function(){
return {
'param1 param2' : 'safe'
}
}

TestModel.prototype.test = function () {
return this.param;
};
Expand Down
6 changes: 4 additions & 2 deletions tests/applications/old_test_app/models/ui_test.js
Expand Up @@ -11,8 +11,10 @@ function UITest( params ) {
});
}

UITest.prototype.get_safe_attributes_names = function(){
return [ 'p1', 'p2' ];
UITest.prototype.attributes = function(){
return {
'p1 p2' : 'safe'
};
}

UITest.user_rights = {
Expand Down

0 comments on commit fbd9996

Please sign in to comment.