<s> from pymongo import DESCENDING <EOL> from django import forms <EOL> from tasks . models import Tasks <EOL> from tasks . exceptions import TaskDoesNotExists <EOL> from . models import Project <EOL> class FindTaskForBadgeForm ( forms . Form ) : <EOL> """<STR_LIT>""" <EOL> project = forms . ModelChoiceField ( <EOL> Project . objects . all ( ) , required = True , to_field_name = '<STR_LIT:name>' , <EOL> ) <EOL> commit = forms . CharField ( required = False ) <EOL> branch = forms . CharField ( required = False ) <EOL> def get_task ( self ) : <EOL> """<STR_LIT>""" <EOL> filter_spec = { <EOL> '<STR_LIT>' : self . cleaned_data [ '<STR_LIT>' ] . name , <EOL> } <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) : <EOL> filter_spec [ '<STR_LIT>' ] = self . cleaned_data [ '<STR_LIT>' ] <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) : <EOL> filter_spec [ '<STR_LIT>' ] = self . cleaned_data [ '<STR_LIT>' ] <EOL> task = Tasks . find_one ( <EOL> filter_spec , sort = [ ( '<STR_LIT>' , DESCENDING ) ] , fields = { <EOL> '<STR_LIT:status>' : True , <EOL> } , <EOL> ) <EOL> if task : <EOL> return task <EOL> else : <EOL> raise TaskDoesNotExists ( filter_spec ) </s>
