| 1 | # coding: utf-8 |
|---|
| 2 | |
|---|
| 3 | from opentrials.repository.trds_forms import ReviewModelForm |
|---|
| 4 | from opentrials.reviewapp.models import Remark |
|---|
| 5 | from opentrials.reviewapp.models import UserProfile |
|---|
| 6 | from opentrials.reviewapp.models import Attachment |
|---|
| 7 | from django import forms |
|---|
| 8 | from django.utils.translation import ugettext as _ |
|---|
| 9 | from django.contrib.auth.models import User |
|---|
| 10 | from django.conf import settings |
|---|
| 11 | |
|---|
| 12 | from repository.models import Institution, CountryCode |
|---|
| 13 | |
|---|
| 14 | ACCESS = [ |
|---|
| 15 | ('public', 'Public'), |
|---|
| 16 | ('private', 'Private'), |
|---|
| 17 | ] |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | class InitialTrialForm(forms.Form): |
|---|
| 21 | def __init__(self, *args, **kwargs): |
|---|
| 22 | self.user = kwargs.pop('user', None) |
|---|
| 23 | super(InitialTrialForm, self).__init__(*args, **kwargs) |
|---|
| 24 | if self.user: |
|---|
| 25 | self.fields['language'] = forms.ChoiceField(label=_('Submission language'), |
|---|
| 26 | choices=settings.MANAGED_LANGUAGES_CHOICES, initial=self.user.get_profile().preferred_language) |
|---|
| 27 | |
|---|
| 28 | form_title = _('Initial Trial Data') |
|---|
| 29 | scientific_title = forms.CharField(widget=forms.Textarea, |
|---|
| 30 | label=_('Scientific Title'), |
|---|
| 31 | max_length=2000) |
|---|
| 32 | recruitment_country = forms.MultipleChoiceField( |
|---|
| 33 | label=_('Recruitment country'), |
|---|
| 34 | choices=((cc.pk,cc.description) for cc in CountryCode.objects.iterator())) |
|---|
| 35 | language = forms.ChoiceField(label=_('Submission language'), |
|---|
| 36 | choices=settings.MANAGED_LANGUAGES_CHOICES) |
|---|
| 37 | |
|---|
| 38 | class PrimarySponsorForm(forms.ModelForm): |
|---|
| 39 | class Meta: |
|---|
| 40 | model = Institution |
|---|
| 41 | exclude = ['address'] |
|---|
| 42 | form_title = _('Primary Sponsor') |
|---|
| 43 | |
|---|
| 44 | class ExistingAttachmentForm(forms.ModelForm): |
|---|
| 45 | class Meta: |
|---|
| 46 | model = Attachment |
|---|
| 47 | exclude = ['submission'] |
|---|
| 48 | |
|---|
| 49 | title = _('Existing Attachment') |
|---|
| 50 | file = forms.CharField(required=False,label=_('File'),max_length=255) |
|---|
| 51 | |
|---|
| 52 | class NewAttachmentForm(ReviewModelForm): |
|---|
| 53 | class Meta: |
|---|
| 54 | model = Attachment |
|---|
| 55 | fields = ['file','description','public'] |
|---|
| 56 | |
|---|
| 57 | title = _('New Attachment') |
|---|
| 58 | |
|---|
| 59 | class UserForm(forms.ModelForm): |
|---|
| 60 | def clean_email(self): |
|---|
| 61 | """ |
|---|
| 62 | Validate that the supplied email address is unique for the |
|---|
| 63 | site. |
|---|
| 64 | |
|---|
| 65 | """ |
|---|
| 66 | if self.cleaned_data['email'] != self.instance.email: |
|---|
| 67 | if User.objects.filter(email__iexact=self.cleaned_data['email']): |
|---|
| 68 | raise forms.ValidationError(_("This email address is already in use. Please supply a different email address.")) |
|---|
| 69 | return self.cleaned_data['email'] |
|---|
| 70 | |
|---|
| 71 | class Meta: |
|---|
| 72 | model = User |
|---|
| 73 | fields = ['first_name','last_name','email'] |
|---|
| 74 | |
|---|
| 75 | title = _('User Profile') |
|---|
| 76 | |
|---|
| 77 | class UserProfileForm(forms.ModelForm): |
|---|
| 78 | class Meta: |
|---|
| 79 | model = UserProfile |
|---|
| 80 | fields = ['preferred_language'] |
|---|
| 81 | |
|---|
| 82 | title = _('Aditional info for profile') |
|---|
| 83 | |
|---|
| 84 | class UploadTrial(forms.Form): |
|---|
| 85 | submission_xml = forms.CharField(widget=forms.FileInput,required=True) |
|---|
| 86 | |
|---|
| 87 | class OpenRemarkForm(forms.ModelForm): |
|---|
| 88 | class Meta: |
|---|
| 89 | model = Remark |
|---|
| 90 | exclude = ['submission','context','status'] |
|---|
| 91 | |
|---|
| 92 | title = _('Open Remark') |
|---|
| 93 | |
|---|
| 94 | class ContactForm(forms.Form): |
|---|
| 95 | name = forms.CharField(label=_("Name"), max_length=50) |
|---|
| 96 | from_email = forms.EmailField(label=_("E-mail")) |
|---|
| 97 | subject = forms.CharField(label=_("Subject"), max_length=50) |
|---|
| 98 | message = forms.CharField(label=_("Message"), widget=forms.Textarea) |
|---|