def refresh_attempts(self, attempts=None, student_visible=None, refresh_all=False): """Bulk-refresh all missing assignment data.""" attempt_keys = [] students = self.students.values() if attempts is None: if student_visible is not None: students = list(filter(student_visible, students)) for user in students: for assignment_id, assignment in user.assignments.items(): if refresh_all or assignment.cached_attempts is None: attempt_keys.append((user.id, assignment_id)) else: attempt_ids = set(attempt.id for attempt in attempts) for user in students: for assignment_id, assignment in user.assignments.items(): a = assignment.cached_attempts or [] if any(attempt.id in attempt_ids for attempt in a): attempt_keys.append((user.id, assignment_id)) if not attempt_keys: return logger.info("Fetching %d attempt list%s", len(attempt_keys), '' if len(attempt_keys) == 1 else 's') attempt_data = dwr_get_attempts_info(self.session, attempt_keys) for (user_id, aid), attempts in zip(attempt_keys, attempt_data): self.students[user_id]['assignments'][aid]['attempts'] = attempts
def refresh(self): logger.info("Refresh gradebook") self.gradebook.refresh() if not self.attempt_state: self.attempt_state = {} self.groups = fetch_groups(self.session) self.autosave()
def refresh_attempt_files(self, attempt): assert isinstance(attempt, Attempt) logger.info("Fetch details for attempt %s", attempt) new_state = fetch_attempt( self.session, attempt.id, attempt.assignment.group_assignment) st = self.get_attempt_state(attempt, create=True) st.update(new_state) self.autosave()
def refresh(self, **kwargs): logger.info("Refresh gradebook") self.gradebook.refresh(student_visible=self.get_student_visible, **kwargs) if not self.attempt_state: self.attempt_state = {} if self.should_refresh_groups(): self.refresh_groups() self.autosave()
def refresh(self, **kwargs): logger.info("Refresh gradebook") self.gradebook.refresh( student_visible=self.get_student_visible, **kwargs) if not self.attempt_state: self.attempt_state = {} if self.should_refresh_groups(): self.refresh_groups() self.autosave()
def download_attempt_files(self, attempt): assert isinstance(attempt, Attempt) try: files = self.get_attempt_files(attempt) except NotYetSubmitted: logger.info('Skip downloading %s (not yet submitted)', attempt) return d = self.get_attempt_directory(attempt, create=True) for o in files: filename = o['filename'] outfile = os.path.join(d, filename) if os.path.exists(outfile): logger.info("Skip downloading %s %s (already exists)", attempt, outfile) elif 'contents' in o: s = o['contents'] if s and not s.endswith('\n'): s += '\n' with open(outfile, 'w') as fp: fp.write(s) logger.info("Storing %s %s (text content)", attempt, filename) else: download_link = o['download_link'] response = self.session.session.get(download_link, stream=True) logger.info("Download %s %s", attempt, outfile) with open(outfile, 'wb') as fp: for chunk in response.iter_content(chunk_size=64 * 1024): if chunk: fp.write(chunk) self.extract_archive(outfile)
def download_attempt_files(self, attempt): assert isinstance(attempt, Attempt) files = self.get_attempt_files(attempt) d = self.get_attempt_directory(attempt, create=True) for o in files: filename = o['filename'] outfile = os.path.join(d, filename) if os.path.exists(outfile): logger.info("Skip downloading %s %s (already exists)", attempt, outfile) elif 'contents' in o: s = o['contents'] if s and not s.endswith('\n'): s += '\n' with open(outfile, 'w') as fp: fp.write(s) logger.info("Storing %s %s (text content)", attempt, filename) else: download_link = o['download_link'] response = self.session.session.get(download_link, stream=True) logger.info("Download %s %s", attempt, outfile) with open(outfile, 'wb') as fp: for chunk in response.iter_content(chunk_size=64*1024): if chunk: fp.write(chunk) self.extract_archive(outfile)
def download_attempt_files(self, attempt): assert isinstance(attempt, Attempt) files = self.get_attempt_files(attempt) d = self.get_attempt_directory(attempt, create=True) for o in files: filename = o['filename'] outfile = os.path.join(d, filename) if os.path.exists(outfile): logger.info("%s already exists; skipping", outfile) continue if 'contents' in o: with open(outfile, 'w') as fp: fp.write(o['contents']) logger.info("Saving %s for attempt %s", filename, attempt) continue download_link = o['download_link'] response = self.session.session.get(download_link, stream=True) logger.info("Download %s %s (%s bytes)", attempt, outfile, response.headers.get('content-length')) with open(outfile, 'wb') as fp: for chunk in response.iter_content(chunk_size=64*1024): if chunk: fp.write(chunk) self.extract_archive(outfile)
def refresh_groups(self): logger.info("Fetching student group memberships") self.groups = fetch_groups(self.session) if any(k.startswith('Access the profile') for k in self.groups.keys()): raise Exception("fetch_groups returned bad usernames")