2727from ietf .utils .admin import admin_link
2828from ietf .utils .validators import validate_no_control_chars
2929from ietf .utils .mail import formataddr
30+ from ietf .utils .models import ForeignKey , OneToOneField
3031
3132logger = logging .getLogger ('django' )
3233
@@ -52,7 +53,7 @@ def check_statetype_slugs(app_configs, **kwargs):
5253 return errors
5354
5455class State (models .Model ):
55- type = models . ForeignKey (StateType )
56+ type = ForeignKey (StateType )
5657 slug = models .SlugField ()
5758 name = models .CharField (max_length = 255 )
5859 used = models .BooleanField (default = True )
@@ -74,24 +75,24 @@ class DocumentInfo(models.Model):
7475 """Any kind of document. Draft, RFC, Charter, IPR Statement, Liaison Statement"""
7576 time = models .DateTimeField (default = datetime .datetime .now ) # should probably have auto_now=True
7677
77- type = models . ForeignKey (DocTypeName , blank = True , null = True ) # Draft, Agenda, Minutes, Charter, Discuss, Guideline, Email, Review, Issue, Wiki, External ...
78+ type = ForeignKey (DocTypeName , blank = True , null = True ) # Draft, Agenda, Minutes, Charter, Discuss, Guideline, Email, Review, Issue, Wiki, External ...
7879 title = models .CharField (max_length = 255 , validators = [validate_no_control_chars , ])
7980
8081 states = models .ManyToManyField (State , blank = True ) # plain state (Active/Expired/...), IESG state, stream state
8182 tags = models .ManyToManyField (DocTagName , blank = True ) # Revised ID Needed, ExternalParty, AD Followup, ...
82- stream = models . ForeignKey (StreamName , blank = True , null = True ) # IETF, IAB, IRTF, Independent Submission
83- group = models . ForeignKey (Group , blank = True , null = True ) # WG, RG, IAB, IESG, Edu, Tools
83+ stream = ForeignKey (StreamName , blank = True , null = True ) # IETF, IAB, IRTF, Independent Submission
84+ group = ForeignKey (Group , blank = True , null = True ) # WG, RG, IAB, IESG, Edu, Tools
8485
8586 abstract = models .TextField (blank = True )
8687 rev = models .CharField (verbose_name = "revision" , max_length = 16 , blank = True )
8788 pages = models .IntegerField (blank = True , null = True )
8889 words = models .IntegerField (blank = True , null = True )
8990 formal_languages = models .ManyToManyField (FormalLanguageName , blank = True , help_text = "Formal languages used in document" )
9091 order = models .IntegerField (default = 1 , blank = True ) # This is probably obviated by SessionPresentaion.order
91- intended_std_level = models . ForeignKey (IntendedStdLevelName , verbose_name = "Intended standardization level" , blank = True , null = True )
92- std_level = models . ForeignKey (StdLevelName , verbose_name = "Standardization level" , blank = True , null = True )
93- ad = models . ForeignKey (Person , verbose_name = "area director" , related_name = 'ad_%(class)s_set' , blank = True , null = True )
94- shepherd = models . ForeignKey (Email , related_name = 'shepherd_%(class)s_set' , blank = True , null = True )
92+ intended_std_level = ForeignKey (IntendedStdLevelName , verbose_name = "Intended standardization level" , blank = True , null = True )
93+ std_level = ForeignKey (StdLevelName , verbose_name = "Standardization level" , blank = True , null = True )
94+ ad = ForeignKey (Person , verbose_name = "area director" , related_name = 'ad_%(class)s_set' , blank = True , null = True )
95+ shepherd = ForeignKey (Email , related_name = 'shepherd_%(class)s_set' , blank = True , null = True )
9596 expires = models .DateTimeField (blank = True , null = True )
9697 notify = models .CharField (max_length = 255 , blank = True )
9798 external_url = models .URLField (blank = True ) # Should be set for documents with type 'External'.
@@ -482,9 +483,9 @@ class Meta:
482483STATUSCHANGE_RELATIONS = ('tops' ,'tois' ,'tohist' ,'toinf' ,'tobcp' ,'toexp' )
483484
484485class RelatedDocument (models .Model ):
485- source = models . ForeignKey ('Document' )
486- target = models . ForeignKey ('DocAlias' )
487- relationship = models . ForeignKey (DocRelationshipName )
486+ source = ForeignKey ('Document' )
487+ target = ForeignKey ('DocAlias' )
488+ relationship = ForeignKey (DocRelationshipName )
488489 def action (self ):
489490 return self .relationship .name
490491 def __unicode__ (self ):
@@ -536,9 +537,9 @@ def is_approved_downref(self):
536537 return False
537538
538539class DocumentAuthorInfo (models .Model ):
539- person = models . ForeignKey (Person )
540+ person = ForeignKey (Person )
540541 # email should only be null for some historic documents
541- email = models . ForeignKey (Email , help_text = "Email address used by author for submission" , blank = True , null = True )
542+ email = ForeignKey (Email , help_text = "Email address used by author for submission" , blank = True , null = True )
542543 affiliation = models .CharField (max_length = 100 , blank = True , help_text = "Organization/company used by author for submission" )
543544 country = models .CharField (max_length = 255 , blank = True , help_text = "Country used by author for submission" )
544545 order = models .IntegerField (default = 1 )
@@ -555,7 +556,7 @@ class Meta:
555556 ordering = ["document" , "order" ]
556557
557558class DocumentAuthor (DocumentAuthorInfo ):
558- document = models . ForeignKey ('Document' )
559+ document = ForeignKey ('Document' )
559560
560561 def __unicode__ (self ):
561562 return u"%s %s (%s)" % (self .document .name , self .person , self .order )
@@ -807,28 +808,28 @@ def fake_history_obj(self, rev):
807808
808809
809810class DocumentURL (models .Model ):
810- doc = models . ForeignKey (Document )
811- tag = models . ForeignKey (DocUrlTagName )
811+ doc = ForeignKey (Document )
812+ tag = ForeignKey (DocUrlTagName )
812813 desc = models .CharField (max_length = 255 , default = '' , blank = True )
813814 url = models .URLField (max_length = 512 )
814815
815816class RelatedDocHistory (models .Model ):
816- source = models . ForeignKey ('DocHistory' )
817- target = models . ForeignKey ('DocAlias' , related_name = "reversely_related_document_history_set" )
818- relationship = models . ForeignKey (DocRelationshipName )
817+ source = ForeignKey ('DocHistory' )
818+ target = ForeignKey ('DocAlias' , related_name = "reversely_related_document_history_set" )
819+ relationship = ForeignKey (DocRelationshipName )
819820 def __unicode__ (self ):
820821 return u"%s %s %s" % (self .source .doc .name , self .relationship .name .lower (), self .target .name )
821822
822823class DocHistoryAuthor (DocumentAuthorInfo ):
823824 # use same naming convention as non-history version to make it a bit
824825 # easier to write generic code
825- document = models . ForeignKey ('DocHistory' , related_name = "documentauthor_set" )
826+ document = ForeignKey ('DocHistory' , related_name = "documentauthor_set" )
826827
827828 def __unicode__ (self ):
828829 return u"%s %s (%s)" % (self .document .doc .name , self .person , self .order )
829830
830831class DocHistory (DocumentInfo ):
831- doc = models . ForeignKey (Document , related_name = "history_set" )
832+ doc = ForeignKey (Document , related_name = "history_set" )
832833 # the name here is used to capture the canonical name at the time
833834 # - it would perhaps be more elegant to simply call the attribute
834835 # canonical_name and replace the function on Document with a
@@ -878,7 +879,7 @@ class DocAlias(models.Model):
878879 to by RFC number, primarily, after achieving RFC status.
879880 """
880881 name = models .CharField (max_length = 255 , primary_key = True )
881- document = models . ForeignKey (Document )
882+ document = ForeignKey (Document )
882883 def __unicode__ (self ):
883884 return "%s-->%s" % (self .name , self .document .name )
884885 document_link = admin_link ("document" )
@@ -887,8 +888,8 @@ class Meta:
887888 verbose_name_plural = "document aliases"
888889
889890class DocReminder (models .Model ):
890- event = models . ForeignKey ('DocEvent' )
891- type = models . ForeignKey (DocReminderTypeName )
891+ event = ForeignKey ('DocEvent' )
892+ type = ForeignKey (DocReminderTypeName )
892893 due = models .DateTimeField ()
893894 active = models .BooleanField (default = True )
894895
@@ -972,8 +973,8 @@ class DocEvent(models.Model):
972973 """An occurrence for a document, used for tracking who, when and what."""
973974 time = models .DateTimeField (default = datetime .datetime .now , help_text = "When the event happened" , db_index = True )
974975 type = models .CharField (max_length = 50 , choices = EVENT_TYPES )
975- by = models . ForeignKey (Person )
976- doc = models . ForeignKey ('doc.Document' )
976+ by = ForeignKey (Person )
977+ doc = ForeignKey ('doc.Document' )
977978 rev = models .CharField (verbose_name = "revision" , max_length = 16 , null = True , blank = True )
978979 desc = models .TextField ()
979980
@@ -998,15 +999,15 @@ class NewRevisionDocEvent(DocEvent):
998999 pass
9991000
10001001class StateDocEvent (DocEvent ):
1001- state_type = models . ForeignKey (StateType )
1002- state = models . ForeignKey (State , blank = True , null = True )
1002+ state_type = ForeignKey (StateType )
1003+ state = ForeignKey (State , blank = True , null = True )
10031004
10041005class ConsensusDocEvent (DocEvent ):
10051006 consensus = models .NullBooleanField (default = None )
10061007
10071008# IESG events
10081009class BallotType (models .Model ):
1009- doc_type = models . ForeignKey (DocTypeName , blank = True , null = True )
1010+ doc_type = ForeignKey (DocTypeName , blank = True , null = True )
10101011 slug = models .SlugField ()
10111012 name = models .CharField (max_length = 255 )
10121013 question = models .TextField (blank = True )
@@ -1021,7 +1022,7 @@ class Meta:
10211022 ordering = ['order' ]
10221023
10231024class BallotDocEvent (DocEvent ):
1024- ballot_type = models . ForeignKey (BallotType )
1025+ ballot_type = ForeignKey (BallotType )
10251026
10261027 def active_ad_positions (self ):
10271028 """Return dict mapping each active AD to a current ballot position (or None if they haven't voted)."""
@@ -1083,9 +1084,9 @@ def all_positions(self):
10831084 return positions
10841085
10851086class BallotPositionDocEvent (DocEvent ):
1086- ballot = models . ForeignKey (BallotDocEvent , null = True , default = None ) # default=None is a temporary migration period fix, should be removed when charter branch is live
1087- ad = models . ForeignKey (Person )
1088- pos = models . ForeignKey (BallotPositionName , verbose_name = "position" , default = "norecord" )
1087+ ballot = ForeignKey (BallotDocEvent , null = True , default = None ) # default=None is a temporary migration period fix, should be removed when charter branch is live
1088+ ad = ForeignKey (Person )
1089+ pos = ForeignKey (BallotPositionName , verbose_name = "position" , default = "norecord" )
10891090 discuss = models .TextField (help_text = "Discuss text if position is discuss" , blank = True )
10901091 discuss_time = models .DateTimeField (help_text = "Time discuss text was written" , blank = True , null = True )
10911092 comment = models .TextField (help_text = "Optional comment" , blank = True )
@@ -1102,29 +1103,29 @@ class TelechatDocEvent(DocEvent):
11021103 returning_item = models .BooleanField (default = False )
11031104
11041105class ReviewRequestDocEvent (DocEvent ):
1105- review_request = models . ForeignKey ('review.ReviewRequest' )
1106- state = models . ForeignKey (ReviewRequestStateName , blank = True , null = True )
1106+ review_request = ForeignKey ('review.ReviewRequest' )
1107+ state = ForeignKey (ReviewRequestStateName , blank = True , null = True )
11071108
11081109# charter events
11091110class InitialReviewDocEvent (DocEvent ):
11101111 expires = models .DateTimeField (blank = True , null = True )
11111112
11121113class AddedMessageEvent (DocEvent ):
11131114 import ietf .message .models
1114- message = models . ForeignKey (ietf .message .models .Message , null = True , blank = True ,related_name = 'doc_manualevents' )
1115+ message = ForeignKey (ietf .message .models .Message , null = True , blank = True ,related_name = 'doc_manualevents' )
11151116 msgtype = models .CharField (max_length = 25 )
1116- in_reply_to = models . ForeignKey (ietf .message .models .Message , null = True , blank = True ,related_name = 'doc_irtomanual' )
1117+ in_reply_to = ForeignKey (ietf .message .models .Message , null = True , blank = True ,related_name = 'doc_irtomanual' )
11171118
11181119
11191120class SubmissionDocEvent (DocEvent ):
11201121 import ietf .submit .models
1121- submission = models . ForeignKey (ietf .submit .models .Submission )
1122+ submission = ForeignKey (ietf .submit .models .Submission )
11221123
11231124# dumping store for removed events
11241125class DeletedEvent (models .Model ):
1125- content_type = models . ForeignKey (ContentType )
1126+ content_type = ForeignKey (ContentType )
11261127 json = models .TextField (help_text = "Deleted object in JSON format, with attribute names chosen to be suitable for passing into the relevant create method." )
1127- by = models . ForeignKey (Person )
1128+ by = ForeignKey (Person )
11281129 time = models .DateTimeField (default = datetime .datetime .now )
11291130
11301131 def __unicode__ (self ):
0 commit comments