mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Skip template checks in Fields screen (#2670)
This commit is contained in:
parent
9b8dfd2860
commit
c2b1ab5eb0
5 changed files with 23 additions and 9 deletions
|
@ -14,7 +14,8 @@ service NotetypesService {
|
|||
rpc AddNotetype(Notetype) returns (collection.OpChangesWithId);
|
||||
rpc UpdateNotetype(Notetype) returns (collection.OpChanges);
|
||||
rpc AddNotetypeLegacy(generic.Json) returns (collection.OpChangesWithId);
|
||||
rpc UpdateNotetypeLegacy(generic.Json) returns (collection.OpChanges);
|
||||
rpc UpdateNotetypeLegacy(UpdateNotetypeLegacyRequest)
|
||||
returns (collection.OpChanges);
|
||||
rpc AddOrUpdateNotetype(AddOrUpdateNotetypeRequest) returns (NotetypeId);
|
||||
rpc GetStockNotetypeLegacy(StockNotetype) returns (generic.Json);
|
||||
rpc GetNotetype(NotetypeId) returns (Notetype);
|
||||
|
@ -134,6 +135,11 @@ message AddOrUpdateNotetypeRequest {
|
|||
bool skip_checks = 3;
|
||||
}
|
||||
|
||||
message UpdateNotetypeLegacyRequest {
|
||||
bytes json = 1;
|
||||
bool skip_checks = 2;
|
||||
}
|
||||
|
||||
message StockNotetype {
|
||||
enum Kind {
|
||||
KIND_BASIC = 0;
|
||||
|
|
|
@ -217,11 +217,15 @@ class ModelManager(DeprecatedNamesMixin):
|
|||
if existing_id is not None and existing_id != notetype["id"]:
|
||||
notetype["name"] += f"-{checksum(str(time.time()))[:5]}"
|
||||
|
||||
def update_dict(self, notetype: NotetypeDict) -> OpChanges:
|
||||
def update_dict(
|
||||
self, notetype: NotetypeDict, skip_checks: bool = False
|
||||
) -> OpChanges:
|
||||
"Update a NotetypeDict. Caller will need to re-load notetype if new fields/cards added."
|
||||
self._remove_from_cache(notetype["id"])
|
||||
self.ensure_name_unique(notetype)
|
||||
return self.col._backend.update_notetype_legacy(to_json_bytes(notetype))
|
||||
return self.col._backend.update_notetype_legacy(
|
||||
json=to_json_bytes(notetype), skip_checks=skip_checks
|
||||
)
|
||||
|
||||
def _mutate_after_write(self, notetype: NotetypeDict) -> None:
|
||||
# existing code expects the note type to be mutated to reflect
|
||||
|
|
|
@ -289,9 +289,9 @@ class FieldDialog(QDialog):
|
|||
tooltip(tr.card_templates_changes_saved(), parent=self.parentWidget())
|
||||
QDialog.accept(self)
|
||||
|
||||
update_notetype_legacy(parent=self.mw, notetype=self.model).success(
|
||||
on_done
|
||||
).run_in_background()
|
||||
update_notetype_legacy(
|
||||
parent=self.mw, notetype=self.model, skip_checks=True
|
||||
).success(on_done).run_in_background()
|
||||
|
||||
def onHelp(self) -> None:
|
||||
openHelp(HelpPage.CUSTOMIZING_FIELDS)
|
||||
|
|
|
@ -22,8 +22,11 @@ def update_notetype_legacy(
|
|||
*,
|
||||
parent: QWidget,
|
||||
notetype: NotetypeDict,
|
||||
skip_checks: bool = False,
|
||||
) -> CollectionOp[OpChanges]:
|
||||
return CollectionOp(parent, lambda col: col.models.update_dict(notetype))
|
||||
return CollectionOp(
|
||||
parent, lambda col: col.models.update_dict(notetype, skip_checks)
|
||||
)
|
||||
|
||||
|
||||
def remove_notetype(
|
||||
|
|
|
@ -53,11 +53,12 @@ impl crate::services::NotetypesService for Collection {
|
|||
|
||||
fn update_notetype_legacy(
|
||||
&mut self,
|
||||
input: generic::Json,
|
||||
input: anki_proto::notetypes::UpdateNotetypeLegacyRequest,
|
||||
) -> error::Result<anki_proto::collection::OpChanges> {
|
||||
let legacy: NotetypeSchema11 = serde_json::from_slice(&input.json)?;
|
||||
let mut notetype: Notetype = legacy.into();
|
||||
self.update_notetype(&mut notetype, false).map(Into::into)
|
||||
self.update_notetype(&mut notetype, input.skip_checks)
|
||||
.map(Into::into)
|
||||
}
|
||||
|
||||
fn add_or_update_notetype(
|
||||
|
|
Loading…
Reference in a new issue