Commit bec6330c by Ned Batchelder

Merge pull request #251 from edx/ned/pylint-fixes

Ned/pylint fixes
parents 2fadd655 5a5d425e
...@@ -181,6 +181,6 @@ if SEGMENT_IO_KEY: ...@@ -181,6 +181,6 @@ if SEGMENT_IO_KEY:
##################################################################### #####################################################################
# Lastly, see if the developer has any local overrides. # Lastly, see if the developer has any local overrides.
try: try:
from .private import * from .private import * # pylint: disable=F0401
except ImportError: except ImportError:
pass pass
...@@ -3,7 +3,7 @@ import json ...@@ -3,7 +3,7 @@ import json
import logging import logging
import random import random
import re import re
import string import string # pylint: disable=W0402
import fnmatch import fnmatch
from textwrap import dedent from textwrap import dedent
......
from django.conf.urls import * from django.conf.urls import url, patterns
urlpatterns = patterns('', # nopep8 urlpatterns = patterns('', # nopep8
url(r'^$', 'heartbeat.views.heartbeat', name='heartbeat'), url(r'^$', 'heartbeat.views.heartbeat', name='heartbeat'),
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
django admin pages for courseware model django admin pages for courseware model
''' '''
from student.models import * from student.models import UserProfile, UserTestGroup, CourseEnrollmentAllowed
from student.models import CourseEnrollment, Registration, PendingNameChange
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User
admin.site.register(UserProfile) admin.site.register(UserProfile)
......
...@@ -37,7 +37,6 @@ rate -- messages per second ...@@ -37,7 +37,6 @@ rate -- messages per second
self.log_file.write(datetime.datetime.utcnow().isoformat() + ' -- ' + text + '\n') self.log_file.write(datetime.datetime.utcnow().isoformat() + ' -- ' + text + '\n')
def handle(self, *args, **options): def handle(self, *args, **options):
global log_file
(user_file, message_base, logfilename, ratestr) = args (user_file, message_base, logfilename, ratestr) = args
users = [u.strip() for u in open(user_file).readlines()] users = [u.strip() for u in open(user_file).readlines()]
......
...@@ -4,7 +4,7 @@ import json ...@@ -4,7 +4,7 @@ import json
import logging import logging
import random import random
import re import re
import string import string # pylint: disable=W0402
import urllib import urllib
import uuid import uuid
import time import time
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
django admin pages for courseware model django admin pages for courseware model
''' '''
from track.models import * from track.models import TrackingLog
from django.contrib import admin from django.contrib import admin
admin.site.register(TrackingLog) admin.site.register(TrackingLog)
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# Provides sympy representation. # Provides sympy representation.
import os import os
import string import string # pylint: disable=W0402
import re import re
import logging import logging
import operator import operator
......
...@@ -18,8 +18,6 @@ def load_function(path): ...@@ -18,8 +18,6 @@ def load_function(path):
def contentstore(name='default'): def contentstore(name='default'):
global _CONTENTSTORE
if name not in _CONTENTSTORE: if name not in _CONTENTSTORE:
class_ = load_function(settings.CONTENTSTORE['ENGINE']) class_ = load_function(settings.CONTENTSTORE['ENGINE'])
options = {} options = {}
......
...@@ -26,8 +26,6 @@ def load_function(path): ...@@ -26,8 +26,6 @@ def load_function(path):
def modulestore(name='default'): def modulestore(name='default'):
global _MODULESTORES
if name not in _MODULESTORES: if name not in _MODULESTORES:
class_ = load_function(settings.MODULESTORE[name]['ENGINE']) class_ = load_function(settings.MODULESTORE[name]['ENGINE'])
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
django admin pages for courseware model django admin pages for courseware model
''' '''
from courseware.models import * from courseware.models import StudentModule, OfflineComputedGrade, OfflineComputedGradeLog
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User from django.contrib.auth.models import User
......
...@@ -2,7 +2,7 @@ from django.conf import settings ...@@ -2,7 +2,7 @@ from django.conf import settings
from .mustache_helpers import mustache_helpers from .mustache_helpers import mustache_helpers
from functools import partial from functools import partial
from .utils import * from .utils import extend_content, merge_dict, render_mustache
import django_comment_client.settings as cc_settings import django_comment_client.settings as cc_settings
import pystache_custom as pystache import pystache_custom as pystache
......
import string import string # pylint: disable=W0402
import random import random
from django.contrib.auth.models import User from django.contrib.auth.models import User
......
...@@ -73,21 +73,17 @@ def get_discussion_id_map(course): ...@@ -73,21 +73,17 @@ def get_discussion_id_map(course):
""" """
return a dict of the form {category: modules} return a dict of the form {category: modules}
""" """
global _DISCUSSIONINFO
initialize_discussion_info(course) initialize_discussion_info(course)
return _DISCUSSIONINFO[course.id]['id_map'] return _DISCUSSIONINFO[course.id]['id_map']
def get_discussion_title(course, discussion_id): def get_discussion_title(course, discussion_id):
global _DISCUSSIONINFO
initialize_discussion_info(course) initialize_discussion_info(course)
title = _DISCUSSIONINFO[course.id]['id_map'].get(discussion_id, {}).get('title', '(no title)') title = _DISCUSSIONINFO[course.id]['id_map'].get(discussion_id, {}).get('title', '(no title)')
return title return title
def get_discussion_category_map(course): def get_discussion_category_map(course):
global _DISCUSSIONINFO
initialize_discussion_info(course) initialize_discussion_info(course)
return filter_unstarted_categories(_DISCUSSIONINFO[course.id]['category_map']) return filter_unstarted_categories(_DISCUSSIONINFO[course.id]['category_map'])
...@@ -141,8 +137,6 @@ def sort_map_entries(category_map): ...@@ -141,8 +137,6 @@ def sort_map_entries(category_map):
def initialize_discussion_info(course): def initialize_discussion_info(course):
global _DISCUSSIONINFO
course_id = course.id course_id = course.id
discussion_id_map = {} discussion_id_map = {}
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# django management command: dump grades to csv files # django management command: dump grades to csv files
# for use by batch processes # for use by batch processes
from instructor.offline_gradecalc import * from instructor.offline_gradecalc import offline_grade_calculation
from courseware.courses import get_course_by_id from courseware.courses import get_course_by_id
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import os import os
import sys import sys
import string import string # pylint: disable=W0402
import datetime import datetime
from getpass import getpass from getpass import getpass
import json import json
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
django admin pages for courseware model django admin pages for courseware model
''' '''
from psychometrics.models import * from psychometrics.models import PsychometricData
from django.contrib import admin from django.contrib import admin
admin.site.register(PsychometricData) admin.site.register(PsychometricData)
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
import json import json
from courseware.models import * from courseware.models import StudentModule
from track.models import * from track.models import TrackingLog
from psychometrics.models import * from psychometrics.models import PsychometricData
from xmodule.modulestore import Location from xmodule.modulestore import Location
from django.conf import settings from django.conf import settings
......
...@@ -14,7 +14,8 @@ from scipy.optimize import curve_fit ...@@ -14,7 +14,8 @@ from scipy.optimize import curve_fit
from django.conf import settings from django.conf import settings
from django.db.models import Sum, Max from django.db.models import Sum, Max
from psychometrics.models import * from psychometrics.models import PsychometricData
from courseware.models import StudentModule
from pytz import UTC from pytz import UTC
log = logging.getLogger("mitx.psychometrics") log = logging.getLogger("mitx.psychometrics")
...@@ -303,7 +304,7 @@ def generate_plots_for_problem(problem): ...@@ -303,7 +304,7 @@ def generate_plots_for_problem(problem):
def make_psychometrics_data_update_handler(course_id, user, module_state_key): def make_psychometrics_data_update_handler(course_id, user, module_state_key):
""" """
Construct and return a procedure which may be called to update Construct and return a procedure which may be called to update
the PsychometricsData instance for the given StudentModule instance. the PsychometricData instance for the given StudentModule instance.
""" """
sm, status = StudentModule.objects.get_or_create( sm, status = StudentModule.objects.get_or_create(
course_id=course_id, course_id=course_id,
......
...@@ -258,6 +258,6 @@ if SEGMENT_IO_LMS_KEY: ...@@ -258,6 +258,6 @@ if SEGMENT_IO_LMS_KEY:
##################################################################### #####################################################################
# Lastly, see if the developer has any local overrides. # Lastly, see if the developer has any local overrides.
try: try:
from .private import * from .private import * # pylint: disable=F0401
except ImportError: except ImportError:
pass pass
from .utils import * from .utils import CommentClientError, perform_request
from .thread import Thread from .thread import Thread, _url_for_flag_abuse_thread, _url_for_unflag_abuse_thread
import models import models
import settings import settings
......
...@@ -5,7 +5,7 @@ from .thread import Thread ...@@ -5,7 +5,7 @@ from .thread import Thread
from .user import User from .user import User
from .commentable import Commentable from .commentable import Commentable
from .utils import * from .utils import perform_request
import settings import settings
......
from .utils import *
import models import models
import settings import settings
......
def delete_threads(commentable_id, *args, **kwargs):
return _perform_request('delete', _url_for_commentable_threads(commentable_id), *args, **kwargs)
def get_threads(commentable_id, recursive=False, query_params={}, *args, **kwargs):
default_params = {'page': 1, 'per_page': 20, 'recursive': recursive}
attributes = dict(default_params.items() + query_params.items())
response = _perform_request('get', _url_for_threads(commentable_id), attributes, *args, **kwargs)
return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
def search_threads(course_id, recursive=False, query_params={}, *args, **kwargs):
default_params = {'page': 1, 'per_page': 20, 'course_id': course_id, 'recursive': recursive}
attributes = dict(default_params.items() + query_params.items())
response = _perform_request('get', _url_for_search_threads(), attributes, *args, **kwargs)
return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
def search_similar_threads(course_id, recursive=False, query_params={}, *args, **kwargs):
default_params = {'course_id': course_id, 'recursive': recursive}
attributes = dict(default_params.items() + query_params.items())
return _perform_request('get', _url_for_search_similar_threads(), attributes, *args, **kwargs)
def search_recent_active_threads(course_id, recursive=False, query_params={}, *args, **kwargs):
default_params = {'course_id': course_id, 'recursive': recursive}
attributes = dict(default_params.items() + query_params.items())
return _perform_request('get', _url_for_search_recent_active_threads(), attributes, *args, **kwargs)
def search_trending_tags(course_id, query_params={}, *args, **kwargs):
default_params = {'course_id': course_id}
attributes = dict(default_params.items() + query_params.items())
return _perform_request('get', _url_for_search_trending_tags(), attributes, *args, **kwargs)
def create_user(attributes, *args, **kwargs):
return _perform_request('post', _url_for_users(), attributes, *args, **kwargs)
def update_user(user_id, attributes, *args, **kwargs):
return _perform_request('put', _url_for_user(user_id), attributes, *args, **kwargs)
def get_threads_tags(*args, **kwargs):
return _perform_request('get', _url_for_threads_tags(), {}, *args, **kwargs)
def tags_autocomplete(value, *args, **kwargs):
return _perform_request('get', _url_for_threads_tags_autocomplete(), {'value': value}, *args, **kwargs)
def create_thread(commentable_id, attributes, *args, **kwargs):
return _perform_request('post', _url_for_threads(commentable_id), attributes, *args, **kwargs)
def get_thread(thread_id, recursive=False, *args, **kwargs):
return _perform_request('get', _url_for_thread(thread_id), {'recursive': recursive}, *args, **kwargs)
def update_thread(thread_id, attributes, *args, **kwargs):
return _perform_request('put', _url_for_thread(thread_id), attributes, *args, **kwargs)
def create_comment(thread_id, attributes, *args, **kwargs):
return _perform_request('post', _url_for_thread_comments(thread_id), attributes, *args, **kwargs)
def delete_thread(thread_id, *args, **kwargs):
return _perform_request('delete', _url_for_thread(thread_id), *args, **kwargs)
def get_comment(comment_id, recursive=False, *args, **kwargs):
return _perform_request('get', _url_for_comment(comment_id), {'recursive': recursive}, *args, **kwargs)
def update_comment(comment_id, attributes, *args, **kwargs):
return _perform_request('put', _url_for_comment(comment_id), attributes, *args, **kwargs)
def create_sub_comment(comment_id, attributes, *args, **kwargs):
return _perform_request('post', _url_for_comment(comment_id), attributes, *args, **kwargs)
def delete_comment(comment_id, *args, **kwargs):
return _perform_request('delete', _url_for_comment(comment_id), *args, **kwargs)
def vote_for_comment(comment_id, user_id, value, *args, **kwargs):
return _perform_request('put', _url_for_vote_comment(comment_id), {'user_id': user_id, 'value': value}, *args, **kwargs)
def undo_vote_for_comment(comment_id, user_id, *args, **kwargs):
return _perform_request('delete', _url_for_vote_comment(comment_id), {'user_id': user_id}, *args, **kwargs)
def vote_for_thread(thread_id, user_id, value, *args, **kwargs):
return _perform_request('put', _url_for_vote_thread(thread_id), {'user_id': user_id, 'value': value}, *args, **kwargs)
def undo_vote_for_thread(thread_id, user_id, *args, **kwargs):
return _perform_request('delete', _url_for_vote_thread(thread_id), {'user_id': user_id}, *args, **kwargs)
def get_notifications(user_id, *args, **kwargs):
return _perform_request('get', _url_for_notifications(user_id), *args, **kwargs)
def get_user_info(user_id, complete=True, *args, **kwargs):
return _perform_request('get', _url_for_user(user_id), {'complete': complete}, *args, **kwargs)
def subscribe(user_id, subscription_detail, *args, **kwargs):
return _perform_request('post', _url_for_subscription(user_id), subscription_detail, *args, **kwargs)
def subscribe_user(user_id, followed_user_id, *args, **kwargs):
return subscribe(user_id, {'source_type': 'user', 'source_id': followed_user_id})
follow = subscribe_user
def subscribe_thread(user_id, thread_id, *args, **kwargs):
return subscribe(user_id, {'source_type': 'thread', 'source_id': thread_id})
def subscribe_commentable(user_id, commentable_id, *args, **kwargs):
return subscribe(user_id, {'source_type': 'other', 'source_id': commentable_id})
def unsubscribe(user_id, subscription_detail, *args, **kwargs):
return _perform_request('delete', _url_for_subscription(user_id), subscription_detail, *args, **kwargs)
def unsubscribe_user(user_id, followed_user_id, *args, **kwargs):
return unsubscribe(user_id, {'source_type': 'user', 'source_id': followed_user_id})
unfollow = unsubscribe_user
def unsubscribe_thread(user_id, thread_id, *args, **kwargs):
return unsubscribe(user_id, {'source_type': 'thread', 'source_id': thread_id})
def unsubscribe_commentable(user_id, commentable_id, *args, **kwargs):
return unsubscribe(user_id, {'source_type': 'other', 'source_id': commentable_id})
def _perform_request(method, url, data_or_params=None, *args, **kwargs):
if method in ['post', 'put', 'patch']:
response = requests.request(method, url, data=data_or_params)
else:
response = requests.request(method, url, params=data_or_params)
if 200 < response.status_code < 500:
raise CommentClientError(response.text)
elif response.status_code == 500:
raise CommentClientUnknownError(response.text)
else:
if kwargs.get("raw", False):
return response.text
else:
return json.loads(response.text)
def _url_for_threads(commentable_id):
return "{prefix}/{commentable_id}/threads".format(prefix=PREFIX, commentable_id=commentable_id)
def _url_for_thread(thread_id):
return "{prefix}/threads/{thread_id}".format(prefix=PREFIX, thread_id=thread_id)
def _url_for_thread_comments(thread_id):
return "{prefix}/threads/{thread_id}/comments".format(prefix=PREFIX, thread_id=thread_id)
def _url_for_comment(comment_id):
return "{prefix}/comments/{comment_id}".format(prefix=PREFIX, comment_id=comment_id)
def _url_for_vote_comment(comment_id):
return "{prefix}/comments/{comment_id}/votes".format(prefix=PREFIX, comment_id=comment_id)
def _url_for_vote_thread(thread_id):
return "{prefix}/threads/{thread_id}/votes".format(prefix=PREFIX, thread_id=thread_id)
def _url_for_notifications(user_id):
return "{prefix}/users/{user_id}/notifications".format(prefix=PREFIX, user_id=user_id)
def _url_for_subscription(user_id):
return "{prefix}/users/{user_id}/subscriptions".format(prefix=PREFIX, user_id=user_id)
def _url_for_user(user_id):
return "{prefix}/users/{user_id}".format(prefix=PREFIX, user_id=user_id)
def _url_for_search_threads():
return "{prefix}/search/threads".format(prefix=PREFIX)
def _url_for_search_similar_threads():
return "{prefix}/search/threads/more_like_this".format(prefix=PREFIX)
def _url_for_search_recent_active_threads():
return "{prefix}/search/threads/recent_active".format(prefix=PREFIX)
def _url_for_search_trending_tags():
return "{prefix}/search/tags/trending".format(prefix=PREFIX)
def _url_for_threads_tags():
return "{prefix}/threads/tags".format(prefix=PREFIX)
def _url_for_threads_tags_autocomplete():
return "{prefix}/threads/tags/autocomplete".format(prefix=PREFIX)
def _url_for_users():
return "{prefix}/users".format(prefix=PREFIX)
from .utils import * from .utils import merge_dict, strip_blank, strip_none, extract, perform_request
from .utils import CommentClientError
import models import models
import settings import settings
......
from .utils import * from .utils import merge_dict, perform_request, CommentClientError
import models import models
import settings import settings
......
...@@ -41,6 +41,10 @@ disable= ...@@ -41,6 +41,10 @@ disable=
# W0142: Used * or ** magic # W0142: Used * or ** magic
I0011,C0301,W0141,W0142, I0011,C0301,W0141,W0142,
# Django makes classes that trigger these
# W0232: Class has no __init__ method
W0232,
# Might use these when the code is in better shape # Might use these when the code is in better shape
# C0302: Too many lines in module # C0302: Too many lines in module
# R0201: Method could be a function # R0201: Method could be a function
......
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