<s> from django import forms <EOL> from django . core . exceptions import ValidationError <EOL> from journalmanager import models as jm_models <EOL> class BlidModelChoiceField ( forms . ModelChoiceField ) : <EOL> def to_python ( self , value ) : <EOL> try : <EOL> issue_pk = int ( value ) <EOL> except ValueError : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> try : <EOL> return jm_models . Issue . objects . get ( pk = issue_pk ) <EOL> except jm_models . Issue . DoesNotExist : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> class MarkupFilesForm ( forms . Form ) : <EOL> journal = forms . ModelChoiceField ( queryset = jm_models . Journal . objects . none ( ) ) <EOL> issue = BlidModelChoiceField ( queryset = jm_models . Issue . objects . none ( ) ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> user = kwargs . pop ( '<STR_LIT:user>' , None ) <EOL> super ( MarkupFilesForm , self ) . __init__ ( * args , ** kwargs ) <EOL> if user : <EOL> self . fields [ '<STR_LIT>' ] . queryset = jm_models . Journal . objects . all_by_user ( user ) </s>
