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:
|
class AnkiConnect:
|
||||||
|
_anki21_version = int(aqt.appVersion.split('.')[-1])
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log = None
|
self.log = None
|
||||||
logPath = util.setting('apiLogPath')
|
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'))
|
'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):
|
def logEvent(self, name, data):
|
||||||
if self.log is not None:
|
if self.log is not None:
|
||||||
@ -1064,8 +1072,7 @@ class AnkiConnect:
|
|||||||
if afmt:
|
if afmt:
|
||||||
ankiTemplate['afmt'] = afmt
|
ankiTemplate['afmt'] = afmt
|
||||||
|
|
||||||
models.save(ankiModel, True)
|
self.save_model(models, ankiModel)
|
||||||
models.flush()
|
|
||||||
|
|
||||||
|
|
||||||
@util.api()
|
@util.api()
|
||||||
@ -1077,8 +1084,7 @@ class AnkiConnect:
|
|||||||
|
|
||||||
ankiModel['css'] = model['css']
|
ankiModel['css'] = model['css']
|
||||||
|
|
||||||
models.save(ankiModel, True)
|
self.save_model(models, ankiModel)
|
||||||
models.flush()
|
|
||||||
|
|
||||||
|
|
||||||
@util.api()
|
@util.api()
|
||||||
@ -1104,8 +1110,7 @@ class AnkiConnect:
|
|||||||
if back and findText in tmpls['afmt']:
|
if back and findText in tmpls['afmt']:
|
||||||
checkForText = True
|
checkForText = True
|
||||||
tmpls['afmt'] = tmpls['afmt'].replace(findText, replaceText)
|
tmpls['afmt'] = tmpls['afmt'].replace(findText, replaceText)
|
||||||
self.collection().models.save(model, True)
|
self.save_model(self.collection().models, model)
|
||||||
self.collection().models.flush()
|
|
||||||
if checkForText:
|
if checkForText:
|
||||||
updatedModels += 1
|
updatedModels += 1
|
||||||
return updatedModels
|
return updatedModels
|
||||||
|
@ -218,7 +218,7 @@ class WebServer:
|
|||||||
['Access-Control-Allow-Origin', corsOrigin],
|
['Access-Control-Allow-Origin', corsOrigin],
|
||||||
['Access-Control-Allow-Headers', '*']
|
['Access-Control-Allow-Headers', '*']
|
||||||
]
|
]
|
||||||
body = ''.encode('utf-8');
|
body = ''.encode('utf-8')
|
||||||
|
|
||||||
for key, value in headers:
|
for key, value in headers:
|
||||||
if value is None:
|
if value is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user