Beispiel #1
0
    def form_valid(self, form):
        user_obj = form.save()
        assign_perm('institutions.is_institute', user_obj)
        user_obj.save()
        institution_obj = Institutions()

        institution_obj.user = user_obj
        institution_obj.institute_name = self.request.POST['institute_name']
        institution_obj.institute_address = self.request.POST['institute_address']
        institution_obj.institute_city = self.request.POST['institute_city']
        institution_obj.institute_state = self.request.POST['institute_state']
        institution_obj.institute_country = self.request.POST['institute_country']
        institution_obj.institute_contact_mobile = self.request.POST['institute_contact_mobile']
        institution_obj.institute_contact_landline = self.request.POST['institute_contact_landline']
        
        license_obj = License()
        institution_obj.save()
        
        license_obj.li_institute = institution_obj
        license_obj.li_key = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16))
        license_obj.li_expiration_date = datetime.now() + timedelta(days=10*365)
        license_obj.li_max_staff = 50
        license_obj.li_max_students = 500
        license_obj.li_max_assesments = 1000
        license_obj.li_current_status = 'acti'
        
        license_obj.save()
        
        messages.add_message(self.request, messages.SUCCESS, 'Your Account Registered Successfully')
        return HttpResponseRedirect(self.get_success_url())
Beispiel #2
0
    def form_valid(self, form):
        user_obj = form.save()
        assign_perm('institutions.is_institute', user_obj)
        user_obj.save()
        institution_obj = Institutions()

        institution_obj.user = user_obj
        institution_obj.institute_name = self.request.POST['institute_name']
        institution_obj.institute_address = self.request.POST[
            'institute_address']
        institution_obj.institute_city = self.request.POST['institute_city']
        institution_obj.institute_state = self.request.POST['institute_state']
        institution_obj.institute_country = self.request.POST[
            'institute_country']
        institution_obj.institute_contact_mobile = self.request.POST[
            'institute_contact_mobile']
        institution_obj.institute_contact_landline = self.request.POST[
            'institute_contact_landline']

        license_obj = License()
        institution_obj.save()

        license_obj.li_institute = institution_obj
        license_obj.li_key = ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=16))
        license_obj.li_expiration_date = datetime.now() + timedelta(days=10 *
                                                                    365)
        license_obj.li_max_staff = 50
        license_obj.li_max_students = 500
        license_obj.li_max_assesments = 1000
        license_obj.li_current_status = 'acti'

        license_obj.save()

        #Register Institute as first user:

        user_obj.refresh_from_db(
        )  # This will load the Profile created by the Signal
        assign_perm('staff.is_staff', user_obj)
        profile_form = Staff(
        )  # Reload the profile form with the profile instance
        profile_form.institute = user_obj.institutions
        profile_form.staffuser = user_obj
        profile_form.full_clean(
        )  # Manually clean the form this time. It is implicitly called by "is_valid()" method
        license_obj.li_current_staff += 1
        license_obj.save()
        profile_form.save()  # Gracefully save the form

        messages.add_message(self.request, messages.SUCCESS,
                             'Your Account Registered Successfully')
        return HttpResponseRedirect(self.get_success_url())