Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow im-/exporting with or without deck configs #2804

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode.dist/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"env": {
"PYTHONWARNINGS": "default",
"PYTHONPYCACHEPREFIX": "out/pycache",
"ANKIDEV": "1"
"ANKIDEV": "1",
"QTWEBENGINE_REMOTE_DEBUGGING": "8080",
"QTWEBENGINE_CHROMIUM_FLAGS": "--remote-allow-origins=http://localhost:8080"
},
"justMyCode": true,
"preLaunchTask": "ninja"
Expand Down
1 change: 1 addition & 0 deletions ftl/core/exporting.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exporting-include = <b>Include</b>:
exporting-include-html-and-media-references = Include HTML and media references
exporting-include-media = Include media
exporting-include-scheduling-information = Include scheduling information
exporting-include-deck-configs = Include deck presets
exporting-include-tags = Include tags
exporting-support-older-anki-versions = Support older Anki versions (slower/larger files)
exporting-notes-in-plain-text = Notes in Plain Text
Expand Down
6 changes: 5 additions & 1 deletion ftl/core/importing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ importing-notes-skipped-as-theyre-already-in = Notes skipped, as up-to-date copi
importing-notes-skipped-update-due-to-notetype = Notes not updated, as notetype has been modified since you first imported the notes: { $val }
importing-notes-updated-as-file-had-newer = Notes updated, as file had newer version: { $val }
importing-include-reviews = Include reviews
importing-also-import-progress = Also import any learning progress
importing-also-import-progress = Import any learning progress
importing-with-deck-configs = Import any deck presets
importing-updates = Updates
importing-include-reviews-help =
If enabled, any previous reviews that the deck sharer included will also be imported.
Otherwise, all cards will be imported as new cards.
importing-with-deck-configs-help =
If enabled, any deck options that the deck sharer included will also be imported.
Otherwise, all decks will be assigned the default preset.
importing-packaged-anki-deckcollection-apkg-colpkg-zip = Packaged Anki Deck/Collection (*.apkg *.colpkg *.zip)
importing-pauker-18-lesson-paugz = Pauker 1.8 Lesson (*.pau.gz)
# the '|' character
Expand Down
10 changes: 8 additions & 2 deletions proto/anki/import_export.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ message ImportAnkiPackageOptions {
ImportAnkiPackageUpdateCondition update_notes = 2;
ImportAnkiPackageUpdateCondition update_notetypes = 3;
bool with_scheduling = 4;
bool with_deck_configs = 5;
}

message ImportAnkiPackageRequest {
Expand Down Expand Up @@ -88,10 +89,15 @@ message ImportResponse {

message ExportAnkiPackageRequest {
string out_path = 1;
bool with_scheduling = 2;
ExportAnkiPackageOptions options = 2;
ExportLimit limit = 3;
}

message ExportAnkiPackageOptions {
bool with_scheduling = 1;
bool with_deck_configs = 2;
bool with_media = 3;
bool legacy = 4;
ExportLimit limit = 5;
}

message PackageMetadata {
Expand Down
13 changes: 3 additions & 10 deletions pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
StripHtmlMode = card_rendering_pb2.StripHtmlRequest
ImportLogWithChanges = import_export_pb2.ImportResponse
ImportAnkiPackageRequest = import_export_pb2.ImportAnkiPackageRequest
ExportAnkiPackageOptions = import_export_pb2.ExportAnkiPackageOptions
ImportCsvRequest = import_export_pb2.ImportCsvRequest
CsvMetadata = import_export_pb2.CsvMetadata
DupeResolution = CsvMetadata.DupeResolution
Expand Down Expand Up @@ -361,19 +362,11 @@ def import_anki_package(
return ImportLogWithChanges.FromString(log)

def export_anki_package(
self,
*,
out_path: str,
limit: ExportLimit,
with_scheduling: bool,
with_media: bool,
legacy_support: bool,
self, *, out_path: str, options: ExportAnkiPackageOptions, limit: ExportLimit
) -> int:
Copy link
Member

@dae dae Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(musing to myself: this is an API break. Given that, and we're adding new features, this next update might be better called 23.12 than 23.10.2)

return self._backend.export_anki_package(
out_path=out_path,
with_scheduling=with_scheduling,
with_media=with_media,
legacy=legacy_support,
options=options,
limit=pb_export_limit(limit),
)

Expand Down
17 changes: 16 additions & 1 deletion qt/aqt/forms/exporting.ui
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QCheckBox" name="include_deck_configs">
<property name="text">
<string>exporting_include_deck_configs</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QCheckBox" name="includeMedia">
<property name="text">
Expand Down Expand Up @@ -162,9 +172,14 @@
<tabstop>format</tabstop>
<tabstop>deck</tabstop>
<tabstop>includeSched</tabstop>
<tabstop>include_deck_configs</tabstop>
<tabstop>includeMedia</tabstop>
<tabstop>includeHTML</tabstop>
<tabstop>includeTags</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>includeDeck</tabstop>
<tabstop>includeNotetype</tabstop>
<tabstop>includeGuid</tabstop>
<tabstop>legacy_support</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down
24 changes: 20 additions & 4 deletions qt/aqt/import_export/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

import aqt.forms
import aqt.main
from anki.collection import DeckIdLimit, ExportLimit, NoteIdsLimit, Progress
from anki.collection import (
DeckIdLimit,
ExportAnkiPackageOptions,
ExportLimit,
NoteIdsLimit,
Progress,
)
from anki.decks import DeckId, DeckNameId
from anki.notes import NoteId
from aqt import gui_hooks
Expand Down Expand Up @@ -90,6 +96,9 @@ def setup(self, did: DeckId | None) -> None:
def exporter_changed(self, idx: int) -> None:
self.exporter = self.exporter_classes[idx]()
self.frm.includeSched.setVisible(self.exporter.show_include_scheduling)
self.frm.include_deck_configs.setVisible(
self.exporter.show_include_deck_configs
)
self.frm.includeMedia.setVisible(self.exporter.show_include_media)
self.frm.includeTags.setVisible(self.exporter.show_include_tags)
self.frm.includeHTML.setVisible(self.exporter.show_include_html)
Expand Down Expand Up @@ -137,6 +146,7 @@ def options(self, out_path: str) -> ExportOptions:
return ExportOptions(
out_path=out_path,
include_scheduling=self.frm.includeSched.isChecked(),
include_deck_configs=self.frm.include_deck_configs.isChecked(),
include_media=self.frm.includeMedia.isChecked(),
include_tags=self.frm.includeTags.isChecked(),
include_html=self.frm.includeHTML.isChecked(),
Expand Down Expand Up @@ -170,6 +180,7 @@ def filename(self) -> str:
class ExportOptions:
out_path: str
include_scheduling: bool
include_deck_configs: bool
include_media: bool
include_tags: bool
include_html: bool
Expand All @@ -184,6 +195,7 @@ class Exporter(ABC):
extension: str
show_deck_list = False
show_include_scheduling = False
show_include_deck_configs = False
show_include_media = False
show_include_tags = False
show_include_html = False
Expand Down Expand Up @@ -241,6 +253,7 @@ class ApkgExporter(Exporter):
extension = "apkg"
show_deck_list = True
show_include_scheduling = True
show_include_deck_configs = True
show_include_media = True
show_legacy_support = True

Expand All @@ -260,9 +273,12 @@ def on_success(count: int) -> None:
op=lambda col: col.export_anki_package(
out_path=options.out_path,
limit=options.limit,
with_scheduling=options.include_scheduling,
with_media=options.include_media,
legacy_support=options.legacy_support,
options=ExportAnkiPackageOptions(
with_scheduling=options.include_scheduling,
with_deck_configs=options.include_deck_configs,
with_media=options.include_media,
legacy=options.legacy_support,
),
),
success=on_success,
).with_backend_progress(export_progress_update).run_in_background()
Expand Down
1 change: 1 addition & 0 deletions rslib/src/config/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum BoolKey {
ShiftPositionOfExistingCards,
MergeNotetypes,
WithScheduling,
WithDeckConfigs,
Fsrs,
#[strum(to_string = "normalize_note_text")]
NormalizeNoteText,
Expand Down
Loading