Revision dd5f8f4d snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
468 | 468 |
|
469 | 469 |
class ExtendedPasswordResetForm(PasswordResetForm): |
470 | 470 |
""" |
471 |
Extends PasswordResetForm by overriding save method: |
|
472 |
passes a custom from_email in send_mail. |
|
471 |
Extends PasswordResetForm by overriding |
|
473 | 472 |
|
474 |
Since Django 1.3 this is useless since ``django.contrib.auth.views.reset_password``
|
|
475 |
accepts a from_email argument.
|
|
473 |
save method: to pass a custom from_email in send_mail.
|
|
474 |
clean_email: to handle local auth provider checks
|
|
476 | 475 |
""" |
477 | 476 |
def clean_email(self): |
478 | 477 |
email = super(ExtendedPasswordResetForm, self).clean_email() |
479 | 478 |
try: |
480 |
user = AstakosUser.objects.get(email__iexact=email) |
|
479 |
user = AstakosUser.objects.get_by_identifier(email) |
|
480 |
|
|
481 |
if not user.is_active: |
|
482 |
raise forms.ValidationError(_(astakos_messages.ACCOUNT_INACTIVE)) |
|
483 |
|
|
481 | 484 |
if not user.has_usable_password(): |
482 | 485 |
raise forms.ValidationError(_(astakos_messages.UNUSABLE_PASSWORD)) |
483 | 486 |
|
484 | 487 |
if not user.can_change_password(): |
485 |
raise forms.ValidationError(_('Password change for this account' |
|
486 |
' is not supported.')) |
|
487 |
|
|
488 |
raise forms.ValidationError(_(astakos_messages.AUTH_PROVIDER_CANNOT_CHANGE_PASSWORD)) |
|
488 | 489 |
except AstakosUser.DoesNotExist, e: |
489 | 490 |
raise forms.ValidationError(_(astakos_messages.EMAIL_UNKNOWN)) |
490 | 491 |
return email |
... | ... | |
619 | 620 |
# ) |
620 | 621 |
# desc = forms.CharField( |
621 | 622 |
# label= 'Description', |
622 |
# widget=forms.Textarea,
|
|
623 |
# widget=forms.Textarea, |
|
623 | 624 |
# help_text= "Please provide a short but descriptive abstract of your Project, so that anyone searching can quickly understand what this Project is about. " |
624 | 625 |
# ) |
625 | 626 |
# issue_date = forms.DateTimeField( |
... | ... | |
641 | 642 |
# required=True, min_value=1, |
642 | 643 |
# help_text="Here you specify the number of members this Project is going to have. This means that this number of people will be granted the resources you will specify in the next step. This can be '1' if you are the only one wanting to get resources. " |
643 | 644 |
# ) |
644 |
#
|
|
645 |
# |
|
645 | 646 |
# class Meta: |
646 | 647 |
# model = AstakosGroup |
647 |
#
|
|
648 |
# |
|
648 | 649 |
# def __init__(self, *args, **kwargs): |
649 | 650 |
# #update QueryDict |
650 | 651 |
# args = list(args) |
651 | 652 |
# qd = args.pop(0).copy() |
652 | 653 |
# members_unlimited = qd.pop('members_unlimited', False) |
653 | 654 |
# members_uplimit = qd.pop('members_uplimit', None) |
654 |
#
|
|
655 |
# |
|
655 | 656 |
# #substitue QueryDict |
656 | 657 |
# args.insert(0, qd) |
657 |
#
|
|
658 |
# |
|
658 | 659 |
# super(AstakosGroupCreationForm, self).__init__(*args, **kwargs) |
659 |
#
|
|
660 |
# |
|
660 | 661 |
# self.fields.keyOrder = ['kind', 'name', 'homepage', 'desc', |
661 | 662 |
# 'issue_date', 'expiration_date', |
662 | 663 |
# 'moderation_enabled', 'max_participants'] |
... | ... | |
670 | 671 |
# map(add_fields, |
671 | 672 |
# ((k, v) for k,v in qd.iteritems() if k.endswith('_uplimit')) |
672 | 673 |
# ) |
673 |
#
|
|
674 |
# |
|
674 | 675 |
# def add_fields((k, v)): |
675 | 676 |
# self.fields[k] = forms.BooleanField( |
676 | 677 |
# required=False, |
... | ... | |
679 | 680 |
# map(add_fields, |
680 | 681 |
# ((k, v) for k,v in qd.iteritems() if k.startswith('is_selected_')) |
681 | 682 |
# ) |
682 |
#
|
|
683 |
# |
|
683 | 684 |
# def policies(self): |
684 | 685 |
# self.clean() |
685 | 686 |
# policies = [] |
686 | 687 |
# append = policies.append |
687 | 688 |
# for name, uplimit in self.cleaned_data.iteritems(): |
688 |
#
|
|
689 |
# |
|
689 | 690 |
# subs = name.split('_uplimit') |
690 | 691 |
# if len(subs) == 2: |
691 | 692 |
# prefix, suffix = subs |
692 | 693 |
# s, sep, r = prefix.partition(RESOURCE_SEPARATOR) |
693 | 694 |
# resource = Resource.objects.get(service__name=s, name=r) |
694 |
#
|
|
695 |
# |
|
695 | 696 |
# # keep only resource limits for selected resource groups |
696 | 697 |
# if self.cleaned_data.get( |
697 | 698 |
# 'is_selected_%s' % resource.group, False |
698 | 699 |
# ): |
699 | 700 |
# append(dict(service=s, resource=r, uplimit=uplimit)) |
700 | 701 |
# return policies |
701 |
#
|
|
702 |
# |
|
702 | 703 |
# class AstakosGroupCreationSummaryForm(forms.ModelForm): |
703 | 704 |
# kind = forms.ModelChoiceField( |
704 | 705 |
# queryset=GroupKind.objects.all(), |
... | ... | |
717 | 718 |
# max_participants = forms.IntegerField( |
718 | 719 |
# required=False, min_value=1 |
719 | 720 |
# ) |
720 |
#
|
|
721 |
# |
|
721 | 722 |
# class Meta: |
722 | 723 |
# model = AstakosGroup |
723 |
#
|
|
724 |
# |
|
724 | 725 |
# def __init__(self, *args, **kwargs): |
725 | 726 |
# #update QueryDict |
726 | 727 |
# args = list(args) |
727 | 728 |
# qd = args.pop(0).copy() |
728 | 729 |
# members_unlimited = qd.pop('members_unlimited', False) |
729 | 730 |
# members_uplimit = qd.pop('members_uplimit', None) |
730 |
#
|
|
731 |
# |
|
731 | 732 |
# #substitue QueryDict |
732 | 733 |
# args.insert(0, qd) |
733 |
#
|
|
734 |
# |
|
734 | 735 |
# super(AstakosGroupCreationSummaryForm, self).__init__(*args, **kwargs) |
735 | 736 |
# self.fields.keyOrder = ['kind', 'name', 'homepage', 'desc', |
736 | 737 |
# 'issue_date', 'expiration_date', |
... | ... | |
744 | 745 |
# map(add_fields, |
745 | 746 |
# ((k, v) for k,v in qd.iteritems() if k.endswith('_uplimit')) |
746 | 747 |
# ) |
747 |
#
|
|
748 |
# |
|
748 | 749 |
# def add_fields((k, v)): |
749 | 750 |
# self.fields[k] = forms.BooleanField( |
750 | 751 |
# required=False, |
... | ... | |
755 | 756 |
# ) |
756 | 757 |
# for f in self.fields.values(): |
757 | 758 |
# f.widget = forms.HiddenInput() |
758 |
#
|
|
759 |
# |
|
759 | 760 |
# def clean(self): |
760 | 761 |
# super(AstakosGroupCreationSummaryForm, self).clean() |
761 | 762 |
# self.cleaned_data['policies'] = [] |
... | ... | |
769 | 770 |
# prefix, suffix = subs |
770 | 771 |
# s, sep, r = prefix.partition(RESOURCE_SEPARATOR) |
771 | 772 |
# resource = Resource.objects.get(service__name=s, name=r) |
772 |
#
|
|
773 |
# |
|
773 | 774 |
# # keep only resource limits for selected resource groups |
774 | 775 |
# if self.cleaned_data.get( |
775 | 776 |
# 'is_selected_%s' % resource.group, False |
... | ... | |
778 | 779 |
# for name in tbd: |
779 | 780 |
# self.cleaned_data.pop(name, None) |
780 | 781 |
# return self.cleaned_data |
781 |
#
|
|
782 |
# |
|
782 | 783 |
# class AstakosGroupUpdateForm(forms.ModelForm): |
783 | 784 |
# class Meta: |
784 | 785 |
# model = AstakosGroup |
785 | 786 |
# fields = ( 'desc','homepage', 'moderation_enabled') |
786 |
#
|
|
787 |
#
|
|
787 |
# |
|
788 |
# |
|
788 | 789 |
# class AddGroupMembersForm(forms.Form): |
789 | 790 |
# q = forms.CharField( |
790 | 791 |
# max_length=800, widget=forms.Textarea, label=_('Add members'), |
791 | 792 |
# help_text=_(astakos_messages.ADD_GROUP_MEMBERS_Q_HELP), |
792 | 793 |
# required=True) |
793 |
#
|
|
794 |
# |
|
794 | 795 |
# def clean(self): |
795 | 796 |
# q = self.cleaned_data.get('q') or '' |
796 | 797 |
# users = q.split(',') |
... | ... | |
801 | 802 |
# raise forms.ValidationError(_(astakos_messages.UNKNOWN_USERS) % ','.join(unknown)) |
802 | 803 |
# self.valid_users = db_entries |
803 | 804 |
# return self.cleaned_data |
804 |
#
|
|
805 |
# |
|
805 | 806 |
# def get_valid_users(self): |
806 | 807 |
# """Should be called after form cleaning""" |
807 | 808 |
# try: |
808 | 809 |
# return self.valid_users |
809 | 810 |
# except: |
810 | 811 |
# return () |
811 |
#
|
|
812 |
#
|
|
812 |
# |
|
813 |
# |
|
813 | 814 |
# class AstakosGroupSearchForm(forms.Form): |
814 | 815 |
# q = forms.CharField(max_length=200, label='Search project') |
815 |
#
|
|
816 |
#
|
|
816 |
# |
|
817 |
# |
|
817 | 818 |
# class TimelineForm(forms.Form): |
818 | 819 |
# entity = forms.ModelChoiceField( |
819 | 820 |
# queryset=AstakosUser.objects.filter(is_active=True) |
... | ... | |
830 | 831 |
# ('charge_usage', 'Charge Usage'), |
831 | 832 |
# ('charge_traffic', 'Charge Traffic'), ) |
832 | 833 |
# ) |
833 |
#
|
|
834 |
# |
|
834 | 835 |
# def clean(self): |
835 | 836 |
# super(TimelineForm, self).clean() |
836 | 837 |
# d = self.cleaned_data |
... | ... | |
844 | 845 |
# if 'entity' in d: |
845 | 846 |
# d['entity'] = d['entity'].email |
846 | 847 |
# return d |
847 |
#
|
|
848 |
#
|
|
848 |
# |
|
849 |
# |
|
849 | 850 |
# class AstakosGroupSortForm(forms.Form): |
850 | 851 |
# sorting = forms.ChoiceField( |
851 | 852 |
# label='Sort by', |
... | ... | |
859 | 860 |
# ), |
860 | 861 |
# required=True |
861 | 862 |
# ) |
862 |
#
|
|
863 |
# |
|
863 | 864 |
# class MembersSortForm(forms.Form): |
864 | 865 |
# sorting = forms.ChoiceField( |
865 | 866 |
# label='Sort by', |
... | ... | |
869 | 870 |
# ), |
870 | 871 |
# required=True |
871 | 872 |
# ) |
872 |
#
|
|
873 |
# |
|
873 | 874 |
# class PickResourceForm(forms.Form): |
874 | 875 |
# resource = forms.ModelChoiceField( |
875 | 876 |
# queryset=Resource.objects.select_related().all() |
... | ... | |
920 | 921 |
homepage = forms.URLField( |
921 | 922 |
help_text="This should be a URL pointing at your project's site. e.g.: http://myproject.com ", |
922 | 923 |
widget=forms.TextInput(attrs={'placeholder': 'http://myproject.com'}), |
923 |
|
|
924 |
|
|
924 | 925 |
required=False |
925 | 926 |
) |
926 | 927 |
comments = forms.CharField(widget=forms.Textarea, required=False) |
927 |
|
|
928 |
|
|
928 | 929 |
class Meta: |
929 | 930 |
model = ProjectApplication |
930 | 931 |
exclude = ( |
... | ... | |
935 | 936 |
def __init__(self, *args, **kwargs): |
936 | 937 |
self.precursor_application = kwargs.get('instance') |
937 | 938 |
super(ProjectApplicationForm, self).__init__(*args, **kwargs) |
938 |
|
|
939 |
|
|
939 | 940 |
def clean(self): |
940 | 941 |
userid = self.data.get('user', None) |
941 | 942 |
self.user = None |
... | ... | |
948 | 949 |
raise forms.ValidationError(_(astakos_messages.NO_APPLICANT)) |
949 | 950 |
super(ProjectApplicationForm, self).clean() |
950 | 951 |
return self.cleaned_data |
951 |
|
|
952 |
|
|
952 | 953 |
@property |
953 | 954 |
def resource_policies(self): |
954 | 955 |
policies = [] |
... | ... | |
971 | 972 |
append(dict(service=s, resource=r, uplimit=uplimit)) |
972 | 973 |
else: |
973 | 974 |
append(dict(service=s, resource=r, uplimit=None)) |
974 |
|
|
975 |
|
|
975 | 976 |
return policies |
976 |
|
|
977 |
|
|
977 | 978 |
|
978 | 979 |
def save(self, commit=True): |
979 | 980 |
application = super(ProjectApplicationForm, self).save(commit=False) |
Also available in: Unified diff