Commit Graph

64 Commits

Author SHA1 Message Date
Usama Sadiq
b6828cecaa fix: enable pylint warnings (#36195)
* fix: enable pylint warnings
2025-01-30 17:15:33 +05:00
Tim McCormack
0359d5204d fix: Prevent error page recursion (#35209)
We sometimes see rendering errors in the error page itself, which then
cause another attempt at rendering the error page. I'm not sure _exactly_
how the loop is occurring, but it looks something like this:

1. An error is raised in a view or middleware and is not caught by
   application code
2. Django catches the error and calls the registered uncaught error
   handler
3. Our handler tries to render an error page
4. The rendering code raises an error
5. GOTO 2 (until some sort of server limit is reached)

By catching all errors raised during error-page render and substituting in
a hardcoded string, we can reduce server resources, avoid logging massive
sequences of recursive stack traces, and still give the user *some*
indication that yes, there was a problem.

This should help address https://github.com/openedx/edx-platform/issues/35151

At least one of these rendering errors is known to be due to a translation
error. There's a separate issue for restoring translation quality so that
we avoid those issues in the future (https://github.com/openedx/openedx-translations/issues/549)
but in general we should catch all rendering errors, including unknown
ones.

Testing:

- In `lms/envs/devstack.py` change `DEBUG` to `False` to ensure that the
  usual error page is displayed (rather than the debug error page).
- Add line `1/0` to the top of the `student_dashboard` function in
 `common/djangoapps/student/views/dashboard.py` to make that view error.
- In `lms/templates/static_templates/server-error.html` replace
  `static.get_platform_name()` with `None * 7` to make the error template
  itself produce an error.
- Visit <http://localhost:18000/dashboard>.

Without the fix, the response takes 10 seconds and produces a 6 MB, 85k
line set of stack traces and the page displays "A server error occurred.
Please contact the administrator."

With the fix, the response takes less than a second and produces three
stack traces (one of which contains the error page's rendering error).
2024-07-31 17:36:08 +00:00
Feanil Patel
3b7facd565 fix: Add names to the error page urls.
Some of the static_template_view tests use names to get the URLs for the
error pages for testing, so I added names and updated the test to match
the new names.

I also updated the `test_404` function because we're no longer rendering
the 404 page in a different way from the 500 page so the response
includes the correct response code and content type.  This reduces the
number of differences between the 404 handler and the 500 handler.
2023-06-13 12:20:11 -04:00
Feanil Patel
0326b45d6a fix: Update how we render the error pages.
We were adding paths for the error pages in two places so one of them
simply wasn't being used. The lms urls.py also covered the 429 wich the
static_templates_view urls.py did not cover.  We don't need both and we
need the definition of the handlerNNN variables in urls.py to override
the default django error views so I'll leave just those.

I also made the `exception` parameter for the `render_404` function
optional by adding a default value.  We don't use the exception when
rendering the 404 page but the exception argument is a part of the
default method signature for the function that `render_404` replaces so
I didn't want to remove it and cause issues when django tries to call
this function.
2023-06-13 11:52:19 -04:00
Mohammad Ahtasham ul Hassan
b01cf355a7 Unpin django-ratelimit (#31416)
* fix: fix ratelimit upgrade changes

Co-authored-by: Awais Qureshi <awais.qureshi@arbisoft.com>
2023-01-19 16:39:23 +05:00
M. Zulqarnain
b84b862cc0 feat: Django codemods on LMS (3) (#28853) 2021-11-16 18:27:21 +05:00
M. Zulqarnain
65f79ef9b3 BOM-2365 : pyupgrade on static_templates, staticbook and support apps (#26699)
*pyupgrade on static_templates, staticbook and support apps

This reverts commit 1ec2e797a1.

* Apply suggestions from code review

Co-authored-by: Usama Sadiq <usama.sadiq@arbisoft.com>
2021-02-25 14:37:09 +05:00
Cory Lee
1ec2e797a1 Revert "pyupgrade on static_templates, staticbook and support apps (#26646)" (#26685)
This reverts commit a235425ac3.
2021-02-23 13:01:16 -05:00
M. Zulqarnain
a235425ac3 pyupgrade on static_templates, staticbook and support apps (#26646) 2021-02-23 12:35:53 +05:00
Aarif
944df92787 replaced unittest assertions pytest assertions (#26548) 2021-02-19 15:58:45 +05:00
Feanil Patel
cd3e4353b1 feat: Add a 403 and 429 handler.
See context here: https://django-ratelimit.readthedocs.io/en/latest/cookbook/429.html#context

For now we continue to fall back to django's default 403 handler for 403
but provide a new 429 template that we use for ratelimit exceptions.

This commit also updates a logistration test that relied on the old 403
behavior of django-ratelimit instead of the newly added 429 behavior.
2021-02-08 14:03:26 -05:00
Awais Qureshi
5510dc1c43 BOM-2286
Apply pylint-amnesty.
2021-02-02 12:39:06 +05:00
Kyle McCormick
151bd13666 Use full names for common.djangoapps imports; warn when using old style (#25477)
* Generate common/djangoapps import shims for LMS
* Generate common/djangoapps import shims for Studio
* Stop appending project root to sys.path
* Stop appending common/djangoapps to sys.path
* Import from common.djangoapps.course_action_state instead of course_action_state
* Import from common.djangoapps.course_modes instead of course_modes
* Import from common.djangoapps.database_fixups instead of database_fixups
* Import from common.djangoapps.edxmako instead of edxmako
* Import from common.djangoapps.entitlements instead of entitlements
* Import from common.djangoapps.pipline_mako instead of pipeline_mako
* Import from common.djangoapps.static_replace instead of static_replace
* Import from common.djangoapps.student instead of student
* Import from common.djangoapps.terrain instead of terrain
* Import from common.djangoapps.third_party_auth instead of third_party_auth
* Import from common.djangoapps.track instead of track
* Import from common.djangoapps.util instead of util
* Import from common.djangoapps.xblock_django instead of xblock_django
* Add empty common/djangoapps/__init__.py to fix pytest collection
* Fix pylint formatting violations
* Exclude import_shims/ directory tree from linting
2020-11-10 07:02:01 -05:00
Kyle McCormick
d1a775d3cd Use full names for lms.djangoapps imports (#25401)
* Use full LMS imports paths in LMS settings and urls modules
* Use full LMS import paths in Studio settings and urls modules
* Import from lms.djangoapps.badges instead of badges
* Import from lms.djangoapps.branding instead of branding
* Import from lms.djangoapps.bulk_email instead of bulk_email
* Import from lms.djangoapps.bulk_enroll instead of bulk_enroll
* Import from lms.djangoapps.ccx instead of ccx
* Import from lms.djangoapps.course_api instead of course_api
* Import from lms.djangoapps.course_blocks instead of course_blocks
* Import from lms.djangoapps.course_wiki instead of course_wiki
* Import from lms.djangoapps.courseware instead of courseware
* Import from lms.djangoapps.dashboard instead of dashboard
* Import from lms.djangoapps.discussion import discussion
* Import from lms.djangoapps.email_marketing instead of email_marketing
* Import from lms.djangoapps.experiments instead of experiments
* Import from lms.djangoapps.gating instead of gating
* Import from lms.djangoapps.grades instead of grades
* Import from lms.djangoapps.instructor_analytics instead of instructor_analytics
* Import form lms.djangoapps.lms_xblock instead of lms_xblock
* Import from lms.djangoapps.lti_provider instead of lti_provider
* Import from lms.djangoapps.mobile_api instead of mobile_api
* Import from lms.djangoapps.rss_proxy instead of rss_proxy
* Import from lms.djangoapps.static_template_view instead of static_template_view
* Import from lms.djangoapps.survey instead of survey
* Import from lms.djangoapps.verify_student instead of verify_student
* Stop suppressing EdxPlatformDeprecatedImportWarnings
2020-11-04 08:48:33 -05:00
Aarif
98af9ce418 remove useless-supression warnings 2020-05-01 19:42:15 +05:00
Ahtisham Shahid
f6be77d493 Removed tech email form error templates
fixed tests

fixed test fail

Fixed failing tests
2020-04-01 14:53:01 +05:00
zia.fazal@arbisoft.com
2453bc8c05 Stop showing hitting enterprise API in case of 404 error
Stop showing hitting enterprise API when request is originated as result of 404 error.

fixed quality violations

Removed line break

add unit tests

Updated test docstring
2020-02-14 15:16:51 +05:00
usama sadiq
720dcb6c3a Updated ExceptionViews handles
Added additional 'exception' parameter to function headers.
Disabled pylint warnings for missing docstring and unused arguments.
2020-01-10 15:56:24 +05:00
Feanil Patel
6e3fe00fff Fix all E303 pep8 errors. 2019-12-30 12:25:38 -05:00
Feanil Patel
9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00
Nimisha Asthagiri
a6b219a9e9 Python-3: assertIn(..response.content) -> assertContains 2019-09-30 08:50:38 -04:00
Nimisha Asthagiri
feaacef3f3 Remove microsites from static_template_view
DEPR-28
2019-05-29 10:38:00 -04:00
Stu Young
c20c770eb0 incr-297 (#20604)
* run python modernize

* run isort
2019-05-15 16:58:04 -04:00
Calen Pennington
8c53ce6493 Merge pull request #19743 from edx/unicode7
fix unicode strings in lms/ part 2
2019-02-13 14:15:02 -05:00
Matthew Piatetsky
764319d3e0 fix unicode strings in lms/ part 2 2019-02-13 10:35:56 -05:00
Michael Youngstrom
3221c2b91f Remove lms pytest shards 2019-02-12 11:03:46 -05:00
Eric Fischer
247bb50ed2 s/django.core.urlresolvers/django.urls/g
Django 1.10 deprecation fix for Hackathon XIX
Addresses PLAT-1397
2018-06-05 13:59:09 -04:00
Stuart Young
1fd2167144 rebalance python unittests onto new shards 2018-05-03 11:16:05 -04:00
Mike
0e2b667bb4 Added ability to change header and content of static pages in two ways.
1. Using the pageheader and pagecontent block names.
2. Setting SiteConfiguration settings for each individual html page.

Co-authored by: Tomasz Gargas <tomasz@opencraft.com>
2018-03-24 21:37:09 +01:00
Gavin Sidebottom
67442c2641 Fixed unthemed error pages in Studio and LMS 2018-02-22 16:49:06 -05:00
Jeremy Bowman
ca84751bbd PLAT-1889 Fix URL config and reversal issues 2018-01-19 11:02:06 -05:00
Jeremy Bowman
fdc50c3aa8 PLAT-1419 Make edxmako a proper template backend 2017-12-01 17:01:52 -05:00
bmedx
bebdc069a7 LMS urls cleanup for Django 1.11
- Remove usage of django.urls.patterns
- Change urls tuples to lists
- Make all string view names callables
- This is the third urls update for LMS
2017-11-07 14:17:54 -05:00
Andy Armstrong
79acb5c5be Reorder LMS imports using isort 2017-06-11 21:48:06 -04:00
Douglas Cerna
eaa02db6ae Added Terms of Service modal 2017-05-29 11:57:04 -06:00
Robert Raposa
e7028c6eab Move static_template_view.views to its own urls.py. 2016-10-12 14:37:18 -04:00
Matjaz Gregoric
344c72b3e2 Use non-ascii PLATFORM_NAME in tests.
It should help catch unicode encoding problems earlier.

This also updates python-saml dependency to a version that includes a
patch for unicode strings.
2016-09-23 15:38:23 +02:00
Saleem Latif
8ae92901ef 1. Merge microsites into Comprehensive Theming
2. Add site configuration overrides to theming/helpers.py
3. Move microsite.get_value from theming/helpers to site_configuration/helpers
4. Move microsite_configuration.microsite.get_value usages to site_configuration.helpers.values
2016-07-27 13:55:14 +05:00
Calen Pennington
93970f3473 Allow edxmako to be passed an explicit request to create the RequestContext from 2016-06-08 16:35:25 -04:00
Calen Pennington
4a3f8358de Make static_template_view.tests an actual module 2016-05-18 14:10:28 -04:00
Zia Fazal
06e38e1c24 added branding to 404 and 500 error pages
changes based on feedback

renamed a definition and added test coverage

fixed broken tests
2016-01-29 15:46:51 +05:00
Ibrahim
0f09bb8a94 raise 404 when copyright template is missing 2016-01-22 12:02:46 -05:00
Hasnain
c14f65a293 Added site_map in static template
Allow file extensions in MKTG_URL_LINK_MAP template keys
Set content type on requests for static templates based on the template key
2016-01-14 13:44:54 -05:00
Sarina Canelake
e53b9c83d9 Use Django 1.4 @ensure_csrf_cookie method PLAT-664 2015-06-06 08:48:36 -04:00
Renzo Lucioni
f5767a961c Prep marketing iframe and relevant courseware view for email opt-in
Feature flagged. Puts a checkbox in the iframe. The iframe uses an organization_full_name parameter forwarded from Drupal by the courseware views and POSTs an email_opt_in parameter to the student views, preserving it on 403.
2014-12-01 10:30:16 -05:00
David Baumgold
8eff442752 mitxmako => edxmako 2013-12-03 14:15:09 -05:00
David Baumgold
7db77dc525 Remove static_template_view tests 2013-07-09 12:54:50 -04:00
Ned Batchelder
3eec09b87a Merge pull request #216 from edx/ned/remove-unused-imports
Ned/remove unused imports
2013-06-20 14:15:31 -07:00
Calen Pennington
308fe26b65 Clean up pep8 E128 issues 2013-06-20 09:08:25 -04:00
Ned Batchelder
61b53713d2 Remove unused imports from lms, as detected by pylint. 2013-06-19 16:56:34 -04:00