Exemplo n.º 1
0
    def import_users(self, users):
        pkey_map = {}
        doc = dom.parse(users)

        rows = doc.getElementsByTagName('row')
        unknown_count = 0

        added_names = []

        for row in rows:
            values = self.row_to_dic(row)

            username = values.get('displayname',
                            values.get('realname',
                                values.get('email', None)))

            if username is None:
                unknown_count += 1
                username = '******' % unknown_count

            if username in added_names:
                cnt = 1
                new_username = "******" % (username, cnt)
                while new_username in added_names:
                    cnt += 1
                    new_username = "******" % (username, cnt)

                username = new_username

            added_names.append(username)

            user = User(username=username, email=values.get('email', ''))

            user.reputation = values['reputation']
            user.last_seen = self.from_sx_time(values['lastaccessdate'])

            user.real_name = values.get('realname', '')
            user.about = values.get('aboutme', '')
            user.website = values.get('websiteurl', '')
            user.date_of_birth = self.from_sx_time(values.get('birthday', None))
            user.location = values.get('location', '')

            user.is_active = True
            user.email_isvalid = True


            if int(values['usertypeid']) == 5:
                user.is_superuser = True

            if int(values['usertypeid']) == 5:
                user.is_staff = True

            user.save()

            pkey_map[values['id']] = user

        return users
Exemplo n.º 2
0
def update_forum_user(request):
    """ Create or Update Forum User model """

    try:
        # Customise User Model
        # username = request.user.username.split('@')[0]
        user = User.objects.get(user_ptr_id=request.user.id)
        user.user_ptr = request.user
        user.save()
    except ObjectDoesNotExist:
        obj = User()
        obj.user_ptr = request.user
        obj.email_isvalid = True

        obj.last_seen = request.user.last_login
        obj.username = request.user.username if '@' not in request.user.username else request.user.username.split('@')[0]
        obj.real_name = "%s %s" % (request.user.first_name, request.user.last_name)
        # obj.is_active = request.user.is_active
        obj.email = request.user.email
        obj.profile_image_url = request.session['profile_image'] if 'profile_image' in request.session else ''
        obj.save()