Commit 628dff53 by David Baumgold

pylint fixing

parent c68895ca
# pylint: disable=W0401, W0511 # pylint: disable=W0401, W0511
"All view functions for contentstore, broken out into submodules"
# Disable warnings about import from wildcard # Disable warnings about import from wildcard
# All files below declare exports with __all__ # All files below declare exports with __all__
from .assets import * from .assets import *
......
...@@ -56,15 +56,15 @@ def assets_to_json_dict(assets): ...@@ -56,15 +56,15 @@ def assets_to_json_dict(assets):
thumbnail = asset.get("thumbnail_location") thumbnail = asset.get("thumbnail_location")
if thumbnail: if thumbnail:
obj["thumbnail"] = thumbnail obj["thumbnail"] = thumbnail
idInfo = asset.get("_id") id_info = asset.get("_id")
if idInfo: if id_info:
obj["id"] = "/{tag}/{org}/{course}/{revision}/{category}/{name}".format( obj["id"] = "/{tag}/{org}/{course}/{revision}/{category}/{name}".format(
org=idInfo.get("org", ""), org=id_info.get("org", ""),
course=idInfo.get("course", ""), course=id_info.get("course", ""),
revision=idInfo.get("revision", ""), revision=id_info.get("revision", ""),
tag=idInfo.get("tag", ""), tag=id_info.get("tag", ""),
category=idInfo.get("category", ""), category=id_info.get("category", ""),
name=idInfo.get("name", ""), name=id_info.get("name", ""),
) )
ret.append(obj) ret.append(obj)
return ret return ret
......
...@@ -234,7 +234,7 @@ def assignment_type_update(request, org, course, category, name): ...@@ -234,7 +234,7 @@ def assignment_type_update(request, org, course, category, name):
''' '''
location = Location(['i4x', org, course, category, name]) location = Location(['i4x', org, course, category, name])
if not has_access(request.user, location): if not has_access(request.user, location):
raise HttpResponseForbidden() return HttpResponseForbidden()
if request.method == 'GET': if request.method == 'GET':
return JsonResponse(CourseGradingModel.get_section_grader_type(location)) return JsonResponse(CourseGradingModel.get_section_grader_type(location))
......
""" """
Views related to operations on course objects Views related to operations on course objects
""" """
#pylint: disable=W0402
import json import json
import random import random
import string import string
...@@ -91,7 +92,9 @@ def course_index(request, org, course, name): ...@@ -91,7 +92,9 @@ def course_index(request, org, course, name):
@login_required @login_required
@expect_json @expect_json
def create_new_course(request): def create_new_course(request):
"""
Create a new course
"""
if not is_user_in_creator_group(request.user): if not is_user_in_creator_group(request.user):
raise PermissionDenied() raise PermissionDenied()
...@@ -401,15 +404,19 @@ def course_advanced_updates(request, org, course, name): ...@@ -401,15 +404,19 @@ def course_advanced_updates(request, org, course, name):
return JsonResponse(CourseMetadata.update_from_json(location, return JsonResponse(CourseMetadata.update_from_json(location,
request_body, request_body,
filter_tabs=filter_tabs)) filter_tabs=filter_tabs))
except (TypeError, ValueError) as e: except (TypeError, ValueError) as err:
return HttpResponseBadRequest("Incorrect setting format. " + str(e), content_type="text/plain") return HttpResponseBadRequest("Incorrect setting format. " + str(err), content_type="text/plain")
class TextbookValidationError(Exception): class TextbookValidationError(Exception):
"An error thrown when a textbook input is invalid"
pass pass
def validate_textbooks_json(text): def validate_textbooks_json(text):
"""
Validate the given text as representing a single PDF textbook
"""
try: try:
textbooks = json.loads(text) textbooks = json.loads(text)
except ValueError: except ValueError:
...@@ -426,7 +433,10 @@ def validate_textbooks_json(text): ...@@ -426,7 +433,10 @@ def validate_textbooks_json(text):
return textbooks return textbooks
def validate_textbook_json(textbook, used_ids=()): def validate_textbook_json(textbook):
"""
Validate the given text as representing a list of PDF textbooks
"""
if isinstance(textbook, basestring): if isinstance(textbook, basestring):
try: try:
textbook = json.loads(textbook) textbook = json.loads(textbook)
...@@ -443,6 +453,10 @@ def validate_textbook_json(textbook, used_ids=()): ...@@ -443,6 +453,10 @@ def validate_textbook_json(textbook, used_ids=()):
def assign_textbook_id(textbook, used_ids=()): def assign_textbook_id(textbook, used_ids=()):
"""
Return an ID that can be assigned to a textbook
and doesn't match the used_ids
"""
tid = Location.clean(textbook["tab_title"]) tid = Location.clean(textbook["tab_title"])
if not tid[0].isdigit(): if not tid[0].isdigit():
# stick a random digit in front # stick a random digit in front
...@@ -471,8 +485,8 @@ def textbook_index(request, org, course, name): ...@@ -471,8 +485,8 @@ def textbook_index(request, org, course, name):
elif request.method == 'POST': elif request.method == 'POST':
try: try:
textbooks = validate_textbooks_json(request.body) textbooks = validate_textbooks_json(request.body)
except TextbookValidationError as e: except TextbookValidationError as err:
return JsonResponse({"error": e.message}, status=400) return JsonResponse({"error": err.message}, status=400)
tids = set(t["id"] for t in textbooks if "id" in t) tids = set(t["id"] for t in textbooks if "id" in t)
for textbook in textbooks: for textbook in textbooks:
...@@ -518,8 +532,8 @@ def create_textbook(request, org, course, name): ...@@ -518,8 +532,8 @@ def create_textbook(request, org, course, name):
try: try:
textbook = validate_textbook_json(request.body) textbook = validate_textbook_json(request.body)
except TextbookValidationError as e: except TextbookValidationError as err:
return JsonResponse({"error": e.message}, status=400) return JsonResponse({"error": err.message}, status=400)
if not textbook.get("id"): if not textbook.get("id"):
tids = set(t["id"] for t in course_module.pdf_textbooks if "id" in t) tids = set(t["id"] for t in course_module.pdf_textbooks if "id" in t)
textbook["id"] = assign_textbook_id(textbook, tids) textbook["id"] = assign_textbook_id(textbook, tids)
...@@ -566,8 +580,8 @@ def textbook_by_id(request, org, course, name, tid): ...@@ -566,8 +580,8 @@ def textbook_by_id(request, org, course, name, tid):
elif request.method in ('POST', 'PUT'): elif request.method in ('POST', 'PUT'):
try: try:
new_textbook = validate_textbook_json(request.body) new_textbook = validate_textbook_json(request.body)
except TextbookValidationError as e: except TextbookValidationError as err:
return JsonResponse({"error": e.message}, status=400) return JsonResponse({"error": err.message}, status=400)
new_textbook["id"] = tid new_textbook["id"] = tid
if textbook: if textbook:
i = course_module.pdf_textbooks.index(textbook) i = course_module.pdf_textbooks.index(textbook)
......
...@@ -68,7 +68,7 @@ def preview_dispatch(request, preview_id, location, dispatch=None): ...@@ -68,7 +68,7 @@ def preview_dispatch(request, preview_id, location, dispatch=None):
def preview_component(request, location): def preview_component(request, location):
# TODO (vshnayder): change name from id to location in coffee+html as well. # TODO (vshnayder): change name from id to location in coffee+html as well.
if not has_access(request.user, location): if not has_access(request.user, location):
raise HttpResponseForbidden() return HttpResponseForbidden()
component = modulestore().get_item(location) component = modulestore().get_item(location)
......
...@@ -23,13 +23,11 @@ def user_author_string(user): ...@@ -23,13 +23,11 @@ def user_author_string(user):
If the first and last names are blank, uses the username instead. If the first and last names are blank, uses the username instead.
Assumes that the email is not blank. Assumes that the email is not blank.
''' '''
f = user.first_name if not user.first_name and not user.last_name:
l = user.last_name name = user.username
if f == '' and l == '': else:
f = user.username name = "{0} {1}".format(user.first_name, user.last_name)
return '{first} {last} <{email}>'.format(first=f, return "{name} <{email}>".format(name=name, email=user.email)
last=l,
email=user.email)
@login_required @login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment