Merge branch 'master' into storage-api
This commit is contained in:
commit
f12af86757
@ -22,6 +22,7 @@ import hashlib
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
@ -551,6 +552,18 @@ class AnkiBridge:
|
|||||||
return collection.models.allNames()
|
return collection.models.allNames()
|
||||||
|
|
||||||
|
|
||||||
|
def modelNamesAndIds(self):
|
||||||
|
models = {}
|
||||||
|
|
||||||
|
modelNames = self.modelNames()
|
||||||
|
for model in modelNames:
|
||||||
|
mid = self.collection().models.byName(model)['id']
|
||||||
|
mid = int(mid) # sometimes Anki stores the ID as a string
|
||||||
|
models[model] = mid
|
||||||
|
|
||||||
|
return models
|
||||||
|
|
||||||
|
|
||||||
def modelNameFromId(self, modelId):
|
def modelNameFromId(self, modelId):
|
||||||
collection = self.collection()
|
collection = self.collection()
|
||||||
if collection is not None:
|
if collection is not None:
|
||||||
@ -567,6 +580,37 @@ class AnkiBridge:
|
|||||||
return [field['name'] for field in model['flds']]
|
return [field['name'] for field in model['flds']]
|
||||||
|
|
||||||
|
|
||||||
|
def modelFieldsOnTemplates(self, modelName):
|
||||||
|
model = self.collection().models.byName(modelName)
|
||||||
|
|
||||||
|
if model is not None:
|
||||||
|
templates = {}
|
||||||
|
for template in model['tmpls']:
|
||||||
|
fields = []
|
||||||
|
|
||||||
|
for side in ['qfmt', 'afmt']:
|
||||||
|
fieldsForSide = []
|
||||||
|
|
||||||
|
# based on _fieldsOnTemplate from aqt/clayout.py
|
||||||
|
matches = re.findall('{{[^#/}]+?}}', template[side])
|
||||||
|
for match in matches:
|
||||||
|
# remove braces and modifiers
|
||||||
|
match = re.sub(r'[{}]', '', match)
|
||||||
|
match = match.split(":")[-1]
|
||||||
|
|
||||||
|
# for the answer side, ignore fields present on the question side + the FrontSide field
|
||||||
|
if match == 'FrontSide' or side == 'afmt' and match in fields[0]:
|
||||||
|
continue
|
||||||
|
fieldsForSide.append(match)
|
||||||
|
|
||||||
|
|
||||||
|
fields.append(fieldsForSide)
|
||||||
|
|
||||||
|
templates[template['name']] = fields
|
||||||
|
|
||||||
|
return templates
|
||||||
|
|
||||||
|
|
||||||
def getDeckConfig(self, deck):
|
def getDeckConfig(self, deck):
|
||||||
if not deck in self.deckNames():
|
if not deck in self.deckNames():
|
||||||
return False
|
return False
|
||||||
@ -907,11 +951,21 @@ class AnkiConnect:
|
|||||||
return self.anki.modelNames()
|
return self.anki.modelNames()
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def modelNamesAndIds(self):
|
||||||
|
return self.anki.modelNamesAndIds()
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def modelFieldNames(self, modelName):
|
def modelFieldNames(self, modelName):
|
||||||
return self.anki.modelFieldNames(modelName)
|
return self.anki.modelFieldNames(modelName)
|
||||||
|
|
||||||
|
|
||||||
|
@webApi
|
||||||
|
def modelFieldsOnTemplates(self, modelName):
|
||||||
|
return self.anki.modelFieldsOnTemplates(modelName)
|
||||||
|
|
||||||
|
|
||||||
@webApi
|
@webApi
|
||||||
def getDeckConfig(self, deck):
|
def getDeckConfig(self, deck):
|
||||||
return self.anki.getDeckConfig(deck)
|
return self.anki.getDeckConfig(deck)
|
||||||
|
Loading…
Reference in New Issue
Block a user