當前位置: 首頁>>代碼示例>>Python>>正文


Python models.UserProfile類代碼示例

本文整理匯總了Python中tardis.tardis_portal.models.UserProfile的典型用法代碼示例。如果您正苦於以下問題:Python UserProfile類的具體用法?Python UserProfile怎麽用?Python UserProfile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UserProfile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

    def setUp(self):

        self.accounts = [('user1', 'pwd1', 'useronefirstname', 'useronelastname'),
                         ('user2', 'pwd2', 'usertwofirstname', 'usertwolastname'),
                         ('user3', 'pwd3', 'userthreefirstname', 'userthreelastname')]

        for (uname, pwd, first, last) in self.accounts:
            user = User.objects.create_user(uname, '', pwd)
            user.first_name = first
            user.last_name = last
            user.save()
            profile = UserProfile(user=user,
                                         isDjangoAccount=True)
            profile.save()
        self.users = User.objects.all()

        self.client = Client()
        login = self.client.login(username=self.accounts[0][0],
                                  password=self.accounts[0][1])
        self.assertTrue(login)

        self.groups = ['group1', 'group2', 'group3', 'group4']
        for groupname in self.groups:
            group = Group(name=groupname)
            group.save()
開發者ID:aaryani,項目名稱:aa-migration-test1,代碼行數:25,代碼來源:test_views.py

示例2: create_user

def create_user(auth_method, user_id, email=''):
    # length of the maximum username
    max_length = 30

    # the username to be used on the User table
    if user_id.find('@') > 0:
        unique_username = user_id.partition('@')[0][:max_length]
    else:
        unique_username = user_id[:max_length]

    # Generate a unique username
    i = 0
    try:
        while (User.objects.get(username=unique_username)):
            i += 1
            unique_username = user_id[:max_length - len(str(i))] + str(i)
    except User.DoesNotExist:
        pass

    password = User.objects.make_random_password()
    user = User.objects.create_user(username=unique_username,
                                    password=password,
                                    email=email)
    user.save()

    userProfile = UserProfile(user=user, isDjangoAccount=False)
    userProfile.save()

    userAuth = UserAuthentication(userProfile=userProfile,
        username=user_id, authenticationMethod=auth_method)
    userAuth.save()

    return user
開發者ID:aaryani,項目名稱:aa-migration-test1,代碼行數:33,代碼來源:utils.py

示例3: setUp

    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '[email protected]',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        Location.force_initialize()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ObjectACL(
            pluginId='django_user',
            entityId=str(user.id),
            content_object=experiment,
            canRead=True,
            canWrite=True,
            canDelete=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED)
        acl.save()

        dataset = Dataset(description='dataset description...')
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()

        def create_datafile(filename):
            testfile = path.join(path.dirname(__file__), 'fixtures',
                                 filename)

            size, sha512sum = get_size_and_sha512sum(testfile)

            datafile = Dataset_File(dataset=dataset,
                                    filename=path.basename(testfile),
                                    size=size,
                                    sha512sum=sha512sum)
            datafile.save()
            base_url = 'file://' + path.abspath(path.dirname(testfile))
            location = Location.load_location({
                'name': 'test-grabber', 'url': base_url, 'type': 'external',
                'priority': 10, 'transfer_provider': 'local'})
            replica = Replica(datafile=datafile,
                              url='file://'+path.abspath(testfile),
                              protocol='file',
                              location=location)
            replica.verify()
            replica.save()
            return Dataset_File.objects.get(pk=datafile.pk)

        self.dataset = dataset
        self.datafiles = [create_datafile('data_grabber_test1.admin'),
                          create_datafile('testfile.txt')
                         ] 
開發者ID:UQ-CMM-Mirage,項目名稱:mytardis-app-datagrabber,代碼行數:59,代碼來源:test_datagrabber.py

示例4: configure_user

def configure_user(user):
    """ Configure a user account that has just been created by adding
    the user to the default groups and creating a UserProfile.

    :param user: the User instance for the newly created account
    """
    for group_name in settings.NEW_USER_INITIAL_GROUPS:
        try:
            group = Group.objects.get(name=group_name)
            user.groups.add(group)
        except Group.DoesNotExist:
            pass
    userProfile = UserProfile(user=user, isDjangoAccount=False)
    userProfile.save()
開發者ID:JMSS-IT-11-2012,項目名稱:mytardis,代碼行數:14,代碼來源:utils.py

示例5: get_or_create_user_with_username

def get_or_create_user_with_username(request, username, auth_key):
    isDjangoAccount = True

    try:
        # check if the given username in combination with the LDAP
        # auth method is already in the UserAuthentication table
        user = UserAuthentication.objects.get(username=username,
            authenticationMethod=auth_key).userProfile.user

    except UserAuthentication.DoesNotExist:
        # if request.user is not null, then we can assume that we are only
        # calling this function to verify if the provided username and
        # password will authenticate with the provided backend
        if type(request.user) is not AnonymousUser:
            user = request.user

        # else, create a new user with a random password
        else:
            isDjangoAccount = False

            if username.find('@') > 0:
                # the username to be used on the User table
                name = username.partition('@')[0]
            else:
                name = username

            # length of the maximum username and the separator `_`
            max_length = 31 - len(name)
            name = '%s_%s' % (auth_key, name[0:max_length])
            password = User.objects.make_random_password()
            user = User.objects.create_user(username=name,
                                            password=password,
                                            email=username)
            user.save()

        try:
            # we'll also try and check if the user already has an
            # existing userProfile attached to his/her account
            userProfile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            userProfile = UserProfile(user=user,
                isDjangoAccount=isDjangoAccount)
            userProfile.save()

        userAuth = UserAuthentication(userProfile=userProfile,
            username=username, authenticationMethod=auth_key)
        userAuth.save()

    return user
開發者ID:aaryani,項目名稱:CoreTardis,代碼行數:49,代碼來源:utils.py

示例6: handle

    def handle(self, *args, **options):
        verbosity = int(options.get('verbosity', 1))
        username = options.get('username', None)
        email = 'noreply'
        password = None

        user = User.objects.create_user(username, email, password)
        userProfile = UserProfile(user=user, isDjangoAccount=False)
        userProfile.save()

        # We do not create a UserAuthentication intentionally.
        # If we did, lookups to find the "TokenAuth" would fail

        if verbosity > 0:
            self.stdout.write("Tokenuser %s created successfully\n" % username)
            self.stdout.write("Ensure you have TOKEN_USERNAME='%s' in your settings file\n" % username)
開發者ID:ANSTO,項目名稱:mytardis,代碼行數:16,代碼來源:createtokenuser.py

示例7: save

    def save(self, profile_callback=None):
        user = RegistrationProfile.objects.create_inactive_user(
            username=self.cleaned_data['username'],
            password=self.cleaned_data['password1'],
            email=self.cleaned_data['email'])

        userProfile = UserProfile(user=user, isDjangoAccount=True)
        userProfile.save()

        authentication = UserAuthentication(
            userProfile=userProfile,
            username=self.cleaned_data['username'],
            authenticationMethod=locabdb_auth_key)
        authentication.save()

        return user
開發者ID:aaryani,項目名稱:aa-migration-test1,代碼行數:16,代碼來源:forms.py

示例8: setUp

    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '[email protected]',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(
            pluginId='django_user',
            entityId=str(user.id),
            experiment=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
            )
        acl.save()

        dataset = Dataset(description='dataset description...')
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()

        def create_datafile(index):
            testfile = path.join(path.dirname(__file__), 'fixtures',
                                 'jeol_sem_test%d.txt' % index)

            size, sha512sum = get_size_and_sha512sum(testfile)

            datafile = Dataset_File(dataset=dataset,
                                    filename=path.basename(testfile),
                                    url='file://'+path.abspath(testfile),
                                    protocol='file',
                                    size=size,
                                    sha512sum=sha512sum)
            datafile.verify()
            datafile.save()
            return datafile

        self.dataset = dataset
        self.datafiles = [create_datafile(i) for i in (1,2)]
開發者ID:JMSS-IT-11-2012,項目名稱:mytardis,代碼行數:47,代碼來源:test_jeolsem.py

示例9: setUp

    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '[email protected]',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()
        # Need UserAuthentication
        UserAuthentication(userProfile=profile,
                           username=username,
                           authenticationMethod='localdb').save()
        # Create staging dir
        from os import path, makedirs
        staging_dir = path.join(settings.STAGING_PATH, username)
        if not path.exists(staging_dir):
            makedirs(staging_dir)
        # Ensure that staging dir is set up properly
        expect(get_full_staging_path(username)).to_be_truthy()

        Location.force_initialize()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(user.id),
            experiment=experiment,\

            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
            )
        acl.save()

        self.dataset = \
            Dataset(description='dataset description...')
        self.dataset.save()
        self.dataset.experiments.add(experiment)
        self.dataset.save()

        self.username, self.password = (username, password)
開發者ID:guillaumeprevost,項目名稱:mytardis,代碼行數:45,代碼來源:test_views.py

示例10: testRightsRequireValidOwner

    def testRightsRequireValidOwner(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '[email protected]',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ObjectACL(
            pluginId=django_user,
            entityId=str(user.id),
            content_object=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        acl.save()

        # Create client and login as user
        client = Client()
        login = client.login(username=username, password=password)
        self.assertTrue(login)

        # Get "Choose Rights" page, and check that we're forbidden
        rights_url = reverse('tardis.tardis_portal.views.choose_rights',
                             args=[str(experiment.id)])
        response = client.get(rights_url)
        expect(response.status_code).to_equal(403)

        # Fill in remaining details
        user.first_name = "Voltaire" # Mononymous persons are just fine
        user.save()

        # Get "Choose Rights" page, and check that we're now allowed access
        response = client.get(rights_url)
        expect(response.status_code).to_equal(200)
開發者ID:crawley,項目名稱:mytardis,代碼行數:42,代碼來源:test_views.py

示例11: setUp

    def setUp(self):

        self.accounts = [('user1', 'pwd1'), ('user2', 'pwd2'), ('user3',
                                                                'pwd3')]

        for (uname, pwd) in self.accounts:
            user = User.objects.create_user(uname, '', pwd)
            user.save()
            profile = UserProfile(user=user, isDjangoAccount=True)
            profile.save()

        self.client = Client()
        login = self.client.login(
            username=self.accounts[0][0], password=self.accounts[0][1])
        self.assertTrue(login)

        self.groups = ['group1', 'group2', 'group3', 'group4']
        for groupname in self.groups:
            group = Group(name=groupname)
            group.save()
開發者ID:aaryani,項目名稱:aa-migration-test1,代碼行數:20,代碼來源:test_views.py

示例12: _get_or_create_user_with_username

def _get_or_create_user_with_username(username):
    user = None
    try:
        user = UserAuthentication.objects.get(username=username,
            authenticationMethod=auth_key).userProfile.user
    except UserAuthentication.DoesNotExist:
        # else, create a new user with a random password
        name = 'ldap_%s' % username[0:25]
        user = User(username=name,
            password=User.objects.make_random_password(),
            email=username)
        user.is_staff = True
        user.save()

        userProfile = UserProfile(authcate_user=True, user=user)
        userProfile.save()

        userAuth = UserAuthentication(userProfile=userProfile,
            username=username, authenticationMethod=auth_key)
        userAuth.save()
    return user
開發者ID:grischa,項目名稱:mytardis-mrtardis,代碼行數:21,代碼來源:ldap_auth.py

示例13: testManageAccount

    def testManageAccount(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '[email protected]',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()
        expect(user.get_profile().isValidPublicContact()).to_be(False)

        manage_url = reverse('tardis.tardis_portal.views.manage_user_account')

        # Create client and go to account management URL
        client = Client()
        response = client.get(manage_url)
        # Expect redirect to login
        expect(response.status_code).to_equal(302)

        # Login as user
        login = client.login(username=username, password=password)
        self.assertTrue(login)

        response = client.get(manage_url)
        # Expect 200 OK and a form
        expect(response.status_code).to_equal(200)
        response.content.index('name="first_name"')
        response.content.index('name="last_name"')
        response.content.index('name="email"')
        response.content.index('value="[email protected]"')

        # Update account details
        response = client.post(manage_url,
                               { 'first_name': 'Tommy',
                                 'email': '[email protected]'})
        # Expect 303 See Also redirect on update
        expect(response.status_code).to_equal(303)

        user = User.objects.get(id=user.id)
        expect(user.get_profile().isValidPublicContact()).to_be(True)
開發者ID:crawley,項目名稱:mytardis,代碼行數:39,代碼來源:test_views.py

示例14: setUp

    def setUp(self):

        self.accounts = [('user1', 'pwd1', 'useronefirstname', 'useronelastname'),
                         ('user2', 'pwd2', 'usertwofirstname', 'usertwolastname'),
                         ('user3', 'pwd3', 'userthreefirstname', 'userthreelastname')]

        self.token_accounts = [(settings.TOKEN_USERNAME, '', 'Token', 'User')]

        self.accounts += self.token_accounts

        for (uname, pwd, first, last) in self.accounts:
            user = User.objects.create_user(uname, '', pwd)
            user.first_name = first
            user.last_name = last
            user.save()
            profile = UserProfile(user=user,
                                         isDjangoAccount=True)
            profile.save()
        self.users = User.objects.all()

        self.client = Client()
        login = self.client.login(username=self.accounts[0][0],
                                  password=self.accounts[0][1])
        self.assertTrue(login)
開發者ID:crawley,項目名稱:mytardis,代碼行數:24,代碼來源:test_views.py

示例15: getUser

    def getUser(self, user_dict):
        """Return a user model based on the user dict.

        This function is responsible for creating the
        user within the Django DB and returning the resulting
        user model.
        """
        from django.contrib.auth.models import User
        from tardis.tardis_portal.models import UserProfile, UserAuthentication

        if not self._initialised:
            self._manual_init()

        plugin = user_dict['pluginname']

        username = ''
        if not 'id' in user_dict:
            email = user_dict['email']
            username =\
                self._authentication_backends[plugin].getUsernameByEmail(email)
        else:
            username = user_dict['id']

        try:
            user = UserAuthentication.objects.get(username=username,
                            authenticationMethod=plugin).userProfile.user
            return user
        except UserAuthentication.DoesNotExist:
            pass

        # length of the maximum username
        max_length = 30

        # the username to be used on the User table
        if username.find('@') > 0:
            unique_username = username.partition('@')[0][:max_length]
        else:
            unique_username = username[:max_length]

        # Generate a unique username
        i = 0
        try:
            while (User.objects.get(username=unique_username)):
                i += 1
                unique_username = username[:max_length - len(str(i))] + str(i)
        except User.DoesNotExist:
            pass

        password = User.objects.make_random_password()
        user = User.objects.create_user(username=unique_username,
                                        password=password,
                                        email=user_dict.get("email", ""))
        user.save()

        userProfile = UserProfile(user=user,
                                  isDjangoAccount=False)
        userProfile.save()

        userAuth = UserAuthentication(userProfile=userProfile,
            username=username, authenticationMethod=plugin)
        userAuth.save()

        if settings.STAGING_PROTOCOL == plugin:
            # to be put in its own function
            staging_path = get_full_staging_path(username)
            import os
            if not os.path.exists(staging_path):
                os.makedirs(staging_path)
                os.system('chmod g+w ' + staging_path)
                os.system('chown ' + username + ' ' + staging_path)

        return user
開發者ID:aaryani,項目名稱:CoreTardis,代碼行數:72,代碼來源:authservice.py


注:本文中的tardis.tardis_portal.models.UserProfile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。