1
- from sqlalchemy import Boolean , Column , Date , DateTime , Integer , String , Unicode , ForeignKey , UniqueConstraint , Text , UnicodeText
1
+ from sqlalchemy import Column , Date , DateTime , Integer , String , Unicode , ForeignKey , UniqueConstraint , Text , UnicodeText
2
2
from sqlalchemy .orm import relationship , backref
3
3
from flask_login import UserMixin
4
+ from sqlalchemy .sql .expression import desc
4
5
from database import Base
5
6
import datetime as dt
6
- import pytz
7
7
from pytz import timezone
8
8
9
9
central = timezone ('US/Central' )
@@ -29,6 +29,186 @@ def __init__(self, article_id, variable, value, coder_id, text = None):
29
29
def __repr__ (self ):
30
30
return '<CoderArticleAnnotation %r>' % (self .id )
31
31
32
+
33
+ class CanonicalEvent (Base ):
34
+ __tablename__ = 'canonical_event'
35
+ id = Column (Integer , primary_key = True )
36
+ coder_id = Column (Integer , ForeignKey ('user.id' ), nullable = False )
37
+ key = Column (Text , nullable = False )
38
+ description = Column (UnicodeText , nullable = False )
39
+ notes = Column (UnicodeText )
40
+ last_updated = Column (DateTime )
41
+
42
+ UniqueConstraint ('key' , name = 'unique1' )
43
+
44
+ def __init__ (self , coder_id , key , description , notes = None ):
45
+ self .coder_id = coder_id
46
+ self .key = key
47
+ self .description = description ,
48
+ self .notes = notes
49
+ self .last_updated = dt .datetime .now (tz = central ).replace (tzinfo = None )
50
+
51
+ def __repr__ (self ):
52
+ return '<CanonicalEvent %r>' % (self .id )
53
+
54
+
55
+ class CanonicalEventLink (Base ):
56
+ __tablename__ = 'canonical_event_link'
57
+ id = Column (Integer , primary_key = True )
58
+ coder_id = Column (Integer , ForeignKey ('user.id' ), nullable = False )
59
+ canonical_id = Column (Integer , ForeignKey ('canonical_event.id' ), nullable = False )
60
+ cec_id = Column (Integer , ForeignKey ('coder_event_creator.id' ), nullable = False )
61
+ timestamp = Column (DateTime )
62
+
63
+ UniqueConstraint ('canonical_id' , 'cec_id' , name = 'unique1' )
64
+
65
+ def __init__ (self , coder_id , canonical_id , cec_id ):
66
+ self .coder_id = coder_id
67
+ self .canonical_id = canonical_id
68
+ self .cec_id = cec_id
69
+ self .timestamp = dt .datetime .now (tz = central ).replace (tzinfo = None )
70
+
71
+ def __repr__ (self ):
72
+ return '<CanonicalEventLink %r>' % (self .id )
73
+
74
+
75
+ class CanonicalEventRelationship (Base ):
76
+ __tablename__ = 'canonical_event_relationship'
77
+ id = Column (Integer , primary_key = True )
78
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
79
+ canonical_id1 = Column (Integer , ForeignKey ('canonical_event.id' ))
80
+ canonical_id2 = Column (Integer , ForeignKey ('canonical_event.id' ))
81
+ relationship_type = Column (Text )
82
+ timestamp = Column (DateTime )
83
+
84
+ UniqueConstraint ('canonical_id1' , 'canonical_id2' , 'relationship_type' , name = 'unique1' )
85
+
86
+ def __init__ (self , coder_id , canonical_id1 , canonical_id2 , relationship_type ):
87
+ self .coder_id = coder_id
88
+ self .canonical_id1 = canonical_id1
89
+ self .canonical_id2 = canonical_id2
90
+ self .relationship_type = relationship_type
91
+ self .timestamp = dt .datetime .now (tz = central ).replace (tzinfo = None )
92
+
93
+ def __repr__ (self ):
94
+ return '<CanonicalEventRelationship %r -> %r (%r)>' % \
95
+ (self .canonical_id1 , self .canonical_id2 , self .relationship_type )
96
+
97
+
98
+ class EventFlag (Base ):
99
+ __tablename__ = 'event_flag'
100
+ id = Column (Integer , primary_key = True )
101
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
102
+ event_id = Column (Integer , ForeignKey ('event.id' ))
103
+ flag = Column (Text )
104
+ timestamp = Column (DateTime )
105
+
106
+ UniqueConstraint ('event_id' , name = 'unique1' )
107
+
108
+ def __init__ (self , coder_id , event_id , flag ):
109
+ self .coder_id = coder_id
110
+ self .event_id = event_id
111
+ self .flag = flag
112
+ self .timestamp = dt .datetime .now (tz = central ).replace (tzinfo = None )
113
+
114
+ def __repr__ (self ):
115
+ return '<EventFlag %r (%r)>' % (self .event_id , self .flag )
116
+
117
+
118
+ class EventMetadata (Base ):
119
+ __tablename__ = 'event_metadata'
120
+ id = Column (Integer , primary_key = True )
121
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
122
+ event_id = Column (Integer , ForeignKey ('event.id' ))
123
+ article_id = Column (Integer , ForeignKey ('article_metadata.id' ))
124
+ article_desc = Column (UnicodeText , nullable = True )
125
+ desc = Column (UnicodeText , nullable = True )
126
+ location = Column (Text , nullable = True )
127
+ start_date = Column (Date , nullable = True )
128
+ publication = Column (Text )
129
+ pub_date = Column (Date )
130
+ title = Column (Text )
131
+ form = Column (Text )
132
+
133
+ UniqueConstraint ('event_id' , name = 'unique1' )
134
+
135
+ def __init__ (self , coder_id , event_id , article_id , article_desc , desc ,
136
+ location , start_date , publication , pub_date , title , form ):
137
+ self .coder_id = coder_id
138
+ self .event_id = event_id
139
+ self .article_id = article_id
140
+ self .article_desc = article_desc
141
+ self .desc = desc
142
+ self .location = location
143
+ self .start_date = start_date
144
+ self .publication = publication
145
+ self .pub_date = pub_date
146
+ self .title = title
147
+ self .form = form
148
+
149
+ def __repr__ (self ):
150
+ return '<EventMetadata %r>' % (self .event_id )
151
+
152
+
153
+ class RecentCanonicalEvent (Base ):
154
+ __tablename__ = 'recent_canonical_event'
155
+ id = Column (Integer , primary_key = True )
156
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
157
+ canonical_id = Column (Integer , ForeignKey ('canonical_event.id' ))
158
+ last_accessed = Column (DateTime )
159
+
160
+ UniqueConstraint ('coder_id' , 'canonical_id' , name = 'unique1' )
161
+
162
+ def __init__ (self , coder_id , canonical_id ):
163
+ self .coder_id = coder_id
164
+ self .canonical_id = canonical_id
165
+ self .last_accessed = dt .datetime .now (tz = central ).replace (tzinfo = None )
166
+
167
+ def __repr__ (self ):
168
+ return '<RecentCanonicalEvent %r (%r)>' % (self .canonical_id , self .last_accessed )
169
+
170
+
171
+ class RecentEvent (Base ):
172
+ __tablename__ = 'recent_event'
173
+ id = Column (Integer , primary_key = True )
174
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
175
+ event_id = Column (Integer , ForeignKey ('event.id' ))
176
+ last_accessed = Column (DateTime )
177
+
178
+ UniqueConstraint ('coder_id' , 'event_id' , name = 'unique1' )
179
+
180
+ def __init__ (self , coder_id , event_id ):
181
+ self .coder_id = coder_id
182
+ self .event_id = event_id
183
+ self .last_accessed = dt .datetime .now (tz = central ).replace (tzinfo = None )
184
+
185
+ def __repr__ (self ):
186
+ return '<RecentEvent %r (%r)>' % (self .event_id , self .last_accessed )
187
+
188
+
189
+ class RecentSearch (Base ):
190
+ __tablename__ = 'recent_search'
191
+ id = Column (Integer , primary_key = True )
192
+ coder_id = Column (Integer , ForeignKey ('user.id' ))
193
+ field = Column (Text )
194
+ comparison = Column (Text )
195
+ value = Column (Text )
196
+ last_accessed = Column (DateTime )
197
+
198
+ UniqueConstraint ('coder_id' , 'field' , 'comparison' , 'value' , name = 'unique1' )
199
+
200
+ def __init__ (self , coder_id , field , comparison , value ):
201
+ self .coder_id = coder_id
202
+ self .field = field
203
+ self .comparison = comparison
204
+ self .value = value
205
+ self .last_accessed = dt .datetime .now (tz = central ).replace (tzinfo = None )
206
+
207
+ def __repr__ (self ):
208
+ return '<RecentSearch %r-%r-%r (%r)>' % \
209
+ (self .field , self .comparison , self .value , self .last_accessed )
210
+
211
+
32
212
class CodeFirstPass (Base ):
33
213
__tablename__ = 'coder_first_pass'
34
214
id = Column (Integer , primary_key = True )
@@ -116,7 +296,7 @@ class ArticleQueue(Base):
116
296
id = Column (Integer , primary_key = True )
117
297
article_id = Column (Integer , ForeignKey ('article_metadata.id' ), nullable = False )
118
298
coder_id = Column (Integer , ForeignKey ('user.id' ), nullable = False )
119
- coded_dt = Column (DateTime )
299
+ coded_dt = Column (DateTime )
120
300
121
301
UniqueConstraint ('article_id' , 'coder_id' , name = 'unique1' )
122
302
@@ -219,11 +399,11 @@ def __init__(self, username, password, authlevel):
219
399
self .password = password
220
400
self .authlevel = authlevel
221
401
222
- def get_id (self ):
223
- try :
224
- return unicode (self .id ) # python 2
225
- except NameError :
226
- return str (self .id ) # python 3
402
+ # def get_id(self):
403
+ # try:
404
+ # return unicode(self.id) # python 2
405
+ # except NameError:
406
+ # return str(self.id) # python 3
227
407
228
408
def __repr__ (self ):
229
409
return '<Coder %r>' % (self .username )
0 commit comments