Beispiel #1
0
    def get(self, request):
        user = request.user

        forms_context_dict = {}
        form_class_context_key_user_field_tuples = [
            [InstituteAddressForm, 'insti_address_form', ('insti_address',)],
            [ProgramForm, 'program_form', ('program',)],
            [SexUpdateForm, 'sex_update_form', ('userprofile', 'sex',)],
        ]

        for form_class, context_key, user_attr in form_class_context_key_user_field_tuples:
            try:
                form = form_class(initial=attr_to_dict(get_attribute(user, user_attr), key=user_attr[-1]))
            except (AttributeError, ObjectDoesNotExist):
                form = form_class()
            forms_context_dict[context_key] = form

        mobile_numbers = ContactNumber.objects.all().filter(user=user).order_by('-id')
        secondary_emails = SecondaryEmail.objects.all().filter(user=user).order_by('-id')
        user_profile = user.userprofile
        gpo_email = user.email
        ldap_number = user_profile.mobile
        roll_number = user_profile.roll_number

        request_context = {
            'mobile_numbers': mobile_numbers,
            'secondary_emails': secondary_emails,
            'gpo_email': gpo_email,
            'ldap_number': ldap_number,
            'roll_number': roll_number,
            'user_profile_picture': model_field_media_url(user.userprofile.profile_picture),
        }
        request_context.update(forms_context_dict)

        return render(request, 'user_resources/home.html', request_context)
Beispiel #2
0
    def get(self, request):
        user = request.user

        forms_context_dict = {}
        form_class_context_key_user_field_tuples = [
            [InstituteAddressForm, 'insti_address_form', ('insti_address', )],
            [ProgramForm, 'program_form', ('program', )],
            [SexUpdateForm, 'sex_update_form', (
                'userprofile',
                'sex',
            )],
        ]

        for form_class, context_key, user_attr in form_class_context_key_user_field_tuples:
            try:
                form = form_class(initial=attr_to_dict(
                    get_attribute(user, user_attr), key=user_attr[-1]))
            except (AttributeError, ObjectDoesNotExist):
                form = form_class()
            forms_context_dict[context_key] = form

        mobile_numbers = ContactNumber.objects.all().filter(
            user=user).order_by('-id')
        secondary_emails = SecondaryEmail.objects.all().filter(
            user=user).order_by('-id')
        user_profile = user.userprofile
        gpo_email = user.email
        ldap_number = user_profile.mobile
        roll_number = user_profile.roll_number

        request_context = {
            'mobile_numbers':
            mobile_numbers,
            'secondary_emails':
            secondary_emails,
            'gpo_email':
            gpo_email,
            'ldap_number':
            ldap_number,
            'roll_number':
            roll_number,
            'user_profile_picture':
            model_field_media_url(user.userprofile.profile_picture),
        }
        request_context.update(forms_context_dict)

        return render(request, 'user_resources/home.html', request_context)
Beispiel #3
0
 def get(self, request):
     user = request.user
     return self.render({'form': SexUpdateForm(initial=attr_to_dict(user.userprofile.sex, 'sex'))})
Beispiel #4
0
 def get(self, request):
     user = request.user
     return self.render({
         'form':
         SexUpdateForm(initial=attr_to_dict(user.userprofile.sex, 'sex'))
     })