Merge pull request #61 from jingtaozf/master

add support to modify fields of exist note.
This commit is contained in:
Alex Yatskov 2018-01-01 08:51:00 -08:00 committed by GitHub
commit c60b311eaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -424,6 +424,18 @@ class AnkiBridge:
if not note.dupeOrEmpty(): if not note.dupeOrEmpty():
return note return note
def updateNoteFields(self, params):
collection = self.collection()
if collection is None:
return
note = collection.getNote(params['id'])
if note is None:
raise Exception("Failed to get note:{}".format(params['id']))
for name, value in params['fields'].items():
if name in note:
note[name] = value
note.flush()
def addTags(self, notes, tags, add=True): def addTags(self, notes, tags, add=True):
self.startEditing() self.startEditing()
@ -1023,6 +1035,9 @@ class AnkiConnect:
return results return results
@webApi()
def updateNoteFields(self, note):
return self.anki.updateNoteFields(note)
@webApi() @webApi()
def canAddNotes(self, notes): def canAddNotes(self, notes):

View File

@ -763,6 +763,38 @@ guarantee that your application continues to function properly in the future.
} }
``` ```
#### Note Modification ####
* **updateNoteFields**
Modify the fields of an exist note.
*Sample request*:
```json
{
"action": "updateNoteFields",
"version": 5,
"params": {
"note": {
"id": 1514547547030,
"fields": {
"Front": "new front content",
"Back": "new back content"
},
}
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
#### Note Tags #### #### Note Tags ####
* **addTags** * **addTags**