示例#1
0
    def setUp(self):
        self.tz = timezone('America/Denver')

        self.user = User.objects.create_user('tethys1', '*****@*****.**',
                                             'pass')

        self.social_auth = UserSocialAuth.create_social_auth(
            self.user, 'username', 'UITPlus')

        self.uitplusjob = UitPlusJob(
            name='uit_job',
            user=self.user,
            description='test_description',
            label='test_label',
            workspace='test_ws',
            node_type='compute',
            system='topaz',
            job_id='J0001',
            project_id='P001',
            num_nodes=10,
            processes_per_node=5,
            max_time=timedelta(hours=10, seconds=42),
            max_cleanup_time=timedelta(hours=10, seconds=60),
            job_script='PBSScript',
            transfer_input_files=['file1.xml', 'file10.xml'],
            archive_input_files=['file2.xml', 'file3.txt'],
            home_input_files=['file3.xml', 'file4.xml'],
            transfer_output_files=['transfer_out.out', 'transfer_out2.out'],
            archive_output_files=['archive_out.out', 'archive_out2.out'],
            home_output_files=['home.out', 'test_home.out'],
            _modules={'OpenGL': 'load'})

        self.uitplusjob.save()
示例#2
0
    def _post_save(sender, instance, **kwargs):
        original_instance = getattr(instance, "_original_instance") if hasattr(
            instance, "_original_instance") else None
        # add user's email to email identity and social auth if not exist
        if not instance.is_dummy_user:
            EmailIdentity.objects.get_or_create(email=instance.email,
                                                user=instance)
            if not UserSocialAuth.objects.filter(user=instance,
                                                 provider="email",
                                                 uid=instance.email).exists():
                user_social_auth = UserSocialAuth.create_social_auth(
                    instance, instance.email, 'email')
                user_social_auth.extra_data = {'email': [instance.email]}
                user_social_auth.save()

        if original_instance and original_instance.email != instance.email:
            if not original_instance.is_dummy_user:
                # delete the user's email from email identity and social auth
                EmailIdentity.objects.filter(email=original_instance.email,
                                             user=original_instance).delete()
                UserSocialAuth.objects.filter(provider="email",
                                              uid=original_instance.email,
                                              user=original_instance).delete()
            # update profile's email if profile's email is original email
            Profile.objects.filter(email=original_instance.email,
                                   user=instance).update(email=instance.email)

        if original_instance and any([
                original_instance.first_name != instance.first_name,
                original_instance.last_name != instance.last_name
        ]):
            # user changed first name or last name, send a named_changed signal.
            name_changed.send(sender=instance.__class__, user=instance)
示例#3
0
    def _post_save(sender, instance, **kwargs):
        if not hasattr(instance, "auth_identity"):
            # not triggered by user.
            return

        original_instance = getattr(instance, "_original_instance") if hasattr(instance, "_original_instance") else None
        auth_identity = getattr(instance, "auth_identity")
        if auth_identity:
            # add email to email identity and social auth if not exist
            EmailIdentity.objects.get_or_create(email=instance.email, user=instance.user)
            if not UserSocialAuth.objects.filter(user=instance.user, provider="email", uid=instance.email).exists():
                user_social_auth = UserSocialAuth.create_social_auth(instance.user, instance.email, 'email')
                user_social_auth.extra_data = {'email': [instance.email]}
                user_social_auth.save()

        if original_instance and (original_instance.email != instance.email or not auth_identity):
            # delete the profile's email from email identity and social auth
            EmailIdentity.objects.filter(email=original_instance.email, user=original_instance.user).delete()
            UserSocialAuth.objects.filter(provider="email", uid=original_instance.email, user=original_instance.user).delete()

        if not original_instance:
            address = instance.postal_address
            try:
                # Check if the user has the same profile address
                # Check if there is a user address
                oscar_add = UserAddress.objects.get(
                    line1 = address.line1,
                    line2 = address.line2,
                    line3 = address.line3,
                    line4 = address.locality,
                    state = address.state,
                    postcode = address.postcode,
                    country = Country.objects.get(iso_3166_1_a2=address.country),
                    user = instance.user
                )
                if not address.oscar_address:
                    address.oscar_address = oscar_add
                    address.save()
                elif address.oscar_address.id != oscar_add.id:
                    address.oscar_address = oscar_add
                    address.save()
            except UserAddress.DoesNotExist:
                oscar_address = UserAddress.objects.create(
                    line1 = address.line1,
                    line2 = address.line2,
                    line3 = address.line3,
                    line4 = address.locality,
                    state = address.state,
                    postcode = address.postcode,
                    country = Country.objects.get(iso_3166_1_a2=address.country),
                    user = instance.user
                )
                address.oscar_address = oscar_address
                address.save()
        # Clear out unused addresses
        # EmailUser can have address that is not linked with profile, hence the exclude
        ''' This functionality no longer in use due to more than just
示例#4
0
文件: models.py 项目: mehmadi/ledger
    def _post_save(sender, instance, **kwargs):
        if not hasattr(instance, "auth_identity"):
            # not triggered by user.
            return

        original_instance = getattr(instance, "_original_instance") if hasattr(instance, "_original_instance") else None
        auth_identity = getattr(instance, "auth_identity")
        if auth_identity:
            # add email to email identity and social auth if not exist
            EmailIdentity.objects.get_or_create(email=instance.email, user=instance.user)
            if not UserSocialAuth.objects.filter(user=instance.user, provider="email", uid=instance.email).exists():
                user_social_auth = UserSocialAuth.create_social_auth(instance.user, instance.email, 'email')
                user_social_auth.extra_data = {'email': [instance.email]}
                user_social_auth.save()

        if original_instance and (original_instance.email != instance.email or not auth_identity):
            # delete the profile's email from email identity and social auth
            EmailIdentity.objects.filter(email=original_instance.email, user=original_instance.user).delete()
            UserSocialAuth.objects.filter(provider="email", uid=original_instance.email, user=original_instance.user).delete()

        if not original_instance:
            address = instance.postal_address
            try:
                # Check if the user has the same profile address
                # Check if there is a user address
                oscar_add = UserAddress.objects.get(
                    line1 = address.line1,
                    line2 = address.line2,
                    line3 = address.line3,
                    line4 = address.locality,
                    state = address.state,
                    postcode = address.postcode,
                    country = Country.objects.get(iso_3166_1_a2=address.country),
                    user = instance.user
                )
                if not address.oscar_address:
                    address.oscar_address = oscar_add
                    address.save()
                elif address.oscar_address.id != oscar_add.id:
                    address.oscar_address = oscar_add
                    address.save()
            except UserAddress.DoesNotExist:
                oscar_address = UserAddress.objects.create(
                    line1 = address.line1,
                    line2 = address.line2,
                    line3 = address.line3,
                    line4 = address.locality,
                    state = address.state,
                    postcode = address.postcode,
                    country = Country.objects.get(iso_3166_1_a2=address.country),
                    user = instance.user
                )
                address.oscar_address = oscar_address
                address.save()
        # Clear out unused addresses
        ''' This functionality no longer in use due to more than just
def create_admin_user(sender, instance, created, **kwargs):
    if created:
        AdminUser.objects.create(user=instance)
        Token.objects.create(user=instance)
        if instance.is_superuser is True:
            social_user = UserSocialAuth.create_social_auth(instance, instance.id, 'quantummanagement')
            credential = {
                'username': instance.username,
                'password': instance.password,
            }
            credentials = CredentialsModel(user=instance, credentials=credential)
            social_user.save()
            credentials.save()
示例#6
0
def register_user(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(request,
                                username=username,
                                password=raw_password)

            social_user = UserSocialAuth.create_social_auth(
                user, user.id, 'quantummanagement')
            credential = {
                'username': user.username,
                'password': user.password,
            }
            credentials = CredentialsModel(user=user, credentials=credential)
            django_token = Token.objects.get(user=user)

            extra_data = {
                "token": django_token.key,
                # "credentials": credentials,
            }
            social_user.extra_data = extra_data
            social_user.save()
            credentials.save()

            login(request, user)
            return redirect(reverse('quantummanagementapp:home'))
        else:
            print("Register Errors", form.errors.as_data())
            error_messages = form.errors
            messages.add_message(request, messages.ERROR, error_messages)
            return redirect(reverse('quantummanagementapp:register'))

    else:
        admin_users = AdminUser.objects.all()
        form = SignUpForm()
        template = 'registration/register.html'
        context = {'admin_users': admin_users, 'form': form}
        return render(request, template, context)
示例#7
0
    def _post_save(sender, instance, **kwargs):
        original_instance = getattr(instance, "_original_instance") if hasattr(instance, "_original_instance") else None
        # add user's email to email identity and social auth if not exist
        if not instance.is_dummy_user:
            EmailIdentity.objects.get_or_create(email=instance.email, user=instance)
            if not UserSocialAuth.objects.filter(user=instance, provider="email", uid=instance.email).exists():
                user_social_auth = UserSocialAuth.create_social_auth(instance, instance.email, 'email')
                user_social_auth.extra_data = {'email': [instance.email]}
                user_social_auth.save()

        if original_instance and original_instance.email != instance.email:
            if not original_instance.is_dummy_user:
                # delete the user's email from email identity and social auth
                EmailIdentity.objects.filter(email=original_instance.email, user=original_instance).delete()
                UserSocialAuth.objects.filter(provider="email", uid=original_instance.email, user=original_instance).delete()
            # update profile's email if profile's email is original email
            Profile.objects.filter(email=original_instance.email, user=instance).update(email=instance.email)

        if original_instance and any([original_instance.first_name != instance.first_name, original_instance.last_name != instance.last_name]):
            # user changed first name or last name, send a named_changed signal.
            name_changed.send(sender=instance.__class__, user=instance)
示例#8
0
 def test_create_social_auth_without_transaction_atomic(self, *args):
     with self.assertRaises(IntegrityError):
         UserSocialAuth.create_social_auth(user=self.user,
                                           provider=self.usa.provider,
                                           uid=self.usa.uid)
示例#9
0
 def test_create_social_auth(self):
     usa = UserSocialAuth.create_social_auth(user=self.user,
                                             provider='test',
                                             uid=1)
     self.assertEqual(usa.uid, '1')
     self.assertEqual(str(usa), str(self.user))