33from django .db import models
44from ietf .utils import FKAsOneToOne
55from django .test import TestCase
6+ import datetime
67
78class Acronym (models .Model ):
89 acronym_id = models .AutoField (primary_key = True )
@@ -184,8 +185,8 @@ def displayname_with_link(self):
184185 class Meta :
185186 db_table = "internet_drafts"
186187 class Admin :
187- search_fields = ['filename' ]
188- list_display = ('filename' , 'revision' , 'status' )
188+ search_fields = ['filename' , 'title' ]
189+ list_display = ('filename' , 'revision' , 'title' , ' status' )
189190 list_filter = ['status' ]
190191 pass
191192 #date_hierarchy = 'revision_date'
@@ -220,7 +221,7 @@ def email(self, priority=1, type='INET'):
220221 name = str (self )
221222 try :
222223 email = self .emailaddress_set .get (priority = priority , type = type ).address
223- except EmailAddress .DoesNotExist :
224+ except ( EmailAddress .DoesNotExist , AssertionError ) :
224225 email = ''
225226 return (name , email )
226227 # Added by Sunny Lee to display person's affiliation - 5/26/2007
@@ -239,6 +240,14 @@ class Meta:
239240 verbose_name_plural = "Rolodex"
240241 class Admin :
241242 search_fields = ['first_name' ,'last_name' ]
243+ fields = (
244+ (None , {
245+ 'fields' : (('first_name' , 'middle_initial' , 'last_name' ), ('name_suffix' , 'modified_by' ))
246+ }),
247+ ('Obsolete Info' , {
248+ 'classes' : 'collapse' ,
249+ 'fields' : ('record_type' , 'created_by' , 'address_type' )
250+ }))
242251 pass
243252
244253# could use a mapping for user_level
@@ -293,6 +302,7 @@ class Admin:
293302# RFC tables
294303
295304class RfcIntendedStatus (models .Model ):
305+ NONE = 5
296306 intended_status_id = models .AutoField (primary_key = True )
297307 status = models .CharField (maxlength = 25 , db_column = 'status_value' )
298308 def __str__ (self ):
@@ -316,17 +326,18 @@ class Admin:
316326 pass
317327
318328class Rfc (models .Model ):
329+ ONLINE_CHOICES = (('YES' , 'Yes' ), ('NO' , 'No' ))
319330 rfc_number = models .IntegerField (primary_key = True )
320331 title = models .CharField (maxlength = 200 , db_column = 'rfc_name' )
321332 rfc_name_key = models .CharField (maxlength = 200 , editable = False )
322333 group_acronym = models .CharField (blank = True , maxlength = 8 )
323334 area_acronym = models .CharField (blank = True , maxlength = 8 )
324335 status = models .ForeignKey (RfcStatus , db_column = "status_id" )
325- intended_status = models .ForeignKey (RfcIntendedStatus , db_column = "intended_status_id" )
336+ intended_status = models .ForeignKey (RfcIntendedStatus , db_column = "intended_status_id" , default = RfcIntendedStatus . NONE )
326337 fyi_number = models .CharField (blank = True , maxlength = 20 )
327338 std_number = models .CharField (blank = True , maxlength = 20 )
328339 txt_page_count = models .IntegerField (null = True , blank = True )
329- online_version = models .CharField (blank = True , maxlength = 3 )
340+ online_version = models .CharField (choices = ONLINE_CHOICES , maxlength = 3 , default = 'YES' )
330341 rfc_published_date = models .DateField (null = True , blank = True )
331342 proposed_date = models .DateField (null = True , blank = True )
332343 draft_date = models .DateField (null = True , blank = True )
@@ -342,6 +353,7 @@ def __str__(self):
342353 return "RFC%04d" % ( self .rfc_number )
343354 def save (self ):
344355 self .rfc_name_key = self .title .upper ()
356+ self .last_modified_date = datetime .date .today ()
345357 super (Rfc , self ).save ()
346358 def displayname (self ):
347359 return "%s.txt" % ( self .filename () )
@@ -375,9 +387,24 @@ class Meta:
375387 verbose_name = 'RFC'
376388 verbose_name_plural = 'RFCs'
377389 class Admin :
378- search_fields = ['title' , 'group' , 'area' ]
390+ search_fields = ['title' ]
379391 list_display = ['rfc_number' , 'title' ]
380- pass
392+ fields = (
393+ (None , {
394+ 'fields' : ('rfc_number' , 'title' , 'group_acronym' , 'area_acronym' , 'status' , 'comments' , 'last_modified_date' )
395+ }),
396+ ('Metadata' , {
397+ 'classes' : 'collapse' ,
398+ 'fields' : (('online_version' , 'txt_page_count' ), ('fyi_number' , 'std_number' ))
399+ }),
400+ ('Standards Track Dates' , {
401+ 'classes' : 'collapse' ,
402+ 'fields' : ('rfc_published_date' , ('proposed_date' , 'draft_date' ), ('standard_date' , 'historic_date' ))
403+ }),
404+ ('Last Call / Ballot Info' , {
405+ 'classes' : 'collapse' ,
406+ 'fields' : ('intended_status' , ('lc_sent_date' , 'lc_expiration_date' ), ('b_sent_date' , 'b_approve_date' ))
407+ }))
381408
382409class RfcAuthor (models .Model ):
383410 rfc = models .ForeignKey (Rfc , unique = True , db_column = 'rfc_number' , related_name = 'authors' , edit_inline = models .TABULAR )
@@ -649,12 +676,11 @@ class Meta:
649676# create the isUniquefoo_bar method properly. Since django is
650677# moving away from oldforms, I have to assume that this is going
651678# to be fixed by moving admin to newforms.
652- # A table without a unique primary key!
653679# must decide which field is/are core.
654680class PostalAddress (models .Model ):
655681 address_type = models .CharField (maxlength = 4 )
656682 address_priority = models .IntegerField (null = True )
657- person_or_org = models .ForeignKey (PersonOrOrgInfo , primary_key = True , db_column = 'person_or_org_tag' , edit_inline = models .STACKED )
683+ person_or_org = models .ForeignKey (PersonOrOrgInfo , db_column = 'person_or_org_tag' , edit_inline = models .STACKED , num_in_admin = 1 )
658684 person_title = models .CharField (maxlength = 50 , blank = True )
659685 affiliated_company = models .CharField (maxlength = 70 , blank = True )
660686 aff_company_key = models .CharField (maxlength = 70 , blank = True , editable = False )
@@ -675,7 +701,7 @@ class Meta:
675701 verbose_name_plural = 'Postal Addresses'
676702
677703class EmailAddress (models .Model ):
678- person_or_org = models .ForeignKey (PersonOrOrgInfo , primary_key = True , db_column = 'person_or_org_tag' , edit_inline = models .TABULAR )
704+ person_or_org = models .ForeignKey (PersonOrOrgInfo , db_column = 'person_or_org_tag' , edit_inline = models .TABULAR , num_in_admin = 1 )
679705 type = models .CharField (maxlength = 12 , db_column = 'email_type' )
680706 priority = models .IntegerField (db_column = 'email_priority' )
681707 address = models .CharField (maxlength = 255 , core = True , db_column = 'email_address' )
@@ -686,9 +712,10 @@ class Meta:
686712 db_table = 'email_addresses'
687713 #unique_together = (('email_priority', 'person_or_org'), )
688714 # with this, I get 'ChangeManipulator' object has no attribute 'isUniqueemail_priority_person_or_org'
715+ verbose_name_plural = 'Email addresses'
689716
690717class PhoneNumber (models .Model ):
691- person_or_org = models .ForeignKey (PersonOrOrgInfo , primary_key = True , db_column = 'person_or_org_tag' , edit_inline = models .TABULAR )
718+ person_or_org = models .ForeignKey (PersonOrOrgInfo , db_column = 'person_or_org_tag' , edit_inline = models .TABULAR , num_in_admin = 1 )
692719 phone_type = models .CharField (maxlength = 3 )
693720 phone_priority = models .IntegerField ()
694721 phone_number = models .CharField (blank = True , maxlength = 255 , core = True )
@@ -859,6 +886,7 @@ class Role(models.Model):
859886 '''
860887 person = models .ForeignKey (PersonOrOrgInfo , db_column = 'person_or_org_tag' , raw_id_admin = True )
861888 role_name = models .CharField (maxlength = 25 , db_column = 'chair_name' )
889+ # This __str__ makes it odd to use as a ForeignKey.
862890 def __str__ (self ):
863891 return "%s (%s)" % (self .person , self .role ())
864892 def role (self ):
@@ -872,18 +900,18 @@ class Admin:
872900 pass
873901
874902class ChairsHistory (models .Model ):
875- CHAIR_CHOICES = (
876- ( '1' , 'IETF' ),
877- ( '2' , 'IAB' ),
878- ( '3' , 'NOMCOM' ),
879- )
880- chair_type_id = models .IntegerField (choices = CHAIR_CHOICES )
903+ chair_type = models .ForeignKey (Role )
881904 present_chair = models .BooleanField ()
882905 person = models .ForeignKey (PersonOrOrgInfo , db_column = 'person_or_org_tag' , raw_id_admin = True )
883906 start_year = models .IntegerField ()
884907 end_year = models .IntegerField (null = True , blank = True )
908+ def __str__ (self ):
909+ return str (self .person )
885910 class Meta :
886911 db_table = 'chairs_history'
912+ class Admin :
913+ list_display = ('person' , 'chair_type' , 'start_year' , 'end_year' )
914+ pass
887915
888916#
889917# IRTF RG info
0 commit comments