from filer.fields.image import FilerImageField from parler.models import TranslatableModel, TranslatedFields from aldryn_reversion.core import version_controlled_content from .utils import get_additional_styles # NOTE: We use LooseVersion and not StrictVersion because sometimes Aldryn uses # patched build with version numbers of the form X.Y.Z.postN. loose_version = LooseVersion(get_version()) if loose_version < LooseVersion('1.7.0'): # Prior to 1.7 it is pretty straight forward user_model = get_user_model() if user_model not in default_revision_manager.get_registered_models(): default_revision_manager.register(user_model) else: # otherwise it is a pain, but thanks to solution of getting model from # https://github.com/django-oscar/django-oscar/commit/c479a1 # we can do almost the same thing from the different side. from django.apps import apps from django.apps.config import MODELS_MODULE_NAME from django.core.exceptions import AppRegistryNotReady def get_model(app_label, model_name): """ Fetches a Django model using the app registry. This doesn't require that an app with the given app label exists, which makes it safe to call when the registry is being populated. All other methods to access models might raise an exception about the registry not being ready yet.
import_module('%s.%s' % (app_config.name, MODELS_MODULE_NAME)) # In order to account for case-insensitivity of model_name, # look up the model through a private API of the app registry. return apps.get_registered_model(app_label, model_name) else: # This must be a different case (e.g. the model really doesn't # exist). We just re-raise the exception. raise # now get the real user model model_app_name, model_model = user_model.split('.') user_model_object = get_model(model_app_name, model_model) # and try to register, if we have a registration error - that means that # it has been registered already try: default_revision_manager.register(user_model_object) except RegistrationError: pass def default_jobs_attachment_upload_to(instance, filename): date = now().strftime('%Y/%m') return join_path( 'attachments', date, str(uuid4()), get_valid_filename(filename) ) jobs_attachment_upload_to = getattr( settings, 'ALDRYN_JOBS_ATTACHMENT_UPLOAD_DIR', default_jobs_attachment_upload_to )
errors.append("row %d (validation). %s" % ( row_num, '; '.join(['%s: %s' % (i[0], ', '.join(i[1])) for i in e.message_dict.items()]))) except Exception, e: errors.append("row %d. %s" % (row_num, e)) else: rowOKCount += 1 except csv.Error, e: errors.append(_("row %(row)d (csv). %(raw)s") % {'row': row_num, 'raw': e}) except UnicodeError: errors.append(_("File, you are loading is not valid CSV.")) except Exception, e: errors.append(_("Import error: %s." % e)) if must_register: revision.register(Organization) return TemplateResponse(request, 'exmo2010/csv_import_log.html', { 'monitoring': monitoring, 'errors': errors, 'row_count': '{}/{}'.format(rowOKCount, row_num), }) @login_required @csrf_protect def monitoring_parameter_import(request, monitoring_pk): """ Импорт параметров из CSV. """