class RosettaBaseMixin(object): """A mixin class for Rosetta's class-based views. It provides: * security (see decorated dispatch() method) * a property for the 'po_filter' url argument """ # Handle security in our mixin # NOTE: after we drop support for Django 1.8, we can employ these decorators # more cleanly on the class itself, rather than the dispatch() method. (See # the Django docs: https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class) @method_decorator(never_cache) @method_decorator(login_required) @method_decorator(user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL)) def dispatch(self, *args, **kwargs): return super(RosettaBaseMixin, self).dispatch(*args, **kwargs) @cached_property def po_filter(self): """Return the filter applied to all of the .po files under consideration to determine which file is currently being translated. Options are: 'all', 'django', 'third-party', 'project'. If the filter isn't in this list, throw a 404. """ po_filter = self.kwargs.get('po_filter') if po_filter not in {'all', 'django', 'third-party', 'project'}: raise Http404 return po_filter
from rosetta.conf import settings as rosetta_settings from rosetta.polib import pofile from rosetta.poutil import find_pos, pagination_range, timestamp_with_timezone from rosetta.signals import entry_changed, post_save from rosetta.storage import get_storage from rosetta.access import can_translate import re import rosetta import unicodedata import hashlib import os import six @never_cache @user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL) def home(request): """ Displays a list of messages to be translated """ def fix_nls(in_, out_): """Fixes submitted translations by filtering carriage returns and pairing newlines at the begging and end of the translated string with the original """ if 0 == len(in_) or 0 == len(out_): return out_ if "\r" in out_ and "\r" not in in_: out_ = out_.replace("\r", '')
from rosetta.poutil import find_pos, pagination_range, timestamp_with_timezone from rosetta.signals import entry_changed, post_save from rosetta.storage import get_storage from rosetta.access import can_translate, can_translate_language import json import re import rosetta import unicodedata import hashlib import os import six @never_cache @user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL) def home(request): """ Displays a list of messages to be translated """ def fix_nls(in_, out_): """Fixes submitted translations by filtering carriage returns and pairing newlines at the begging and end of the translated string with the original """ if 0 == len(in_) or 0 == len(out_): return out_ if "\r" in out_ and "\r" not in in_: out_ = out_.replace("\r", '') if "\n" == in_[0] and "\n" != out_[0]: