Fix updateModelTemplates and updateModelStyling functionality on Anki 2.1.45 and later (#296)
* fix update functionality on anki 2.1.45+ * delete trailing semicolon in the statement
This commit is contained in:
parent
1db646c13e
commit
418ebcb0de
@ -55,6 +55,8 @@ from . import web, util
|
||||
#
|
||||
|
||||
class AnkiConnect:
|
||||
_anki21_version = int(aqt.appVersion.split('.')[-1])
|
||||
|
||||
def __init__(self):
|
||||
self.log = None
|
||||
logPath = util.setting('apiLogPath')
|
||||
@ -75,6 +77,12 @@ class AnkiConnect:
|
||||
'Failed to listen on port {}.\nMake sure it is available and is not in use.'.format(util.setting('webBindPort'))
|
||||
)
|
||||
|
||||
def save_model(self, models, ankiModel):
|
||||
if self._anki21_version < 45:
|
||||
models.save(ankiModel, True)
|
||||
models.flush()
|
||||
else:
|
||||
models.update_dict(ankiModel)
|
||||
|
||||
def logEvent(self, name, data):
|
||||
if self.log is not None:
|
||||
@ -1064,8 +1072,7 @@ class AnkiConnect:
|
||||
if afmt:
|
||||
ankiTemplate['afmt'] = afmt
|
||||
|
||||
models.save(ankiModel, True)
|
||||
models.flush()
|
||||
self.save_model(models, ankiModel)
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -1077,8 +1084,7 @@ class AnkiConnect:
|
||||
|
||||
ankiModel['css'] = model['css']
|
||||
|
||||
models.save(ankiModel, True)
|
||||
models.flush()
|
||||
self.save_model(models, ankiModel)
|
||||
|
||||
|
||||
@util.api()
|
||||
@ -1104,8 +1110,7 @@ class AnkiConnect:
|
||||
if back and findText in tmpls['afmt']:
|
||||
checkForText = True
|
||||
tmpls['afmt'] = tmpls['afmt'].replace(findText, replaceText)
|
||||
self.collection().models.save(model, True)
|
||||
self.collection().models.flush()
|
||||
self.save_model(self.collection().models, model)
|
||||
if checkForText:
|
||||
updatedModels += 1
|
||||
return updatedModels
|
||||
|
@ -218,7 +218,7 @@ class WebServer:
|
||||
['Access-Control-Allow-Origin', corsOrigin],
|
||||
['Access-Control-Allow-Headers', '*']
|
||||
]
|
||||
body = ''.encode('utf-8');
|
||||
body = ''.encode('utf-8')
|
||||
|
||||
for key, value in headers:
|
||||
if value is None:
|
||||
|
Loading…
Reference in New Issue
Block a user