Commit 74ed4630 by E. Kolpakov

Addressing python review notes

parent 8caf30a5
...@@ -109,7 +109,7 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin): ...@@ -109,7 +109,7 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin):
""" """
Find out if any answer has an image, since it affects layout. Find out if any answer has an image, since it affects layout.
""" """
return any(value['img'] for value in dict(field).values()) return any(value['img'] for key, value in field)
@staticmethod @staticmethod
def markdown_items(items): def markdown_items(items):
...@@ -190,20 +190,23 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin): ...@@ -190,20 +190,23 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin):
Checks to see if the user has permissions to view private results. Checks to see if the user has permissions to view private results.
This only works inside the LMS. This only works inside the LMS.
""" """
if HAS_EDX_ACCESS and hasattr(self.runtime, 'user') and hasattr(self.runtime, 'course_id'): if not (HAS_EDX_ACCESS and hasattr(self.runtime, 'user') and hasattr(self.runtime, 'course_id')):
# Course staff users have permission to view results. return False
if has_access(self.runtime.user, 'staff', self, self.runtime.course_id):
return True # Course staff users have permission to view results.
else: if has_access(self.runtime.user, 'staff', self, self.runtime.course_id):
# Check if user is member of a group that is explicitly granted return True
# permission to view the results through django configuration.
group_names = getattr(settings, 'XBLOCK_POLL_EXTRA_VIEW_GROUPS', []) # Check if user is member of a group that is explicitly granted
if group_names: # permission to view the results through django configuration.
group_ids = self.runtime.user.groups.values_list('id', flat=True) group_names = getattr(settings, 'XBLOCK_POLL_EXTRA_VIEW_GROUPS', [])
return GroupProfile.objects.filter(group_id__in=group_ids, name__in=group_names).exists()
else: if not group_names:
return False return False
group_ids = self.runtime.user.groups.values_list('id', flat=True)
return GroupProfile.objects.filter(group_id__in=group_ids, name__in=group_names).exists()
@staticmethod @staticmethod
def get_max_submissions(data, result, private_results): def get_max_submissions(data, result, private_results):
""" """
...@@ -254,7 +257,7 @@ class PollBlock(PollBase): ...@@ -254,7 +257,7 @@ class PollBlock(PollBase):
we just clean it up on first access within the LMS, in case the studio we just clean it up on first access within the LMS, in case the studio
has made changes to the answers. has made changes to the answers.
""" """
answers = OrderedDict(self.answers) answers = dict(self.answers)
for key in answers.keys(): for key in answers.keys():
if key not in self.tally: if key not in self.tally:
self.tally[key] = 0 self.tally[key] = 0
...@@ -331,7 +334,6 @@ class PollBlock(PollBase): ...@@ -331,7 +334,6 @@ class PollBlock(PollBase):
context.update({ context.update({
'choice': choice, 'choice': choice,
# Offset so choices will always be True.
'answers': self.markdown_items(self.answers), 'answers': self.markdown_items(self.answers),
'question': markdown(self.question), 'question': markdown(self.question),
'private_results': self.private_results, 'private_results': self.private_results,
...@@ -531,7 +533,7 @@ class SurveyBlock(PollBase): ...@@ -531,7 +533,7 @@ class SurveyBlock(PollBase):
def student_view(self, context=None): def student_view(self, context=None):
""" """
The primary view of the PollBlock, shown to students The primary view of the SurveyBlock, shown to students
when viewing courses. when viewing courses.
""" """
if not context: if not context:
...@@ -654,8 +656,8 @@ class SurveyBlock(PollBase): ...@@ -654,8 +656,8 @@ class SurveyBlock(PollBase):
we just clean it up on first access within the LMS, in case the studio we just clean it up on first access within the LMS, in case the studio
has made changes to the answers. has made changes to the answers.
""" """
questions = OrderedDict(self.questions) questions = dict(self.questions)
answers = OrderedDict(self.answers) answers = dict(self.answers)
default_answers = {answer: 0 for answer in answers.keys()} default_answers = {answer: 0 for answer in answers.keys()}
for key in questions.keys(): for key in questions.keys():
if key not in self.tally: if key not in self.tally:
......
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