Coverage for modules/org/openteacher/interfaces/qt/webServices/studyStackApi/studyStackApi : 70%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2012, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
"strict": "Y", "appId": "osrc5103", }) action, urllib.parse.urlencode(kwargs) ) #the JSON is escaped in an invalid way. This should fix it #(every slash other than in '\"' and '\\' is removed, conform #the JSON spec). r'("[^"]*)\\([^"\\])', r'\1\2', data )
stacks = self._get("categoryStackListJson", page=1, sortOrder="stars", categoryId=categoryId) stacks += self._get("categoryStackListJson", page=2, sortOrder="stars", categoryId=categoryId) return ((s["stackName"], s["id"]) for s in stacks)
stack = self._get("json", studyStackId=listId) items = [] for i, row in enumerate(stack["data"]): items.append({ "id": i, "questions": self._parse(row[0]), "answers": self._parse(row[1]), }) return { "list": { "title": stack["name"], "items": items, }, "resources": {}, }
global AbstractSelectDialog, BookSelectDialog, CategorySelectDialog, ListSelectDialog, Model
"""Choices should be an iterable object of tuples of size two, with in it first the text to display and second the value to return.
"""
return len(self._choices)
if not (index.isValid() and role == QtCore.Qt.DisplayRole): return
return self._choices[index.row()][0]
return self._choices[index.row()][1]
self._listView.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok, parent=self )
def chosenItems(self): return [self._model.getChoice(i) for i in self._listView.selectedIndexes()]
self.setWindowTitle(_("Select list")) self.label.setText(_("Please select a list"))
self._mm.mods(type="ui"), self._mm.mods(type="buttonRegister"), self._mm.mods(type="wordsStringParser"), self._mm.mods(type="loaderGui"), ) self._mm.mods(type="translator"), )
"all": x, "selfstudy": x, "student@home": x, "student@school": x, "teacher": x, "words-only": x, "code-documentation": x, "test-suite": x, "default": -1, }
global QtCore, QtWidgets except ImportError: return
except IndexError: pass else:
global _ global ngettext
#Install translator except IndexError: _, ngettext = str, lambda a, b, n: a if n == 1 else b else: self._mm.resourcePath("translations") )
#Translate all active dialogs
def _parse(self):
categoryId = dialog.chosenItems[0] with self._handlingWebErrors(): d = self._showDialog(ListSelectDialog(self._api.getLists(categoryId))) d.accepted.connect(lambda: self._loadSelectedLists(d))
with self._handlingWebErrors(): for listId in dialog.chosenItems: list = self._api.getList(listId) try: self._loadList(list) except NotImplementedError: return
#everything went well self._uiModule.statusViewer.show(_("The word list was imported from Study Stack successfully."))
def _handlingWebErrors(self): except urllib.error.URLError as e: #for debugging purposes logger.debug(e, exc_info=True) QtWidgets.QMessageBox.warning( self._uiModule.qtParent, _("No Study Stack connection"), _("Study Stack didn't accept the connection. Are you sure that your internet connection works and http://www.studystack.com/ is online?") )
self._modules.default("active", type="loaderGui").loadFromLesson("words", list)
|