Changeset 111
- Timestamp:
- 04/27/08 00:54:28 (7 months ago)
- Files:
-
- trunk/sql/postgres.sql (modified) (4 diffs)
- trunk/sql/r70migration.sql (modified) (1 diff)
- trunk/tracforums/db.py (modified) (1 diff)
- trunk/tracforums/htdocs/css/forums.css (modified) (1 diff)
- trunk/tracforums/init.py (modified) (1 diff)
- trunk/tracforums/model.py (modified) (1 diff)
- trunk/tracforums/models/avatar.py (modified) (1 diff)
- trunk/tracforums/models/category.py (modified) (2 diffs)
- trunk/tracforums/models/forum.py (modified) (2 diffs)
- trunk/tracforums/models/message.py (modified) (2 diffs)
- trunk/tracforums/models/moderator.py (modified) (1 diff)
- trunk/tracforums/models/profile.py (modified) (1 diff)
- trunk/tracforums/models/project.py (modified) (1 diff)
- trunk/tracforums/models/topic.py (modified) (2 diffs)
- trunk/tracforums/models/watch.py (modified) (3 diffs)
- trunk/tracforums/orm.py (modified) (5 diffs)
- trunk/tracforums/templates/tracforums/profile/watches.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/sql/postgres.sql
r110 r111 3 3 id serial NOT NULL, 4 4 name text, 5 username varchar(32),5 username text NOT NULL, 6 6 mimetype varchar(256), 7 7 CONSTRAINT forum_pkey PRIMARY KEY (id), … … 59 59 ( 60 60 forumid int4 NOT NULL, 61 username varchar(25)NOT NULL61 username text NOT NULL 62 62 ); 63 63 … … 65 65 ( 66 66 sig text, 67 username varchar(25)NOT NULL,67 username text NOT NULL, 68 68 email varchar(255), 69 69 regdate int4 NOT NULL DEFAULT 0, … … 116 116 ( 117 117 id serial NOT NULL, 118 username varchar(32),118 username text, 119 119 topicid int4, 120 120 CONSTRAINT touched_topic_pkey PRIMARY KEY (id) trunk/sql/r70migration.sql
r110 r111 6 6 7 7 ALTER TABLE project RENAME hidden TO active; 8 9 CREATE TABLE forum_category10 (11 id serial NOT NULL,12 projectid varchar(32),13 description text,14 rank serial NOT NULL,15 CONSTRAINT forum_category_pkey PRIMARY KEY (id)16 );17 18 CREATE TABLE forum_watch19 (20 id serial NOT NULL,21 forumid int4,22 username text,23 CONSTRAINT forum_watch_pkey PRIMARY KEY (id)24 );25 26 CREATE TABLE project_watch27 (28 id serial NOT NULL,29 username text,30 projectid varchar(32),31 CONSTRAINT project_watch_pkey PRIMARY KEY (id)32 );33 34 CREATE TABLE topic_watch35 (36 id serial NOT NULL,37 topicid int4,38 username text,39 CONSTRAINT topic_watch_pkey PRIMARY KEY (id)40 );41 42 CREATE TABLE touched_topic43 (44 id serial NOT NULL,45 username varchar(32),46 topicid int4,47 CONSTRAINT touched_topic_pkey PRIMARY KEY (id)48 );trunk/tracforums/db.py
r88 r111 34 34 version = 1 35 35 36 #TODO: write upgrader/installer 37 def upgradeSchema(): 38 pass 36 def upgradeSchema(db): 37 from tracforums.models import * 38 39 AvatarModel.createTable(db) 40 CategoryModel.createTable(db) 41 ForumModel.createTable(db) 42 MessageModel.createTable(db) 43 ModeratorModel.createTable(db) 44 ProfileModel.createTable(db) 45 ProjectModel.createTable(db) 46 TopicModel.createTable(db) 47 TouchedTopicModel.createTable(db) 48 ForumWatchModel.createTable(db) 49 TopicWatchModel.createTable(db) 50 ProjectWatchModel.createTable(db) trunk/tracforums/htdocs/css/forums.css
r107 r111 178 178 .signature{ 179 179 border-top: 1px solid #D7D7D7; 180 font-size: smaller; 180 181 } 181 182 trunk/tracforums/init.py
r85 r111 31 31 try: 32 32 # assume nothing! 33 upgradeSchema( )33 upgradeSchema(db) 34 34 35 35 # Creation is done. Set the version. trunk/tracforums/model.py
r107 r111 8 8 from trac.wiki import wiki_to_html, wiki_to_oneliner 9 9 from trac.util.datefmt import format_datetime, format_date, pretty_timedelta 10 11 #todo: check out "The IT Crowd" on bittorrent12 10 13 11 class Struct: trunk/tracforums/models/avatar.py
r105 r111 15 15 columns = { 16 16 "id": ORMKey(type='int', auto_increment = True), 17 "username": ORMColumn(type=" str"),18 "mimetype": ORMColumn(type=" str"),19 "name": ORMColumn(type=" str"),17 "username": ORMColumn(type="text"), 18 "mimetype": ORMColumn(type="varchar",size=256), 19 "name": ORMColumn(type="text"), 20 20 "avatarid": ORMAlias(type="int",sql="id"), 21 21 } trunk/tracforums/models/category.py
r105 r111 12 12 columns = { 13 13 "id": ORMKey(type="int", auto_increment = True), 14 "projectid": ORMColumn( force_insert = True),15 "description": ORMColumn(type=" str"),14 "projectid": ORMColumn(type="varchar",size=32,force_insert = True), 15 "description": ORMColumn(type="text"), 16 16 "rank": ORMColumn(type='int', auto_increment = True), 17 17 … … 53 53 "forums": ORMRelation( 54 54 model = ORMImportModel("tracforums.models.forum","ForumModelWithRecentPost"), 55 relationship = {"categoryid":"categoryid"}, 56 debug = True 55 relationship = {"categoryid":"categoryid"} 57 56 ), 58 57 } trunk/tracforums/models/forum.py
r109 r111 16 16 # normal columns 17 17 "id": ORMKey(type="int", auto_increment = True, unique = True), 18 "projectid": ORMColumn(type=" str", required = True),19 "name": ORMColumn(type=" str", unique = True, required = True),18 "projectid": ORMColumn(type="varchar", size=32, required = True), 19 "name": ORMColumn(type="text", unique = True, required = True), 20 20 "created": ORMColumn(type="int"), 21 21 "modified": ORMColumn(type="int"), 22 "description": ORMColumn(type=" str"),22 "description": ORMColumn(type="text"), 23 23 "locked": ORMColumn(type="bool"), 24 24 "hidden": ORMColumn(type="bool"), … … 85 85 86 86 "touched": ORMAlias(type="bool",sql=""" 87 coalesce((select true from %(touchedtopic)s as tt87 coalesce((select distinct true from %(touchedtopic)s as tt 88 88 join %(topic)s as t on tt.topicid = t.id 89 89 where t.forumid = %(forum)s.id trunk/tracforums/models/message.py
r105 r111 18 18 "created": ORMColumn(type="int"), 19 19 "modified": ORMColumn(type="int"), 20 "body": ORMColumn(type=" str"),21 "author": ORMColumn(type=" str"),20 "body": ORMColumn(type="text"), 21 "author": ORMColumn(type="text"), 22 22 "avatarid": ORMColumn(type="int"), 23 "modifiedby": ORMColumn(type=" str"),23 "modifiedby": ORMColumn(type="text"), 24 24 "modcount": ORMColumn(type="int"), 25 25 … … 56 56 %%(isuser)s 57 57 and coalesce(( 58 select true from %(moderator)s m58 select distinct true from %(moderator)s m 59 59 join %(forum)s f on m.forumid = f.id 60 60 join %(topic)s t on f.id = t.forumid trunk/tracforums/models/moderator.py
r97 r111 11 11 orderby = [("username","asc")], 12 12 columns = { 13 "forumid": ORMColumn(type=' str', force_insert=True),14 "username": ORMColumn(type=' str', force_insert=True)13 "forumid": ORMColumn(type='int', force_insert=True), 14 "username": ORMColumn(type='text', force_insert=True) 15 15 } 16 16 ) trunk/tracforums/models/profile.py
r110 r111 11 11 tablename = Tablenames.profile, 12 12 columns = { 13 "sig": ORMColumn(),14 "username": ORMColumn(),15 "email": ORMColumn(),16 "regdate": ORMColumn(type="int"),17 "lastvisit": ORMColumn(type="int"),13 "sig": ORMColumn(type="text"), 14 "username": ORMColumn(type="text"), 15 "email": ORMColumn(type="text"), 16 "regdate": ORMColumn(type="int"), 17 "lastvisit": ORMColumn(type="int"), 18 18 "defaultavatarid": ORMColumn(type="int"), 19 "bio": ORMColumn(),20 "logindate": ORMColumn(type="int"),21 "timezone": ORMColumn(),22 "viewemail": ORMColumn(type="bool"),23 "isactive": ORMColumn(type="bool"),24 "isexpert": ORMColumn(type="bool"),25 "posts": ORMColumn(type="int"),19 "bio": ORMColumn(type="text"), 20 "logindate": ORMColumn(type="int"), 21 "timezone": ORMColumn(type="varchar",size=8), 22 "viewemail": ORMColumn(type="bool"), 23 "isactive": ORMColumn(type="bool"), 24 "isexpert": ORMColumn(type="bool"), 25 "posts": ORMColumn(type="int"), 26 26 27 27 "profileid": ORMAlias( trunk/tracforums/models/project.py
r85 r111 8 8 tablename=Tablenames.project, 9 9 columns={ 10 "id": ORMKey(type=' str'),11 "name": ORMColumn(type=' str'),10 "id": ORMKey(type='varchar',size='32'), 11 "name": ORMColumn(type='text'), 12 12 "active": ORMColumn(type='bool'), 13 13 "projectid": ORMAlias(sql="id") trunk/tracforums/models/topic.py
r109 r111 11 11 columns = { 12 12 "id": ORMKey(type="int", auto_increment = True), 13 "username": ORMColumn(type=" str", force_update = True, force_insert = True),13 "username": ORMColumn(type="text", force_update = True, force_insert = True), 14 14 "topicid": ORMColumn(type="int", force_update = True, force_insert = True), 15 15 } … … 22 22 "id": ORMKey(type="int", auto_increment = True), 23 23 "forumid": ORMColumn(type="int", required = True), 24 "subject": ORMColumn(type=" str"),24 "subject": ORMColumn(type="text"), 25 25 "leadmessageid": ORMColumn(type="int"), 26 26 "views": ORMColumn(type="int"), 27 "type": ORMColumn(type=" str"),27 "type": ORMColumn(type="text"), 28 28 "topicid": ORMAlias(type="int",sql="%(topic)s.id" % Tablenames), 29 29 trunk/tracforums/models/watch.py
r95 r111 16 16 "id": ORMKey(type='int', auto_increment = True), 17 17 "forumid": ORMColumn(type='int'), 18 "username": ORMColumn( ),18 "username": ORMColumn(type="text"), 19 19 "watchusername": ORMAlias(sql='username') 20 20 })): … … 50 50 "id": ORMKey(type='int', auto_increment = True), 51 51 "topicid": ORMColumn(type='int'), 52 "username": ORMColumn( ),52 "username": ORMColumn(type="text"), 53 53 "watchusername": ORMAlias(sql='username'), 54 54 … … 89 89 columns={ 90 90 "id": ORMKey(type='int', auto_increment = True), 91 "projectid": ORMColumn(type=' str'),92 "username": ORMColumn( ),91 "projectid": ORMColumn(type='varchar',size=32), 92 "username": ORMColumn(type="text"), 93 93 "watchusername": ORMAlias(sql='username') 94 94 })): trunk/tracforums/orm.py
r109 r111 203 203 204 204 @staticmethod 205 def getByType(name): 206 if name: 207 return getattr(Format,name,Format.noFormat) 205 def getByType(type): 206 if type: 207 if type == "varchar" or type == "text": 208 return Format.str 209 else: 210 return getattr(Format,type,Format.noFormat) 208 211 return Format.noFormat 209 212 … … 248 251 class ORMColumn: 249 252 def __init__(self, 250 type = None, 253 type = None, 251 254 size = None, 252 255 unique = False, … … 269 272 self.validator = validator 270 273 self.formatter = formatter 271 274 272 275 if type: 273 276 if not validator: 274 277 self.validator = Validate.getByType(type) 275 278 if not formatter: 276 self.formatter = Format.getByType(type) 279 self.formatter = Format.getByType(type) 277 280 278 281 if not validator: … … 642 645 rows = cursor.fetchall() 643 646 for row in rows: 644 return row[0]647 return row[0] 645 648 return 0 646 649 … … 820 823 if reasons and len(reasons) > 0: 821 824 raise ModelValidateException(reasons) 822 823 #TODO: finish me 824 def createTable(self): 825 coldefs = [] 826 for fieldname in self.schema.columns: 827 col = self.schema.columns[fieldname] 828 coldefs.append(col.name + " " + col.type + ",") 829 830 return "create table " + self.schema.tablename + " (" + coldefs.join(",") + ")" 825 826 @staticmethod 827 def createTable(db,debug=False): 828 """ 829 Provides a bridge from the ORM to the trac db scheme for table generation 830 """ 831 from trac.db import Table, Column 832 833 schema = _ORMSchemaData() 834 tracTable = Table(schema.tablename) 835 836 for fieldname in schema.columns: 837 col = schema.columns(fieldname) 838 if isinstance(col,ORMAlias): 839 pass 840 elif isinstance(col,ORMJoin): 841 pass 842 elif isinstance(col,ORMRelation): 843 pass 844 elif isinstance(col,ORMKey): 845 tracTable.columns.append(Column(col.name,col.type,col.size,col.unique,col.auto_increment)) 846 tracTable.keys.append(col.name) 847 elif isinstance(col,ORMColumn): 848 tracTable.columns.append(Column(col.name,col.type,col.size,col.unique,col.auto_increment)) 849 850 db.cursor().execute(db.to_sql(tracTable)) 851 db.commit() 831 852 832 853 return _ORMSchemaModel trunk/tracforums/templates/tracforums/profile/watches.cs
r109 r111 10 10 </div> 11 11 <br> 12 12 13 13 <div class="instructions"> 14 <?cs if:len(forums. forums) == 0?>14 <?cs if:len(forums.projects) != 0 && len(forums.watchedForums) != 0 && len(forums.watchedTopics) != 0?> 15 15 <p>Here you may review and remove your watch entries.</p> 16 16 <?cs /if?> 17 <?cs if:len(forums.projects) == 0 && len(forums.watchedForums) == 0 && len(forums.watchedTopics) == 0?> 18 <p>There are no watches to display.</p> 19 <?cs /if?> 17 20 <?cs if:len(forums.validateErrors) > 0?> 18 21 <?cs each:err = forums.validateErrors?>
