root/trunk/opentrials/reviewapp/forms.py @ 503

Revision 503, 3.4 kB (checked in by luciano.ramalho, 3 years ago)

changed internal references to package clinicaltrials to opentrials; changed context_processor filename to opentrials.py

Line 
1# coding: utf-8
2
3from opentrials.repository.trds_forms import ReviewModelForm
4from opentrials.reviewapp.models import Remark
5from opentrials.reviewapp.models import UserProfile
6from opentrials.reviewapp.models import Attachment
7from django import forms
8from django.utils.translation import ugettext as _
9from django.contrib.auth.models import User
10from django.conf import settings
11
12from repository.models import Institution, CountryCode
13
14ACCESS = [
15    ('public', 'Public'),
16    ('private', 'Private'),
17]
18
19
20class 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   
38class PrimarySponsorForm(forms.ModelForm):
39    class Meta:
40        model = Institution
41        exclude = ['address']
42    form_title = _('Primary Sponsor')
43
44class 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
52class NewAttachmentForm(ReviewModelForm):
53    class Meta:
54        model = Attachment
55        fields = ['file','description','public']
56
57    title = _('New Attachment')
58   
59class 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
77class UserProfileForm(forms.ModelForm):
78    class Meta:
79        model = UserProfile
80        fields = ['preferred_language']
81
82    title = _('Aditional info for profile')
83
84class UploadTrial(forms.Form):
85    submission_xml = forms.CharField(widget=forms.FileInput,required=True)
86
87class OpenRemarkForm(forms.ModelForm):
88    class Meta:
89        model = Remark
90        exclude = ['submission','context','status']
91
92    title = _('Open Remark')
93   
94class 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)
Note: See TracBrowser for help on using the browser.