Skip to content

Commit d82def2

Browse files
author
Nikos Vasileiou
committed
Add support for CDS override_occurrences flag
1 parent 7e8d3d4 commit d82def2

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

tests/native/core/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def test_push_strings_reaches_cds_handler(
380380

381381
strings = [SourceString('a'), SourceString('b')]
382382
mytx = self._get_tx()
383-
mytx.push_source_strings(strings, False, True, True)
384-
mock_push_strings.assert_called_once_with(strings, False, True, True)
383+
mytx.push_source_strings(strings, False, True, True, True)
384+
mock_push_strings.assert_called_once_with(strings, False, True, True, True)
385385

386386
@patch('transifex.native.core.MemoryCache.update')
387387
@patch('transifex.native.core.CDSHandler.fetch_translations')

tests/native/django/test_commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def get_transifex_command():
3131
'without_tags_only',
3232
'dry_run',
3333
'override_tags',
34+
'override_occurrences',
3435
'do_not_keep_translations',
3536
'symlinks',
3637

transifex/native/cds.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def fetch_translations(self, language_code=None):
204204

205205
def push_source_strings(self, strings, purge=False,
206206
do_not_keep_translations=False,
207-
override_tags=False):
207+
override_tags=False,
208+
override_occurrences=False):
208209
"""Push source strings to CDS.
209210
210211
:param list(SourceString) strings: a list of `SourceString` objects
@@ -216,6 +217,8 @@ def push_source_strings(self, strings, purge=False,
216217
source strings of existing keys are updated. False preserves them.
217218
:param bool override_tags: True replaces all the tags of pushed strings.
218219
False appends them to existing tags.
220+
:param bool override_occurrences: True replaces all the occurrences of pushed strings.
221+
False appends them to existing occurrences.
219222
:return: the HTTP response object
220223
:rtype: requests.Response
221224
"""
@@ -238,6 +241,7 @@ def push_source_strings(self, strings, purge=False,
238241
'purge': purge,
239242
'keep_translations': not do_not_keep_translations,
240243
'override_tags': override_tags,
244+
'override_occurrences': override_occurrences,
241245
},
242246
}
243247
)

transifex/native/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def fetch_translations(self):
198198

199199
def push_source_strings(self, strings, purge=False,
200200
do_not_keep_translations=False,
201-
override_tags=False):
201+
override_tags=False,
202+
override_occurrences=False):
202203
"""Push the given source strings to the CDS.
203204
204205
:param list strings: a list of SourceString objects
@@ -209,13 +210,15 @@ def push_source_strings(self, strings, purge=False,
209210
source strings of existing keys are updated. False preserves them.
210211
:param bool override_tags: True replaces all the tags of pushed strings.
211212
False appends them to existing tags.
213+
:param bool override_occurrences: True replaces all the occurrences of pushed strings.
214+
False appends them to existing occurrences.
212215
:return: a tuple containing the status code and the content of the
213216
response
214217
:rtype: tuple
215218
"""
216219
self._check_initialization()
217220
response = self._cds_handler.push_source_strings(
218-
strings, purge, do_not_keep_translations, override_tags)
221+
strings, purge, do_not_keep_translations, override_tags, override_occurrences)
219222
return response.status_code, json.loads(response.content)
220223

221224
def get_push_status(self, job_path):

transifex/native/django/management/utils/push.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def add_arguments(self, subparsers):
6767
'--override-tags', action='store_true', dest='override_tags', default=False,
6868
help=('Override tags when pushing content'),
6969
)
70+
parser.add_argument(
71+
'--override-occurrences', action='store_true', dest='override_occurrences', default=False,
72+
help=('Override occurrences when pushing content'),
73+
)
7074
parser.add_argument(
7175
'--do-not-keep-translations', action='store_true', dest='do_not_keep_translations', default=False,
7276
help=('Remove translations when source strings change'),
@@ -99,6 +103,7 @@ def handle(self, *args, **options):
99103
self.without_tags_only = options['without_tags_only']
100104
self.dry_run = options['dry_run']
101105
self.override_tags = options['override_tags']
106+
self.override_occurrences = options['override_occurrences']
102107
self.do_not_keep_translations = options['do_not_keep_translations']
103108
self.no_wait = options['no_wait']
104109
self.key_generator = options['key_generator']
@@ -193,7 +198,8 @@ def push_strings(self):
193198
)
194199
status_code, response_content = tx.push_source_strings(
195200
self.string_collection.strings.values(), self.purge,
196-
self.do_not_keep_translations, self.override_tags
201+
self.do_not_keep_translations, self.override_tags,
202+
self.override_occurrences
197203
)
198204

199205
if self.no_wait:

0 commit comments

Comments
 (0)