Revision 8fb8d0cf snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
323 | 323 |
self.fields[f].widget.attrs['readonly'] = True |
324 | 324 |
|
325 | 325 |
def save(self, commit=True): |
326 |
user = super(InvitedThirdPartyUserCreationForm, self).save(commit=False) |
|
326 |
user = super( |
|
327 |
InvitedThirdPartyUserCreationForm, self).save(commit=False) |
|
327 | 328 |
user.set_invitation_level() |
328 | 329 |
user.email_verified = True |
329 | 330 |
if commit: |
... | ... | |
340 | 341 |
# copy email value to additional_mail in case user will change it |
341 | 342 |
name = 'email' |
342 | 343 |
field = self.fields[name] |
343 |
self.initial['additional_email'] = self.initial.get(name, field.initial) |
|
344 |
self.initial['additional_email'] = self.initial.get( |
|
345 |
name, field.initial) |
|
344 | 346 |
self.initial['email'] = None |
345 | 347 |
|
346 | 348 |
|
... | ... | |
359 | 361 |
was_limited = kwargs.get('was_limited', False) |
360 | 362 |
request = kwargs.get('request', None) |
361 | 363 |
if request: |
362 |
self.ip = request.META.get('REMOTE_ADDR', |
|
363 |
request.META.get('HTTP_X_REAL_IP', None)) |
|
364 |
self.ip = request.META.get( |
|
365 |
'REMOTE_ADDR', |
|
366 |
request.META.get('HTTP_X_REAL_IP', None)) |
|
364 | 367 |
|
365 | 368 |
t = ('request', 'was_limited') |
366 | 369 |
for elem in t: |
... | ... | |
431 | 434 |
Most of the fields are readonly since the user is not allowed to change |
432 | 435 |
them. |
433 | 436 |
|
434 |
The class defines a save method which sets ``is_verified`` to True so as the
|
|
435 |
user during the next login will not to be redirected to profile page. |
|
437 |
The class defines a save method which sets ``is_verified`` to True so as |
|
438 |
the user during the next login will not to be redirected to profile page.
|
|
436 | 439 |
""" |
437 |
email = forms.EmailField(label='E-mail address', help_text='E-mail address') |
|
440 |
email = forms.EmailField(label='E-mail address', |
|
441 |
help_text='E-mail address') |
|
438 | 442 |
renew = forms.BooleanField(label='Renew token', required=False) |
439 | 443 |
|
440 | 444 |
class Meta: |
... | ... | |
466 | 470 |
return user |
467 | 471 |
|
468 | 472 |
|
469 |
|
|
470 | 473 |
class FeedbackForm(forms.Form): |
471 | 474 |
""" |
472 | 475 |
Form for writing feedback. |
... | ... | |
517 | 520 |
raise forms.ValidationError(_(astakos_messages.EMAIL_UNKNOWN)) |
518 | 521 |
return email |
519 | 522 |
|
520 |
def save( |
|
521 |
self, domain_override=None, email_template_name='registration/password_reset_email.html', |
|
522 |
use_https=False, token_generator=default_token_generator, request=None): |
|
523 |
def save(self, domain_override=None, |
|
524 |
email_template_name='registration/password_reset_email.html', |
|
525 |
use_https=False, token_generator=default_token_generator, |
|
526 |
request=None): |
|
523 | 527 |
""" |
524 |
Generates a one-use only link for resetting password and sends to the user. |
|
528 |
Generates a one-use only link for resetting password and sends to the |
|
529 |
user. |
|
525 | 530 |
""" |
526 | 531 |
for user in self.users_cache: |
527 | 532 |
url = user.astakosuser.get_password_reset_url(token_generator) |
... | ... | |
555 | 560 |
raise forms.ValidationError(_(astakos_messages.EMAIL_USED)) |
556 | 561 |
return addr |
557 | 562 |
|
558 |
def save(self, request, email_template_name='registration/email_change_email.txt', commit=True): |
|
563 |
def save(self, request, |
|
564 |
email_template_name='registration/email_change_email.txt', |
|
565 |
commit=True): |
|
559 | 566 |
ec = super(EmailChangeForm, self).save(commit=False) |
560 | 567 |
ec.user = request.user |
561 | 568 |
# delete pending email changes |
... | ... | |
607 | 614 |
username = self.cleaned_data['username'] |
608 | 615 |
try: |
609 | 616 |
Invitation.objects.get(username=username) |
610 |
raise forms.ValidationError(_(astakos_messages.INVITATION_EMAIL_EXISTS)) |
|
617 |
raise forms.ValidationError( |
|
618 |
_(astakos_messages.INVITATION_EMAIL_EXISTS)) |
|
611 | 619 |
except Invitation.DoesNotExist: |
612 | 620 |
pass |
613 | 621 |
return username |
... | ... | |
619 | 627 |
to optionally renew also the token. |
620 | 628 |
""" |
621 | 629 |
if not settings.NEWPASSWD_INVALIDATE_TOKEN: |
622 |
renew = forms.BooleanField(label='Renew token', required=False, |
|
623 |
initial=True, |
|
624 |
help_text='Unsetting this may result in security risk.') |
|
630 |
renew = forms.BooleanField( |
|
631 |
label='Renew token', required=False, |
|
632 |
initial=True, |
|
633 |
help_text='Unsetting this may result in security risk.') |
|
625 | 634 |
|
626 | 635 |
def __init__(self, user, *args, **kwargs): |
627 | 636 |
self.session_key = kwargs.pop('session_key', None) |
... | ... | |
638 | 647 |
pass |
639 | 648 |
return super(ExtendedPasswordChangeForm, self).save(commit=commit) |
640 | 649 |
|
650 |
|
|
641 | 651 |
class ExtendedSetPasswordForm(SetPasswordForm): |
642 | 652 |
""" |
643 | 653 |
Extends SetPasswordForm by enabling user |
... | ... | |
670 | 680 |
return super(ExtendedSetPasswordForm, self).save(commit=commit) |
671 | 681 |
|
672 | 682 |
|
673 |
|
|
674 |
|
|
675 |
app_name_label = "Project name" |
|
683 |
app_name_label = "Project name" |
|
676 | 684 |
app_name_placeholder = _("myproject.mylab.ntua.gr") |
677 |
app_name_validator = validators.RegexValidator(
|
|
678 |
DOMAIN_VALUE_REGEX,
|
|
679 |
_(astakos_messages.DOMAIN_VALUE_ERR),
|
|
680 |
'invalid')
|
|
681 |
app_name_help = _("""
|
|
685 |
app_name_validator = validators.RegexValidator(
|
|
686 |
DOMAIN_VALUE_REGEX, |
|
687 |
_(astakos_messages.DOMAIN_VALUE_ERR), |
|
688 |
'invalid') |
|
689 |
app_name_help = _("""
|
|
682 | 690 |
The project's name should be in a domain format. |
683 | 691 |
The domain shouldn't neccessarily exist in the real |
684 | 692 |
world but is helpful to imply a structure. |
685 | 693 |
e.g.: myproject.mylab.ntua.gr or |
686 | 694 |
myservice.myteam.myorganization""") |
687 |
app_name_widget = forms.TextInput(
|
|
688 |
attrs={'placeholder': app_name_placeholder})
|
|
695 |
app_name_widget = forms.TextInput(
|
|
696 |
attrs={'placeholder': app_name_placeholder}) |
|
689 | 697 |
|
690 | 698 |
|
691 |
app_home_label = "Homepage URL"
|
|
692 |
app_home_placeholder = 'myinstitution.org/myproject/'
|
|
693 |
app_home_help = _("""
|
|
699 |
app_home_label = "Homepage URL"
|
|
700 |
app_home_placeholder = 'myinstitution.org/myproject/' |
|
701 |
app_home_help = _("""
|
|
694 | 702 |
URL pointing at your project's site. |
695 | 703 |
e.g.: myinstitution.org/myproject/. |
696 | 704 |
Leave blank if there is no website.""") |
697 |
app_home_widget = forms.TextInput(
|
|
698 |
attrs={'placeholder': app_home_placeholder})
|
|
705 |
app_home_widget = forms.TextInput(
|
|
706 |
attrs={'placeholder': app_home_placeholder}) |
|
699 | 707 |
|
700 |
app_desc_label = _("Description")
|
|
701 |
app_desc_help = _("""
|
|
708 |
app_desc_label = _("Description")
|
|
709 |
app_desc_help = _("""
|
|
702 | 710 |
Please provide a short but descriptive abstract of your |
703 | 711 |
project, so that anyone searching can quickly understand |
704 | 712 |
what this project is about.""") |
705 | 713 |
|
706 |
app_comment_label = _("Comments for review (private)")
|
|
707 |
app_comment_help = _("""
|
|
714 |
app_comment_label = _("Comments for review (private)")
|
|
715 |
app_comment_help = _("""
|
|
708 | 716 |
Write down any comments you may have for the reviewer |
709 | 717 |
of this application (e.g. background and rationale to |
710 | 718 |
support your request). |
711 | 719 |
The comments are strictly for the review process |
712 | 720 |
and will not be made public.""") |
713 | 721 |
|
714 |
app_start_date_label = _("Start date")
|
|
715 |
app_start_date_help = _("""
|
|
722 |
app_start_date_label = _("Start date") |
|
723 |
app_start_date_help = _("""
|
|
716 | 724 |
Provide a date when your need your project to be created, |
717 | 725 |
and members to be able to join and get resources. |
718 | 726 |
This date is only a hint to help prioritize reviews.""") |
719 | 727 |
|
720 |
app_end_date_label = _("Termination date")
|
|
721 |
app_end_date_help = _("""
|
|
728 |
app_end_date_label = _("Termination date")
|
|
729 |
app_end_date_help = _("""
|
|
722 | 730 |
At this date, the project will be automatically terminated |
723 | 731 |
and its resource grants revoked from all members. If you are |
724 | 732 |
not certain, it is best to start with a conservative estimation. |
725 | 733 |
You can always re-apply for an extension, if you need.""") |
726 | 734 |
|
727 |
join_policy_label = _("Joining policy")
|
|
728 |
app_member_join_policy_help = _("""
|
|
735 |
join_policy_label = _("Joining policy")
|
|
736 |
app_member_join_policy_help = _("""
|
|
729 | 737 |
Select how new members are accepted into the project.""") |
730 |
leave_policy_label = _("Leaving policy")
|
|
731 |
app_member_leave_policy_help = _("""
|
|
738 |
leave_policy_label = _("Leaving policy")
|
|
739 |
app_member_leave_policy_help = _("""
|
|
732 | 740 |
Select how new members can leave the project.""") |
733 | 741 |
|
734 |
max_members_label = _("Maximum member count")
|
|
735 |
max_members_help = _("""
|
|
742 |
max_members_label = _("Maximum member count")
|
|
743 |
max_members_help = _("""
|
|
736 | 744 |
Specify the maximum number of members this project may have, |
737 | 745 |
including the owner. Beyond this number, no new members |
738 | 746 |
may join the project and be granted the project resources. |
... | ... | |
742 | 750 |
join_policies = presentation.PROJECT_MEMBER_JOIN_POLICIES.items() |
743 | 751 |
leave_policies = presentation.PROJECT_MEMBER_LEAVE_POLICIES.items() |
744 | 752 |
|
753 |
|
|
745 | 754 |
class ProjectApplicationForm(forms.ModelForm): |
746 | 755 |
|
747 | 756 |
name = forms.CharField( |
748 |
label = app_name_label,
|
|
749 |
help_text = app_name_help,
|
|
750 |
widget = app_name_widget,
|
|
751 |
validators = [app_name_validator])
|
|
757 |
label=app_name_label,
|
|
758 |
help_text=app_name_help,
|
|
759 |
widget=app_name_widget,
|
|
760 |
validators=[app_name_validator])
|
|
752 | 761 |
|
753 | 762 |
homepage = forms.URLField( |
754 |
label = app_home_label,
|
|
755 |
help_text = app_home_help,
|
|
756 |
widget = app_home_widget,
|
|
757 |
required = False)
|
|
763 |
label=app_home_label,
|
|
764 |
help_text=app_home_help,
|
|
765 |
widget=app_home_widget,
|
|
766 |
required=False)
|
|
758 | 767 |
|
759 | 768 |
description = forms.CharField( |
760 |
label = app_desc_label,
|
|
761 |
help_text = app_desc_help,
|
|
762 |
widget = forms.Textarea,
|
|
763 |
required = False)
|
|
769 |
label=app_desc_label,
|
|
770 |
help_text=app_desc_help,
|
|
771 |
widget=forms.Textarea,
|
|
772 |
required=False)
|
|
764 | 773 |
|
765 | 774 |
comments = forms.CharField( |
766 |
label = app_comment_label,
|
|
767 |
help_text = app_comment_help,
|
|
768 |
widget = forms.Textarea,
|
|
769 |
required = False)
|
|
775 |
label=app_comment_label,
|
|
776 |
help_text=app_comment_help,
|
|
777 |
widget=forms.Textarea,
|
|
778 |
required=False)
|
|
770 | 779 |
|
771 | 780 |
start_date = forms.DateTimeField( |
772 |
label = app_start_date_label,
|
|
773 |
help_text = app_start_date_help,
|
|
774 |
required = False)
|
|
781 |
label=app_start_date_label,
|
|
782 |
help_text=app_start_date_help,
|
|
783 |
required=False)
|
|
775 | 784 |
|
776 | 785 |
end_date = forms.DateTimeField( |
777 |
label = app_end_date_label,
|
|
778 |
help_text = app_end_date_help)
|
|
786 |
label=app_end_date_label,
|
|
787 |
help_text=app_end_date_help)
|
|
779 | 788 |
|
780 |
member_join_policy = forms.TypedChoiceField(
|
|
781 |
label = join_policy_label,
|
|
782 |
help_text = app_member_join_policy_help,
|
|
783 |
initial = 2,
|
|
784 |
coerce = int,
|
|
785 |
choices = join_policies)
|
|
789 |
member_join_policy = forms.TypedChoiceField( |
|
790 |
label=join_policy_label,
|
|
791 |
help_text=app_member_join_policy_help,
|
|
792 |
initial=2,
|
|
793 |
coerce=int,
|
|
794 |
choices=join_policies)
|
|
786 | 795 |
|
787 | 796 |
member_leave_policy = forms.TypedChoiceField( |
788 |
label = leave_policy_label,
|
|
789 |
help_text = app_member_leave_policy_help,
|
|
790 |
coerce = int,
|
|
791 |
choices = leave_policies)
|
|
797 |
label=leave_policy_label,
|
|
798 |
help_text=app_member_leave_policy_help,
|
|
799 |
coerce=int,
|
|
800 |
choices=leave_policies)
|
|
792 | 801 |
|
793 | 802 |
limit_on_members_number = forms.IntegerField( |
794 |
label = max_members_label,
|
|
795 |
help_text = max_members_help,
|
|
796 |
min_value = 0,
|
|
797 |
required = False)
|
|
803 |
label=max_members_label,
|
|
804 |
help_text=max_members_help,
|
|
805 |
min_value=0,
|
|
806 |
required=False)
|
|
798 | 807 |
|
799 | 808 |
class Meta: |
800 | 809 |
model = ProjectApplication |
801 |
fields = ( 'name', 'homepage', 'description',
|
|
802 |
'start_date', 'end_date', 'comments',
|
|
803 |
'member_join_policy', 'member_leave_policy',
|
|
804 |
'limit_on_members_number')
|
|
810 |
fields = ('name', 'homepage', 'description', |
|
811 |
'start_date', 'end_date', 'comments', |
|
812 |
'member_join_policy', 'member_leave_policy', |
|
813 |
'limit_on_members_number') |
|
805 | 814 |
|
806 | 815 |
def __init__(self, *args, **kwargs): |
807 | 816 |
instance = kwargs.get('instance') |
... | ... | |
820 | 829 |
today = datetime(today.year, today.month, today.day) |
821 | 830 |
if start_date and (start_date - today).days < 0: |
822 | 831 |
raise forms.ValidationError( |
823 |
_(astakos_messages.INVALID_PROJECT_START_DATE)) |
|
832 |
_(astakos_messages.INVALID_PROJECT_START_DATE))
|
|
824 | 833 |
return start_date |
825 | 834 |
|
826 | 835 |
def clean_end_date(self): |
... | ... | |
867 | 876 |
raise forms.ValidationError("Resource %s does not exist" % |
868 | 877 |
resource.name) |
869 | 878 |
# keep only resource limits for selected resource groups |
870 |
if self.data.get( |
|
871 |
'is_selected_%s' % resource.group, "0" |
|
872 |
) == "1": |
|
879 |
if self.data.get('is_selected_%s' % |
|
880 |
resource.group, "0") == "1": |
|
873 | 881 |
if not resource.allow_in_projects: |
874 | 882 |
raise forms.ValidationError("Invalid resource %s" % |
875 | 883 |
resource.name) |
... | ... | |
881 | 889 |
append(d) |
882 | 890 |
|
883 | 891 |
ordered_keys = presentation.RESOURCES['resources_order'] |
892 |
|
|
884 | 893 |
def resource_order(r): |
885 | 894 |
if r['str_repr'] in ordered_keys: |
886 | 895 |
return ordered_keys.index(r['str_repr']) |
... | ... | |
910 | 919 |
('issue_date', 'Sort by Issue date'), |
911 | 920 |
('start_date', 'Sort by Start Date'), |
912 | 921 |
('end_date', 'Sort by End Date'), |
913 |
# ('approved_members_num', 'Sort by Participants'),
|
|
922 |
# ('approved_members_num', 'Sort by Participants'),
|
|
914 | 923 |
('state', 'Sort by Status'), |
915 |
('member_join_policy__description', 'Sort by Member Join Policy'), |
|
916 |
('member_leave_policy__description', 'Sort by Member Leave Policy'), |
|
924 |
('member_join_policy__description', |
|
925 |
'Sort by Member Join Policy'), |
|
926 |
('member_leave_policy__description', |
|
927 |
'Sort by Member Leave Policy'), |
|
917 | 928 |
('-name', 'Sort by Name'), |
918 | 929 |
('-issue_date', 'Sort by Issue date'), |
919 | 930 |
('-start_date', 'Sort by Start Date'), |
920 | 931 |
('-end_date', 'Sort by End Date'), |
921 |
# ('-approved_members_num', 'Sort by Participants'),
|
|
932 |
# ('-approved_members_num', 'Sort by Participants'),
|
|
922 | 933 |
('-state', 'Sort by Status'), |
923 |
('-member_join_policy__description', 'Sort by Member Join Policy'), |
|
924 |
('-member_leave_policy__description', 'Sort by Member Leave Policy') |
|
925 |
), |
|
934 |
('-member_join_policy__description', |
|
935 |
'Sort by Member Join Policy'), |
|
936 |
('-member_leave_policy__description', |
|
937 |
'Sort by Member Leave Policy') |
|
938 |
), |
|
926 | 939 |
required=True |
927 | 940 |
) |
928 | 941 |
|
942 |
|
|
929 | 943 |
class AddProjectMembersForm(forms.Form): |
930 | 944 |
q = forms.CharField( |
931 |
widget=forms.Textarea(attrs={ |
|
932 |
'placeholder': astakos_messages.ADD_PROJECT_MEMBERS_Q_PLACEHOLDER} |
|
933 |
), |
|
945 |
widget=forms.Textarea( |
|
946 |
attrs={ |
|
947 |
'placeholder': |
|
948 |
astakos_messages.ADD_PROJECT_MEMBERS_Q_PLACEHOLDER}), |
|
934 | 949 |
label=_('Add members'), |
935 | 950 |
help_text=_(astakos_messages.ADD_PROJECT_MEMBERS_Q_HELP), |
936 | 951 |
required=True,) |
... | ... | |
966 | 981 |
except: |
967 | 982 |
return () |
968 | 983 |
|
984 |
|
|
969 | 985 |
class ProjectMembersSortForm(forms.Form): |
970 | 986 |
sorting = forms.ChoiceField( |
971 | 987 |
label='Sort by', |
972 | 988 |
choices=(('person__email', 'User Id'), |
973 | 989 |
('person__first_name', 'Name'), |
974 | 990 |
('acceptance_date', 'Acceptance date') |
975 |
), |
|
991 |
),
|
|
976 | 992 |
required=True |
977 | 993 |
) |
978 | 994 |
|
... | ... | |
1009 | 1025 |
def __init__(self, *args, **kwargs): |
1010 | 1026 |
session_key = kwargs.get('session_key', None) |
1011 | 1027 |
self.fields_list = [ |
1012 |
'email',
|
|
1013 |
'new_email_address',
|
|
1014 |
'first_name',
|
|
1015 |
'last_name',
|
|
1016 |
'old_password',
|
|
1017 |
'new_password1',
|
|
1018 |
'new_password2',
|
|
1019 |
'change_email',
|
|
1020 |
'change_password',
|
|
1028 |
'email', |
|
1029 |
'new_email_address', |
|
1030 |
'first_name', |
|
1031 |
'last_name', |
|
1032 |
'old_password', |
|
1033 |
'new_password1', |
|
1034 |
'new_password2', |
|
1035 |
'change_email', |
|
1036 |
'change_password', |
|
1021 | 1037 |
] |
1022 | 1038 |
|
1023 | 1039 |
super(ExtendedProfileForm, self).__init__(*args, **kwargs) |
... | ... | |
1043 | 1059 |
self.success_messages = [] |
1044 | 1060 |
self.fields.keyOrder = self.fields_list |
1045 | 1061 |
|
1046 |
|
|
1047 | 1062 |
def _init_extra_form_fields(self): |
1048 | 1063 |
if self.email_change: |
1049 | 1064 |
self.fields.update(self.email_change_form.fields) |
1050 | 1065 |
self.fields['new_email_address'].required = False |
1051 |
self.fields['email'].help_text = _('Change the email associated with ' |
|
1052 |
'your account. This email will ' |
|
1053 |
'remain active until you verify ' |
|
1054 |
'your new one.') |
|
1066 |
self.fields['email'].help_text = _( |
|
1067 |
'Change the email associated with ' |
|
1068 |
'your account. This email will ' |
|
1069 |
'remain active until you verify ' |
|
1070 |
'your new one.') |
|
1055 | 1071 |
|
1056 | 1072 |
if self.password_change: |
1057 | 1073 |
self.fields.update(self.password_change_form.fields) |
... | ... | |
1070 | 1086 |
|
1071 | 1087 |
def _init_extra_forms(self): |
1072 | 1088 |
self.email_change_form = EmailChangeForm(self.data) |
1073 |
self.password_change_form = ExtendedPasswordChangeForm(user=self.instance, |
|
1074 |
data=self.data, session_key=self.session_key) |
|
1089 |
self.password_change_form = ExtendedPasswordChangeForm( |
|
1090 |
user=self.instance, |
|
1091 |
data=self.data, session_key=self.session_key) |
|
1075 | 1092 |
self._init_extra_form_fields() |
1076 | 1093 |
|
1077 | 1094 |
def is_valid(self): |
... | ... | |
1099 | 1116 |
self.password_change_form.save(*args, **kwargs) |
1100 | 1117 |
self.password_changed = True |
1101 | 1118 |
return super(ExtendedProfileForm, self).save(*args, **kwargs) |
1102 |
|
Also available in: Unified diff