Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-25 08:29:11

0001 from django import forms
0002 from .models import PhysicsCategory, PhysicsTag, EvgenTag, SimuTag, RecoTag, Dataset, ProdConfig
0003 from .schemas import TAG_SCHEMAS, get_param_defs
0004 
0005 
0006 class PhysicsCategoryForm(forms.ModelForm):
0007     class Meta:
0008         model = PhysicsCategory
0009         fields = ['digit', 'name', 'description', 'created_by']
0010         widgets = {
0011             'description': forms.Textarea(attrs={'rows': 3}),
0012         }
0013 
0014 
0015 class PhysicsTagForm(forms.Form):
0016     category = forms.ModelChoiceField(
0017         queryset=PhysicsCategory.objects.all(),
0018         empty_label="Select category",
0019     )
0020     description = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}))
0021     created_by = forms.CharField(max_length=100)
0022 
0023     def __init__(self, *args, **kwargs):
0024         super().__init__(*args, **kwargs)
0025         for pdef in get_param_defs('p'):
0026             self.fields[f'param_{pdef["name"]}'] = forms.CharField(
0027                 label=pdef['name'], required=pdef.get('required', False),
0028             )
0029 
0030     def get_parameters(self):
0031         return {
0032             k.removeprefix('param_'): v
0033             for k, v in self.cleaned_data.items()
0034             if k.startswith('param_') and v
0035         }
0036 
0037 
0038 class SimpleTagForm(forms.Form):
0039     description = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}))
0040     created_by = forms.CharField(max_length=100)
0041 
0042     def __init__(self, *args, tag_type=None, **kwargs):
0043         super().__init__(*args, **kwargs)
0044         self.tag_type = tag_type
0045         if tag_type:
0046             for pdef in get_param_defs(tag_type):
0047                 self.fields[f'param_{pdef["name"]}'] = forms.CharField(
0048                     label=pdef['name'], required=pdef.get('required', False),
0049                 )
0050 
0051     def get_parameters(self):
0052         return {
0053             k.removeprefix('param_'): v
0054             for k, v in self.cleaned_data.items()
0055             if k.startswith('param_') and v
0056         }
0057 
0058 
0059 class DatasetForm(forms.Form):
0060     scope = forms.CharField(max_length=100, initial='group.EIC')
0061     detector_version = forms.CharField(max_length=50)
0062     detector_config = forms.CharField(max_length=100)
0063     physics_tag = forms.ModelChoiceField(
0064         queryset=PhysicsTag.objects.filter(status='locked'),
0065         empty_label="Select physics tag",
0066     )
0067     evgen_tag = forms.ModelChoiceField(
0068         queryset=EvgenTag.objects.filter(status='locked'),
0069         empty_label="Select evgen tag",
0070     )
0071     simu_tag = forms.ModelChoiceField(
0072         queryset=SimuTag.objects.filter(status='locked'),
0073         empty_label="Select simu tag",
0074     )
0075     reco_tag = forms.ModelChoiceField(
0076         queryset=RecoTag.objects.filter(status='locked'),
0077         empty_label="Select reco tag",
0078     )
0079     description = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}), required=False)
0080     created_by = forms.CharField(max_length=100)
0081 
0082 
0083 class ProdConfigForm(forms.ModelForm):
0084     class Meta:
0085         model = ProdConfig
0086         fields = [
0087             'name', 'description',
0088             'bg_mixing', 'bg_cross_section', 'bg_evtgen_file',
0089             'copy_reco', 'copy_full', 'copy_log', 'use_rucio',
0090             'jug_xl_tag', 'container_image',
0091             'target_hours_per_job', 'events_per_task',
0092             'condor_template',
0093             'panda_site', 'panda_queue', 'panda_working_group', 'panda_resource_type',
0094             'rucio_rse', 'rucio_replication_rules',
0095             'data',
0096             'created_by',
0097         ]
0098         widgets = {
0099             'description': forms.Textarea(attrs={'rows': 3}),
0100             'condor_template': forms.Textarea(attrs={'rows': 10, 'style': 'font-family: monospace;'}),
0101             'rucio_replication_rules': forms.Textarea(attrs={'rows': 4, 'style': 'font-family: monospace;'}),
0102             'data': forms.Textarea(attrs={'rows': 8, 'style': 'font-family: monospace;',
0103                                           'placeholder': '{\n  "transformation": "runGen-00-00-02",\n  "processing_type": "epicproduction",\n  "n_jobs": 1000,\n  "events_per_job": 100,\n  "corecount": 1\n}'}),
0104         }
0105 
0106     def __init__(self, *args, **kwargs):
0107         super().__init__(*args, **kwargs)
0108         for name, field in self.fields.items():
0109             if isinstance(field.widget, forms.CheckboxInput):
0110                 field.widget.attrs.setdefault('class', 'form-check-input')
0111             else:
0112                 field.widget.attrs.setdefault('class', 'form-control')