Merge pull request #20974 from edx/INCR-324

INCR-324 python 3 compatibility
This commit is contained in:
Ayub
2019-07-11 00:03:41 +05:00
committed by GitHub
15 changed files with 65 additions and 32 deletions

View File

@@ -43,12 +43,7 @@ from student.models import (
from util.model_utils import emit_setting_changed_event
from util.password_policy_validators import normalize_password, validate_password
from .serializers import (
AccountLegacyProfileSerializer,
AccountUserSerializer,
UserReadOnlySerializer,
_visible_fields
)
from .serializers import AccountLegacyProfileSerializer, AccountUserSerializer, UserReadOnlySerializer, _visible_fields
# Public access point for this function.
visible_fields = _visible_fields

View File

@@ -1,6 +1,8 @@
"""
Django admin configuration pages for the user_api app
"""
from __future__ import absolute_import
from django.conf.urls import url
from django.contrib import admin, messages
from django.core.exceptions import ValidationError
@@ -11,7 +13,8 @@ from django.utils.html import format_html
from django.utils.translation import ugettext as _
from openedx.core.djangoapps.user_api.accounts.forms import RetirementQueueDeletionForm
from .models import UserRetirementPartnerReportingStatus, RetirementState, UserRetirementStatus, UserRetirementRequest
from .models import RetirementState, UserRetirementPartnerReportingStatus, UserRetirementRequest, UserRetirementStatus
@admin.register(RetirementState)

View File

@@ -1,23 +1,31 @@
import copy
import crum
"""
User Api.
"""
from __future__ import absolute_import
import copy
import crum
import six
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse
from django.utils.translation import ugettext as _
from django_countries import countries
import accounts
import third_party_auth
from edxmako.shortcuts import marketing_link
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.user_api import accounts
from openedx.core.djangoapps.user_api.helpers import FormDescription
from openedx.core.djangolib.markup import HTML, Text
from openedx.features.enterprise_support.api import enterprise_customer_for_request
from student.forms import get_registration_extension_form
from student.models import UserProfile
from util.password_policy_validators import (
password_validators_instruction_texts, password_validators_restrictions, DEFAULT_MAX_PASSWORD_LENGTH,
DEFAULT_MAX_PASSWORD_LENGTH,
password_validators_instruction_texts,
password_validators_restrictions
)
@@ -476,7 +484,7 @@ class RegistrationFormFactory(object):
# form used to select the user's year of birth.
yob_label = _(u"Year of birth")
options = [(unicode(year), unicode(year)) for year in UserProfile.VALID_YEARS]
options = [(six.text_type(year), six.text_type(year)) for year in UserProfile.VALID_YEARS]
form_desc.add_field(
"year_of_birth",
label=yob_label,
@@ -512,7 +520,7 @@ class RegistrationFormFactory(object):
field_type = "select"
include_default_option = True
field_options = extra_field_options.get(field_name)
options = [(unicode(option.lower()), option) for option in field_options]
options = [(six.text_type(option.lower()), option) for option in field_options]
error_msg = ''
error_msg = getattr(accounts, u'REQUIRED_FIELD_{}_SELECT_MSG'.format(field_name.upper()))

View File

@@ -3,4 +3,6 @@
"""
Django Administration forms module
"""
from __future__ import absolute_import
from student.forms import PasswordResetFormNoActive

View File

@@ -2,15 +2,18 @@
Helper functions for the account/profile Python APIs.
This is NOT part of the public API.
"""
from __future__ import absolute_import
import json
import logging
import traceback
from collections import defaultdict
from functools import wraps
import six
from django import forms
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponseBadRequest, HttpRequest
from django.http import HttpRequest, HttpResponseBadRequest
from django.utils.encoding import force_text
from django.utils.functional import Promise
@@ -58,7 +61,7 @@ def intercept_errors(api_error, ignore_errors=None):
u"with arguments '{args}' and keyword arguments '{kwargs}': "
u"{exception}"
).format(
func_name=func.func_name,
func_name=func.__name__,
args=args,
kwargs=kwargs,
exception=ex.developer_message if hasattr(ex, 'developer_message') else repr(ex)
@@ -74,7 +77,7 @@ def intercept_errors(api_error, ignore_errors=None):
u"with arguments '{args}' and keyword arguments '{kwargs}' from {caller}: "
u"{exception}"
).format(
func_name=func.func_name,
func_name=func.__name__,
args=args,
kwargs=kwargs,
exception=ex.developer_message if hasattr(ex, 'developer_message') else repr(ex),
@@ -264,7 +267,7 @@ class FormDescription(object):
if restrictions is not None:
allowed_restrictions = self.ALLOWED_RESTRICTIONS.get(field_type, [])
for key, val in restrictions.iteritems():
for key, val in six.iteritems(restrictions):
if key in allowed_restrictions:
field_dict["restrictions"][key] = val
else:
@@ -361,7 +364,7 @@ class FormDescription(object):
self._field_overrides[field_name].update({
property_name: property_value
for property_name, property_value in kwargs.iteritems()
for property_name, property_value in six.iteritems(kwargs)
if property_name in self.OVERRIDE_FIELD_PROPERTIES
})

View File

@@ -2,6 +2,8 @@
Defines the URL routes for this app.
"""
from __future__ import absolute_import
from django.conf import settings
from django.conf.urls import include, url
from rest_framework import routers

View File

@@ -2,6 +2,8 @@
Message Types for user_api emails
"""
from __future__ import absolute_import
from django.conf import settings
from openedx.core.djangoapps.ace_common.message import BaseMessageType

View File

@@ -3,10 +3,12 @@ Middleware for user api.
Adds user's tags to tracking event context.
"""
from __future__ import absolute_import
from eventtracking import tracker
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from eventtracking import tracker
from track.contexts import COURSE_REGEX
from .models import UserCourseTag

View File

@@ -1,6 +1,8 @@
"""
Django ORM model specifications for the User API application
"""
from __future__ import absolute_import
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from django.db import models
@@ -8,6 +10,7 @@ from django.db.models.signals import post_delete, post_save, pre_save
from django.dispatch import receiver
from model_utils.models import TimeStampedModel
from opaque_keys.edx.django.models import CourseKeyField
from openedx.core.djangolib.model_mixins import DeletableByUserValue
# Currently, the "student" app is responsible for

View File

@@ -1,13 +1,15 @@
"""
Provides partition support to the user service.
"""
from __future__ import absolute_import
import logging
import random
import course_tag.api as course_tag_api
from eventtracking import tracker
from xmodule.partitions.partitions import UserPartitionError, NoSuchUserPartitionGroupError
import openedx.core.djangoapps.user_api.course_tag.api as course_tag_api
from xmodule.partitions.partitions import NoSuchUserPartitionGroupError, UserPartitionError
log = logging.getLogger(__name__)

View File

@@ -1,6 +1,8 @@
"""
Permissions classes for User-API aware views.
"""
from __future__ import absolute_import
from django.contrib.auth.models import User
from django.http import Http404
from django.shortcuts import get_object_or_404

View File

@@ -3,8 +3,8 @@ Django rules for accounts
"""
from __future__ import absolute_import
from django.conf import settings
import rules
from django.conf import settings
@rules.predicate

View File

@@ -1,11 +1,13 @@
"""
Django REST Framework serializers for the User API application
"""
from __future__ import absolute_import
from django.contrib.auth.models import User
from django.utils.timezone import now
from rest_framework import serializers
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, SSOVerification, ManualVerification
from lms.djangoapps.verify_student.models import ManualVerification, SoftwareSecurePhotoVerification, SSOVerification
from .models import UserPreference

View File

@@ -2,6 +2,8 @@
Defines the URL routes for this app.
"""
from __future__ import absolute_import
from django.conf import settings
from django.conf.urls import url
@@ -17,8 +19,8 @@ from .accounts.views import (
UsernameReplacementView
)
from .preferences.views import PreferencesDetailView, PreferencesView
from .verification_api.views import IDVerificationStatusView
from .validation.views import RegistrationValidationView
from .verification_api.views import IDVerificationStatusView
ME = AccountViewSet.as_view({
'get': 'get',

View File

@@ -1,5 +1,7 @@
"""HTTP end-points for the User API. """
from __future__ import absolute_import
from django.contrib.auth.models import User
from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
from django.db import transaction
@@ -9,16 +11,15 @@ from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt, csrf_protect, ensure_csrf_cookie
from django.views.decorators.debug import sensitive_post_parameters
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import authentication, generics, status, viewsets
from rest_framework.exceptions import ParseError
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from six import text_type
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from opaque_keys import InvalidKeyError
from opaque_keys.edx import locator
from opaque_keys.edx.keys import CourseKey
from rest_framework import authentication, generics, status, viewsets
from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from six import text_type
from openedx.core.djangoapps.django_comment_common.models import Role
from openedx.core.djangoapps.user_api import accounts
@@ -31,7 +32,11 @@ from openedx.core.djangoapps.user_api.api import (
from openedx.core.djangoapps.user_api.helpers import require_post_params, shim_student_view
from openedx.core.djangoapps.user_api.models import UserPreference
from openedx.core.djangoapps.user_api.preferences.api import get_country_time_zones, update_email_opt_in
from openedx.core.djangoapps.user_api.serializers import CountryTimeZoneSerializer, UserPreferenceSerializer, UserSerializer
from openedx.core.djangoapps.user_api.serializers import (
CountryTimeZoneSerializer,
UserPreferenceSerializer,
UserSerializer
)
from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies
from openedx.core.djangoapps.user_authn.views.register import create_account_with_params
from openedx.core.lib.api.permissions import ApiKeyHeaderPermission