view.py and form.py
unknown
plain_text
2 years ago
5.5 kB
6
Indexable
1432 -- view.py
five_columns = False
for x in app_doc:
if x.accepted_verified_by_bits_flag or x.rejected_by_bits_flag or x.exception_notes:
five_columns = True
2012---- form.py
class DocumentUploadWizardForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(DocumentUploadWizardForm, self).__init__(*args, **kwargs)
if kwargs.get('instance'):
document = kwargs.get('instance').document
sca = kwargs.get('instance').application
elif self.initial:
document = self.initial['document']
sca = StudentCandidateApplication.objects.get(pk=self.initial['application'])
elif kwargs.get('data'):
document = DocumentType.objects.get(pk=kwargs['data']['document'])
sca = StudentCandidateApplication.objects.get(pk=kwargs['data']['application'])
pdm = ProgramDocumentMap.objects.filter(program=sca.program)
mandatory = (
pdm.get(document_type=document).mandatory_flag if pdm.exists()
else document.mandatory_document
)
deffered = (
pdm.get(document_type=document).deffered_submission_flag if pdm.exists()
else False
)
self.fields['document'].label = '%s %s %s' % (
document,
'<span class="text-danger">*</span>' if mandatory else '',
'<br><span style="color:red">Will need to be submitted but can be done later</span>' if deffered else '',
)
self.fields['document'].widget = forms.HiddenInput()
self.fields['application'].widget = forms.HiddenInput()
self.fields['file'].widget = DocFileWizardWidget(
instance=kwargs.get('instance') or kwargs.get('data', {}).get('id'),
mandatory=mandatory)
# self.fields['file'].widget = DocFileWizardWidget(instance=kwargs.get('instance') or kwargs.get('data', {}).get('id'))
document_styles = {
'APPLICANT PHOTOGRAPH': 'display: none;',
'EMPLOYER CONSENT FORM (or NOMINATION LETTER)': 'display: none;',
'MENTOR CONSENT FORM': 'display: none;',
'APPLICATION FORM (SIGNED & SCANNED)': 'display: none;',
}
document_name = document.document_name
if document_name in document_styles:
self.fields['file'].widget.attrs['style'] = document_styles[document_name]
emp = [ 'EMPLOYER CONSENT FORM (or NOMINATION LETTER)', 'MENTOR CONSENT FORM']
if document_name in emp :
file = kwargs.get('instance') or kwargs.get('data', {}).get('id')
self.fields['file'].widget.attrs['class'] = 'employer' if not document_name == emp[1] else 'mentor'
if mandatory and not file.file:
self.fields['file'].widget.attrs['required'] = True
elif mandatory and file.file:
self.fields['file'].widget.attrs['required'] = False
else:
self.fields['file'].widget.attrs['required'] = False
# self.fields['file'].widget.attrs['required'] = True if not file.file else False
if not file.file:
self.fields['file'].widget.attrs['data-error-msg'] = 'Inform your {} to submit the form.'.format('employer' if not document_name == emp[1] else 'mentor')
till above meta
1914--- forms.py
class DocFileWizardWidget(forms.ClearableFileInput):
def __init__(self, instance=None, mandatory=False, *args, **kwargs):
self.instance = instance
super(DocFileWizardWidget, self).__init__(*args, **kwargs)
self.attrs['required'] = False if self.instance else mandatory
template_with_initial = ('%(input)s<br>'
'<a href="%(initial_url)s">Document</a> '
)
def get_template_substitution_values(self, value):
return {
'initial': conditional_escape(value)[:40]+'...',
'initial_url': (
reverse_lazy('registrationForm:document-view', kwargs={'pk': self.instance.pk})
if self.instance and self.instance.file else '#'
),
}
upload form wizard.html
{% load static %}
{% load widget_tweaks %}
{% load admission_specific_filter %}
{% load admission_filter %}
<td>
{{form.document.label|safe}}
{{form.document}}{{form.id}}
{{form.application}}
<br>
<center>
<div class="progress " id="{{form.id.auto_id}}_progress" style="display:none;">
<div id='{{form.id.auto_id}}_pb' class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:50%">
0%
</div>
</div>
</center>
</td>
<td>
<span id='{{form.id.auto_id}}_errors' class="text-danger">
{% for k,v in form.errors %}
<strong>{{k}}</strong>: {{v}}
{% endfor %}
</span>
{{form.file}}
</td>
<!-- status -->
{% if five_columns %}
<td>
{% if form.accepted_verified_by_bits_flag.value %}
Accepted
{% elif form.rejected_by_bits_flag.value %}
<span style="color: rgb(197, 3, 3);">Rejected</span>
{% else %}
{% endif %}
</td>
<!-- Rejection Reason -->
<td>
{{ form.rejection_reason.value |default:'' }}
</td>
<!-- Comments -->
<td>
{{ form.exception_notes.value |default:'' }}
</td>
{% endif %}
Editor is loading...
Leave a Comment