diff options
author | Patrick Maia <patrickjourdanmaia@gmail.com> | 2015-02-10 19:56:57 +0000 |
---|---|---|
committer | Patrick Maia <patrickjourdanmaia@gmail.com> | 2015-02-10 19:57:28 +0000 |
commit | dcec274dd5d727f113bbc64a95e9fc0773829ce3 (patch) | |
tree | 26f1df7e101c100f68bb8b51c23b14145ebac3ad /service/pixelated/adapter | |
parent | f27a5ce3a56cb3e70adcaf21ad97d79e8c26330b (diff) |
Issue #276 - uses the old casing when an existing tag with different casing is posted
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/services/mail_service.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py index 40a7c6ff..5ef0a188 100644 --- a/service/pixelated/adapter/services/mail_service.py +++ b/service/pixelated/adapter/services/mail_service.py @@ -39,6 +39,7 @@ class MailService: reserved_words = self.tag_service.extract_reserved(new_tags) if len(reserved_words): raise ValueError('None of the following words can be used as tags: ' + ' '.join(reserved_words)) + new_tags = self._favor_existing_tags_casing(new_tags) mail = self.mail(mail_id) mail.update_tags(set(new_tags)) self.search_engine.index_mail(mail) @@ -48,6 +49,15 @@ class MailService: def _filter_white_space_tags(self, tags): return filter(bool, map(lambda e: e.strip(), tags)) + def _favor_existing_tags_casing(self, new_tags): + current_tags = map(lambda tag: tag['name'], self.search_engine.tags(query='', skip_default_tags=True)) + current_tags_lower = map(lambda tag: tag.lower(), current_tags) + + def _use_current_casing(new_tag_lower): + return current_tags[current_tags_lower.index(new_tag_lower)] + + return map(lambda new_tag: _use_current_casing(new_tag.lower()) if new_tag.lower() in current_tags_lower else new_tag, new_tags) + def mail(self, mail_id): return self.querier.mail(mail_id) |