From fb595c89f3937f5bdeccba1e37a2b8211434fe1a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 1 Feb 2015 12:10:56 -0500 Subject: [PATCH] Fix a number of incorrect translation string uses These were found by the new pylint checker I wrote! :) --- .../contentstore/git_export_utils.py | 2 +- .../management/commands/git_export.py | 4 +-- cms/djangoapps/contentstore/views/library.py | 2 +- .../models/settings/course_metadata.py | 4 +-- common/lib/xmodule/xmodule/lti_module.py | 20 +++++++++----- common/lib/xmodule/xmodule/seq_module.py | 2 +- lms/djangoapps/dashboard/sysadmin.py | 4 +-- lms/djangoapps/instructor/views/api.py | 4 +-- lms/djangoapps/shoppingcart/models.py | 9 +++++-- lms/djangoapps/shoppingcart/pdf.py | 2 +- .../shoppingcart/processors/CyberSource.py | 26 +++++++++++-------- .../shoppingcart/processors/CyberSource2.py | 7 +++-- lms/djangoapps/shoppingcart/views.py | 24 ++++++++++------- 13 files changed, 65 insertions(+), 45 deletions(-) diff --git a/cms/djangoapps/contentstore/git_export_utils.py b/cms/djangoapps/contentstore/git_export_utils.py index f2752737d2..42698db5a4 100644 --- a/cms/djangoapps/contentstore/git_export_utils.py +++ b/cms/djangoapps/contentstore/git_export_utils.py @@ -32,7 +32,7 @@ class GitExportError(Exception): NO_EXPORT_DIR = _("GIT_REPO_EXPORT_DIR not set or path {0} doesn't exist, " "please create it, or configure a different path with " - "GIT_REPO_EXPORT_DIR".format(GIT_REPO_EXPORT_DIR)) + "GIT_REPO_EXPORT_DIR").format(GIT_REPO_EXPORT_DIR) URL_BAD = _('Non writable git url provided. Expecting something like:' ' git@github.com:mitocw/edx4edx_lite.git') URL_NO_AUTH = _('If using http urls, you must provide the username ' diff --git a/cms/djangoapps/contentstore/management/commands/git_export.py b/cms/djangoapps/contentstore/management/commands/git_export.py index 5182127dca..1edb195345 100644 --- a/cms/djangoapps/contentstore/management/commands/git_export.py +++ b/cms/djangoapps/contentstore/management/commands/git_export.py @@ -62,7 +62,7 @@ class Command(BaseCommand): try: course_key = SlashSeparatedCourseKey.from_deprecated_string(args[0]) except InvalidKeyError: - raise CommandError(_(GitExportError.BAD_COURSE)) + raise CommandError(unicode(GitExportError.BAD_COURSE)) try: git_export_utils.export_to_git( @@ -72,4 +72,4 @@ class Command(BaseCommand): options.get('rdir', None) ) except git_export_utils.GitExportError as ex: - raise CommandError(_(ex.message)) + raise CommandError(unicode(ex.message)) diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index 2bd433c83f..3cbba074ba 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -137,7 +137,7 @@ def _create_library(request): except KeyError as error: log.exception("Unable to create library - missing required JSON key.") return JsonResponseBadRequest({ - "ErrMsg": _("Unable to create library - missing required field '{field}'".format(field=error.message)) + "ErrMsg": _("Unable to create library - missing required field '{field}'").format(field=error.message) }) except InvalidKeyError as error: log.exception("Unable to create library - invalid key.") diff --git a/cms/djangoapps/models/settings/course_metadata.py b/cms/djangoapps/models/settings/course_metadata.py index cbf4b92d60..3a8265aef9 100644 --- a/cms/djangoapps/models/settings/course_metadata.py +++ b/cms/djangoapps/models/settings/course_metadata.py @@ -117,8 +117,8 @@ class CourseMetadata(object): if hasattr(descriptor, key) and getattr(descriptor, key) != val: key_values[key] = descriptor.fields[key].from_json(val) except (TypeError, ValueError) as err: - raise ValueError(_("Incorrect format for field '{name}'. {detailed_message}".format( - name=model['display_name'], detailed_message=err.message))) + raise ValueError(_("Incorrect format for field '{name}'. {detailed_message}").format( + name=model['display_name'], detailed_message=err.message)) return cls.update_from_dict(key_values, descriptor, user) diff --git a/common/lib/xmodule/xmodule/lti_module.py b/common/lib/xmodule/xmodule/lti_module.py index 6881d94dd9..340ce84d24 100644 --- a/common/lib/xmodule/xmodule/lti_module.py +++ b/common/lib/xmodule/xmodule/lti_module.py @@ -80,10 +80,9 @@ log = logging.getLogger(__name__) # Make '_' a no-op so we can scrape strings _ = lambda text: text -DOCS_ANCHOR_TAG = ( - "" - "the edX LTI documentation" ) @@ -122,7 +121,10 @@ class LTIFields(object): "Enter the LTI ID for the external LTI provider. " "This value must be the same LTI ID that you entered in the " "LTI Passports setting on the Advanced Settings page." - "
See " + DOCS_ANCHOR_TAG + " for more details on this setting." + "
See {docs_anchor_open}the edX LTI documentation{anchor_close} for more details on this setting." + ).format( + docs_anchor_open=DOCS_ANCHOR_TAG_OPEN, + anchor_close="" ), default='', scope=Scope.settings @@ -132,7 +134,10 @@ class LTIFields(object): help=_( "Enter the URL of the external tool that this component launches. " "This setting is only used when Hide External Tool is set to False." - "
See " + DOCS_ANCHOR_TAG + " for more details on this setting." + "
See {docs_anchor_open}the edX LTI documentation{anchor_close} for more details on this setting." + ).format( + docs_anchor_open=DOCS_ANCHOR_TAG_OPEN, + anchor_close="" ), default='http://www.example.com', scope=Scope.settings) @@ -141,7 +146,10 @@ class LTIFields(object): help=_( "Add the key/value pair for any custom parameters, such as the page your e-book should open to or " "the background color for this component." - "
See " + DOCS_ANCHOR_TAG + " for more details on this setting." + "
See {docs_anchor_open}the edX LTI documentation{anchor_close} for more details on this setting." + ).format( + docs_anchor_open=DOCS_ANCHOR_TAG_OPEN, + anchor_close="" ), scope=Scope.settings) open_in_a_new_page = Boolean( diff --git a/common/lib/xmodule/xmodule/seq_module.py b/common/lib/xmodule/xmodule/seq_module.py index 1f1b383dc9..4c4d9b26af 100644 --- a/common/lib/xmodule/xmodule/seq_module.py +++ b/common/lib/xmodule/xmodule/seq_module.py @@ -49,7 +49,7 @@ class SequenceFields(object): is_entrance_exam = Boolean( display_name=_("Is Entrance Exam"), help=_( - "Tag this course module as an Entrance Exam. " + + "Tag this course module as an Entrance Exam. " "Note, you must enable Entrance Exams for this course setting to take effect." ), scope=Scope.content, diff --git a/lms/djangoapps/dashboard/sysadmin.py b/lms/djangoapps/dashboard/sysadmin.py index 828ef83634..a7a401f1b7 100644 --- a/lms/djangoapps/dashboard/sysadmin.py +++ b/lms/djangoapps/dashboard/sysadmin.py @@ -463,7 +463,7 @@ class Courses(SysadminDashboardView): # new, and pull is when it is being updated from the # source. return _('Unable to clone or pull repository. Please check ' - 'your url. Output was: {0!r}'.format(ex.output)) + 'your url. Output was: {0!r}').format(ex.output) msg += u'
{0}
'.format(cmd_output) if not os.path.exists(gdir): @@ -479,7 +479,7 @@ class Courses(SysadminDashboardView): # specific version of a courses content msg += u'

{0}

'.format( _('Successfully switched to branch: ' - '{branch_name}'.format(branch_name=branch))) + '{branch_name}').format(branch_name=branch)) self.def_ms.try_load_course(os.path.abspath(gdir)) errlog = self.def_ms.errored_courses.get(cdir, '') diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index ece0296753..8c97f1e899 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -374,7 +374,7 @@ def register_and_enroll_students(request, course_id): # pylint: disable=too-man except Exception as ex: log.exception(type(ex).__name__) row_errors.append({ - 'username': username, 'email': email, 'response': _(type(ex).__name__)}) + 'username': username, 'email': email, 'response': type(ex).__name__}) else: # It's a new user, an email will be sent to each newly created user. email_params['message'] = 'account_creation_and_enrollment' @@ -887,7 +887,7 @@ def sale_validation(request, course_id): try: obj_invoice = Invoice.objects.select_related('is_valid').get(id=invoice_number, course_id=course_id) except Invoice.DoesNotExist: - return HttpResponseNotFound(_("Invoice number '{0}' does not exist.".format(invoice_number))) + return HttpResponseNotFound(_("Invoice number '{0}' does not exist.").format(invoice_number)) if event_type == "invalidate": return invalidate_invoice(obj_invoice) diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index 32562455d1..8c6bda7860 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -1381,7 +1381,10 @@ class CertificateItem(OrderItem): else: msg = u"Mode {mode} does not exist for {course_id}".format(mode=mode, course_id=course_id) log.error(msg) - raise InvalidCartItem(_(msg)) + raise InvalidCartItem( + _(u"Mode {mode} does not exist for {course_id}").format(mode=mode, course_id=course_id) + ) + item, _created = cls.objects.get_or_create( order=order, user=order.user, @@ -1649,7 +1652,9 @@ class Donation(OrderItem): if course is None: msg = u"Could not find a course with the ID '{course_id}'".format(course_id=course_id) log.error(msg) - raise CourseDoesNotExistException(_(msg)) + raise CourseDoesNotExistException( + _(u"Could not find a course with the ID '{course_id}'").format(course_id=course_id) + ) return _(u"Donation for {course}").format(course=course.display_name) diff --git a/lms/djangoapps/shoppingcart/pdf.py b/lms/djangoapps/shoppingcart/pdf.py index 802ac78dc3..32f21555dc 100644 --- a/lms/djangoapps/shoppingcart/pdf.py +++ b/lms/djangoapps/shoppingcart/pdf.py @@ -239,7 +239,7 @@ class PDFInvoice(object): y_pos = y_pos - font_size / 2 - vertical_padding # Draw Order/Invoice No. self.pdf.drawString(horizontal_padding_from_border, y_pos, - _(u'{id_label} # {item_id}'.format(id_label=id_label, item_id=self.item_id))) + _(u'{id_label} # {item_id}').format(id_label=id_label, item_id=self.item_id)) y_pos = y_pos - font_size / 2 - vertical_padding # Draw Date self.pdf.drawString( diff --git a/lms/djangoapps/shoppingcart/processors/CyberSource.py b/lms/djangoapps/shoppingcart/processors/CyberSource.py index 7b5bd6ed19..0e6c12939b 100644 --- a/lms/djangoapps/shoppingcart/processors/CyberSource.py +++ b/lms/djangoapps/shoppingcart/processors/CyberSource.py @@ -166,13 +166,13 @@ def payment_accepted(params): ('decision', str)]: if key not in params: raise CCProcessorDataException( - _("The payment processor did not return a required parameter: {0}".format(key)) + _("The payment processor did not return a required parameter: {0}").format(key) ) try: valid_params[key] = key_type(params[key]) except ValueError: raise CCProcessorDataException( - _("The payment processor returned a badly-typed value {0} for param {1}.".format(params[key], key)) + _("The payment processor returned a badly-typed value {0} for param {1}.").format(params[key], key) ) try: @@ -187,8 +187,9 @@ def payment_accepted(params): charged_amt = Decimal(params['ccAuthReply_amount']) except InvalidOperation: raise CCProcessorDataException( - _("The payment processor returned a badly-typed value {0} for param {1}.".format( - params['ccAuthReply_amount'], 'ccAuthReply_amount')) + _("The payment processor returned a badly-typed value {0} for param {1}.").format( + params['ccAuthReply_amount'], 'ccAuthReply_amount' + ) ) if charged_amt == order.total_cost and valid_params['orderCurrency'] == order.currency: @@ -198,9 +199,13 @@ def payment_accepted(params): 'order': order} else: raise CCProcessorWrongAmountException( - _("The amount charged by the processor {0} {1} is different than the total cost of the order {2} {3}." - .format(charged_amt, valid_params['orderCurrency'], - order.total_cost, order.currency)) + _("The amount charged by the processor {0} {1} is different than the total cost of the order {2} {3}.") + .format( + charged_amt, + valid_params['orderCurrency'], + order.total_cost, + order.currency + ) ) else: return {'accepted': False, @@ -400,10 +405,9 @@ REASONCODE_MAP.update( Possible fix: retry with another form of payment """)), '233': _('General decline by the processor. Possible fix: retry with another form of payment'), - '234': dedent(_( - """ - There is a problem with our CyberSource merchant configuration. Please let us know at {0} - """.format(settings.PAYMENT_SUPPORT_EMAIL))), + '234': _( + "There is a problem with our CyberSource merchant configuration. Please let us know at {0}" + ).format(settings.PAYMENT_SUPPORT_EMAIL), # reason code 235 only applies if we are processing a capture through the API. so we should never see it '235': _('The requested amount exceeds the originally authorized amount.'), '236': _('Processor Failure. Possible fix: retry the payment'), diff --git a/lms/djangoapps/shoppingcart/processors/CyberSource2.py b/lms/djangoapps/shoppingcart/processors/CyberSource2.py index fb4f5e2528..37450b084e 100644 --- a/lms/djangoapps/shoppingcart/processors/CyberSource2.py +++ b/lms/djangoapps/shoppingcart/processors/CyberSource2.py @@ -634,10 +634,9 @@ REASONCODE_MAP.update( Possible fix: retry with another form of payment """)), '233': _('General decline by the processor. Possible fix: retry with another form of payment'), - '234': dedent(_( - """ - There is a problem with the information in your CyberSource account. Please let us know at {0} - """.format(settings.PAYMENT_SUPPORT_EMAIL))), + '234': _( + "There is a problem with the information in your CyberSource account. Please let us know at {0}" + ).format(settings.PAYMENT_SUPPORT_EMAIL), '236': _('Processor Failure. Possible fix: retry the payment'), '240': dedent(_( """ diff --git a/lms/djangoapps/shoppingcart/views.py b/lms/djangoapps/shoppingcart/views.py index c4173510ae..a19541d05c 100644 --- a/lms/djangoapps/shoppingcart/views.py +++ b/lms/djangoapps/shoppingcart/views.py @@ -91,10 +91,10 @@ def add_course_to_cart(request, course_id): except CourseDoesNotExistException: return HttpResponseNotFound(_('The course you requested does not exist.')) except ItemAlreadyInCartException: - return HttpResponseBadRequest(_('The course {course_id} is already in your cart.'.format(course_id=course_id))) + return HttpResponseBadRequest(_('The course {course_id} is already in your cart.').format(course_id=course_id)) except AlreadyEnrolledInCourseException: return HttpResponseBadRequest( - _('You are already registered in course {course_id}.'.format(course_id=course_id))) + _('You are already registered in course {course_id}.').format(course_id=course_id)) else: # in case a coupon redemption code has been applied, new items should also get a discount if applicable. order = paid_course_item.order @@ -283,7 +283,7 @@ def use_code(request): try: course_reg = CourseRegistrationCode.objects.get(code=code) except CourseRegistrationCode.DoesNotExist: - return HttpResponseNotFound(_("Discount does not exist against code '{code}'.".format(code=code))) + return HttpResponseNotFound(_("Discount does not exist against code '{code}'.").format(code=code)) return use_registration_code(course_reg, request.user) @@ -432,18 +432,22 @@ def use_registration_code(course_reg, user): """ if RegistrationCodeRedemption.is_registration_code_redeemed(course_reg): log.warning("Registration code '{registration_code}' already used".format(registration_code=course_reg.code)) - return HttpResponseBadRequest(_( - "Oops! The code '{registration_code}' you entered is either invalid or expired".format( - registration_code=course_reg.code))) + return HttpResponseBadRequest( + _("Oops! The code '{registration_code}' you entered is either invalid or expired").format( + registration_code=course_reg.code + ) + ) try: cart = Order.get_cart_for_user(user) cart_items = cart.find_item_by_course_id(course_reg.course_id) except ItemNotFoundInCartException: log.warning("Course item does not exist against registration code '{registration_code}'".format( registration_code=course_reg.code)) - return HttpResponseNotFound(_( - "Code '{registration_code}' is not valid for any course in the shopping cart.".format( - registration_code=course_reg.code))) + return HttpResponseNotFound( + _("Code '{registration_code}' is not valid for any course in the shopping cart.").format( + registration_code=course_reg.code + ) + ) else: applicable_cart_items = [ cart_item for cart_item in cart_items @@ -478,7 +482,7 @@ def use_coupon_code(coupons, user): if not is_redemption_applied: log.warning("Discount does not exist against code '{code}'.".format(code=coupons[0].code)) - return HttpResponseNotFound(_("Discount does not exist against code '{code}'.".format(code=coupons[0].code))) + return HttpResponseNotFound(_("Discount does not exist against code '{code}'.").format(code=coupons[0].code)) return HttpResponse( json.dumps({'response': 'success', 'coupon_code_applied': True}),