remove editor.utils because nearly nothing in it was used

This commit is contained in:
Laura Klünder 2017-11-30 15:52:02 +01:00
parent af93cd2aa2
commit 1f80f2daa6
5 changed files with 7 additions and 42 deletions

View file

@ -7,8 +7,7 @@ from django.db import models
from django.db.models import DecimalField, Field
from django.utils.translation import ugettext_lazy as _
from c3nav.editor.utils import is_created_pk
from c3nav.editor.wrappers import ModelInstanceWrapper
from c3nav.editor.wrappers import ModelInstanceWrapper, is_created_pk
from c3nav.mapdata.fields import I18nField, JSONField
from c3nav.mapdata.models.locations import LocationRedirect

View file

@ -18,8 +18,7 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from c3nav.editor.models.changedobject import ApplyToInstanceError, ChangedObject
from c3nav.editor.utils import is_created_pk
from c3nav.editor.wrappers import ModelInstanceWrapper, ModelWrapper
from c3nav.editor.wrappers import ModelInstanceWrapper, ModelWrapper, is_created_pk
from c3nav.mapdata.models import LocationSlug, MapUpdate
from c3nav.mapdata.models.locations import LocationRedirect
from c3nav.mapdata.utils.cache.changes import changed_geometries

View file

@ -1,36 +0,0 @@
from typing import Union
from django.db import models
def is_created_pk(pk):
return isinstance(pk, str) and pk.startswith('c') and pk[1:].isnumeric()
def get_current_obj(model, pk, only_field=None):
if is_created_pk(pk):
return model()
if only_field is not None:
return model.objects.only(only_field).get(pk=pk)
return model.objects.get(pk=pk)
def get_field_value(obj, field: Union[str, models.Field]):
lang = None
if isinstance(field, str):
name = field
model = type(obj)
if '__i18n__' in name:
orig_name, i18n, lang = name.split('__')
field = model._meta.get_field(orig_name)
else:
field = model._meta.get_field(name)
else:
name = field.name
try:
current_value = getattr(obj, field.attname)
except AttributeError:
current_value = field.to_prep_value(getattr(obj, field.name))
if lang:
current_value = current_value.get(lang, '')
return current_value

View file

@ -13,8 +13,8 @@ from django.utils.translation import get_language_info
from c3nav.editor.forms import ChangeSetForm, RejectForm
from c3nav.editor.models import ChangeSet
from c3nav.editor.utils import is_created_pk
from c3nav.editor.views.base import sidebar_view
from c3nav.editor.wrappers import is_created_pk
from c3nav.mapdata.models.locations import LocationRedirect, LocationSlug

View file

@ -9,7 +9,6 @@ from django.db import models
from django.db.models import FieldDoesNotExist, Manager, ManyToManyRel, Prefetch, Q
from django.utils.functional import cached_property
from c3nav.editor.utils import is_created_pk
from c3nav.mapdata.utils.models import get_submodels
@ -174,6 +173,10 @@ class ModelWrapper(BaseWrapper):
return '<ModelWrapper '+repr(self._obj.__name__)+'>'
def is_created_pk(pk):
return isinstance(pk, str) and pk.startswith('c') and pk[1:].isnumeric()
class ModelInstanceWrapper(BaseWrapper):
"""
Wraps a model instance. Don't use this directly, call a ModelWrapper instead / use ChangeSet.wrap().