Django-TOC Library API

class tof.admin.ContentTypeAdmin(model, admin_site)[source]

Bases: ModelAdmin

get_search_results(request, queryset, search_term)[source]

Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.

has_add_permission(*args, **kwargs)[source]

Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.

has_change_permission(*args, **kwargs)[source]

Return True if the given request has permission to change the given Django model instance, the default implementation doesn’t examine the obj parameter.

Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to change the obj model instance. If obj is None, this should return True if the given request has permission to change any object of the given type.

has_delete_permission(*args, **kwargs)[source]

Return True if the given request has permission to delete the given Django model instance, the default implementation doesn’t examine the obj parameter.

Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to delete the obj model instance. If obj is None, this should return True if the given request has permission to delete any object of the given type.

property media
search_fields = ('app_label', 'model')
class tof.admin.LanguageAdmin(model, admin_site)[source]

Bases: ModelAdmin

get_search_results(request, queryset, search_term)[source]

Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.

has_view_permission(request, obj=None)[source]

Return True if the given request has permission to view the given Django model instance. The default implementation doesn’t examine the obj parameter.

If overridden by the user in subclasses, it should return True if the given request has permission to view the obj model instance. If obj is None, it should return True if the request has permission to view any object of the given type.

list_display = ('iso', 'is_active')
list_editable = ('is_active',)
property media
search_fields = ('iso',)
class tof.admin.ModelFieldIterator(field)[source]

Bases: object

property id
property name
class tof.admin.StaticMessageTranslationAdmin(model, admin_site)[source]

Bases: ActionViewsMixin, ModelAdmin

actions = (<function View.as_view.<locals>.view>, <function View.as_view.<locals>.view>)
fields = ('message', 'translation')
get_queryset(request)[source]

Return a QuerySet of all model instances that can be edited by the admin site. This is used by changelist_view.

has_add_permission(request)[source]

Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.

has_change_permission(request, obj=None)[source]

Return True if the given request has permission to change the given Django model instance, the default implementation doesn’t examine the obj parameter.

Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to change the obj model instance. If obj is None, this should return True if the given request has permission to change any object of the given type.

has_delete_permission(request, obj=None)[source]

Return True if the given request has permission to delete the given Django model instance, the default implementation doesn’t examine the obj parameter.

Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to delete the obj model instance. If obj is None, this should return True if the given request has permission to delete any object of the given type.

list_display = ('__str__', 'languages')
property media
readonly_fields = ('message', 'languages')
search_fields = ('message', 'translation')
class tof.admin.TranslatableFieldAdmin(model, admin_site)[source]

Bases: ModelAdmin

class Media[source]

Bases: object

css = {'screen': ('admin/css/empty_containers.css',)}
js = ('tof/js/autocomplete_utils.js',)
autocomplete_fields = ('content_type',)
delete_queryset(request, queryset)[source]

Given a queryset, delete it from the database.

fieldsets = ((None, {'fields': ['content_type', 'name']}),)
formfield_for_dbfield(db_field, request, **kwargs)[source]

Hook for specifying the form Field instance for a given database Field instance.

If kwargs are given, they’re passed to the form Field’s constructor.

get_changeform_initial_data(request)[source]

Get the initial form data from the request’s GET params.

get_queryset(request)[source]

Return a QuerySet of all model instances that can be edited by the admin site. This is used by changelist_view.

get_search_results(request, queryset, search_term)[source]

Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.

get_search_results_for_ajax(request, queryset, *__, **___)[source]
has_change_permission(*args, **kwargs)[source]

Return True if the given request has permission to change the given Django model instance, the default implementation doesn’t examine the obj parameter.

Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to change the obj model instance. If obj is None, this should return True if the given request has permission to change any object of the given type.

list_display = ('content_type', 'name')
property media
search_fields = ('content_type__model', 'name')
class tof.admin.TranslationAdmin(model, admin_site)[source]

Bases: ModelAdmin

autocomplete_fields = ('field', 'lang')
fieldsets = ((None, {'fields': (('field', 'lang'), 'object_id', 'value')}), ('hidden', {'classes': ['hidden'], 'fields': ['content_type']}))
form

alias of TranslationsForm

get_readonly_fields(request, obj)[source]

Hook for specifying custom readonly fields.

list_display = ('content_object', 'lang', 'field', 'value')
list_filter = ('content_type',)
property media
url_name = '%s:%s_%s_autocomplete'
class tof.admin.TranslationFormSet(data=None, files=None, instance=None, save_as_new=False, prefix=None, queryset=None, **kwargs)[source]

Bases: BaseGenericInlineFormSet

get_form_kwargs(index)[source]

Return additional keyword arguments for each individual formset form.

index will be None if the form being constructed is a new empty form.

class tof.admin.TranslationInline(parent_model, admin_site)[source]

Bases: TranslationInlineMixin, GenericInlineModelAdmin

property media
class tof.admin.TranslationInlineMixin[source]

Bases: object

autocomplete_fields = ('field', 'lang')
extra = 0
fields = ('field', 'lang', 'value')
form

alias of TranslationsInLineForm

formset

alias of TranslationFormSet

property media
model

alias of Translation

class tof.admin.TranslationStackedInline(parent_model, admin_site)[source]

Bases: TranslationInline, GenericStackedInline

property media
class tof.admin.TranslationTabularInline(parent_model, admin_site)[source]

Bases: TranslationInline, GenericTabularInline

property media
class tof.actions.GenerateTranslationJSONFileAction(**kwargs)[source]

Bases: ActionView

allow_empty = True
description = 'Generate translation JSON file for front'
finished_message = 'Success'
processing(*args, **kwargs)[source]
short_description = 'Generate translation JSON file for front'
class tof.actions.VueI18NExtractAction(**kwargs)[source]

Bases: ActionView

allow_empty = True
description = 'Extract translation from front'
finished_message = 'Success'
processing(*args, **kwargs)[source]
short_description = 'Extract translation from front'
class tof.apps.TofConfig(app_name, app_module)[source]

Bases: AppConfig

default_auto_field = 'django.db.models.BigAutoField'
name = 'tof'
ready()[source]

Override this method in subclasses to run code when Django starts.

release(*args, **kwargs)[source]
class tof.fields.TranslatableFieldFormField(fields, *args, **kwargs)[source]

Bases: MultiValueField

clean(values)[source]

Validate every value in the given list. A value is validated against the corresponding Field in self.fields.

For example, if this MultiValueField was instantiated with fields=(DateField(), TimeField()), clean() would call DateField.clean(value[0]) and TimeField.clean(value[1]).

cleaned_langs = None
compress(data_list)[source]

Return a single value for the given list of values. The values can be assumed to be valid.

For example, if this MultiValueField was instantiated with fields=(DateField(), TimeField()), this might return a datetime object created by combining the date and time in data_list.

hidden_widget

alias of TranslatableFieldHiddenWidget

widget

alias of TranslatableFieldWidget

class tof.forms.TranslationsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Bases: ModelForm

class Media[source]

Bases: object

js = ('tof/js/translation_form.js',)
base_fields = {}
declared_fields = {}
property media

Return all media required to render the widgets on this form.

class tof.forms.TranslationsInLineForm(*args, parent_object=None, **kwargs)[source]

Bases: ModelForm

base_fields = {}
declared_fields = {}
filter_ct(func)[source]
property media

Return all media required to render the widgets on this form.

class tof.mixins.ClassPatcherMixin[source]

Bases: object

classmethod patch_bases(target, *__)[source]
classmethod unpatch_bases(target, *args)[source]
class tof.mixins.InstancePatcherMixin[source]

Bases: ClassPatcherMixin

classmethod patch_bases(target, *args)[source]
classmethod unpatch_bases(target, *args)[source]
class tof.mixins.TofAdminMixin[source]

Bases: InstancePatcherMixin

static check_modeladmin(site, model)[source]

If model was registered with builtin ModelAdmin class we replace it with our TofModelAdmin. Otherwise patch brake MRO for already patched admins.

classmethod get_admins(model)[source]
get_form(request, obj=None, change=False, **kwargs)[source]
classmethod patch_unpatch(patch, model, fields)[source]
class tof.mixins.TofInlineMixin[source]

Bases: ClassPatcherMixin

get_formset(request, obj=None, **kwargs)[source]
classmethod get_inlines(model)[source]
classmethod patch_unpatch(patch, model, fields)[source]
classmethod set_inlines()[source]
class tof.mixins.TofModelAdmin(model, admin_site)[source]

Bases: ModelAdmin

property media
class tof.mixins.TranslationFieldMixin(*args, **kwargs)[source]

Bases: ClassPatcherMixin

collect(action)[source]
get_from_db(**kwargs)[source]
save(*args, **kwargs)[source]
class tof.mixins.TranslationFieldModelFormMixin(*args, **kwargs)[source]

Bases: ClassPatcherMixin

get_initial_for_field(field, field_name)[source]
class tof.mixins.TranslationManagerMixin[source]

Bases: InstancePatcherMixin

exclude(*args, **kwargs)[source]
expand(key, value)[source]
expand_arg(arg)[source]
filter(*args, **kwargs)[source]
get_queryset(*args, **kwargs)[source]
classmethod patch_bases(target, *args)[source]
run_function(func, *args, **kwargs)[source]
classmethod unpatch_bases(target, *args)[source]
tof.mixins.apply_mixins(patch, target_cls, fields)[source]

Add/remove to target_cls bases mixins, whose is necessary for work with tof.

tof.mixins.load_languages(request)[source]
class tof.mixins.tofQ(*args, _connector=None, _negated=False, **kwargs)[source]

Bases: Q

patch = True
tof.mixins.wrapper(func)[source]
class tof.models.Language(id, iso, is_active)[source]

Bases: Model

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

iso

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.ManagerFromLanguageQuerySet object>
translations

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class tof.models.LanguageQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

active()[source]
get_choices_by(*args, **kwargs)[source]
class tof.models.StaticMessageTranslation(id, message, translation)[source]

Bases: Model

CACHE = {}
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

base_translator_cls(message)
static gettext(translator, message)[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

languages()[source]
message

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.ManagerFromQuerySet object>
classmethod patch_djangotranslation()[source]
save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

translation

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class tof.models.ThroughLanguage(*args, **kwargs)[source]

Bases: Model

class Meta[source]

Bases: object

abstract = False
language

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

language_id
class tof.models.TranslatableField(id, name, content_type)[source]

Bases: Model

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

collect(instance, action)[source]
collect_created(saved, value, instance)[source]
static collect_updated(saved, value, *__)[source]
content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_type_id
delete(*args, **kwargs)[source]
get_saved(instance)[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_translatable(value)[source]
name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.ManagerFromTranslatableFieldQuerySet object>
patch_field(target_cls, fields)[source]
patch_unpatch(patch)[source]
pre_save(instance, *__)[source]
replaced_field = None
save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

translations

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

translator_cls

alias of TranslatableText

unpatch_field(target_cls, fields)[source]
class tof.models.TranslatableFieldQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

patch_fields()[source]
class tof.models.Translation(id, content_type, object_id, field, lang, value)[source]

Bases: Model

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_type_id
classmethod create(field, instance, lang, value)[source]
field

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

field_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lang

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lang_id
object_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.ManagerFromTranslationQueryset object>
update(lang, value)[source]
value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class tof.models.TranslationQueryset(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

bulk_delete(objs)[source]
save_translations(instance)[source]
class tof.utils.TranslatableText[source]

Bases: str

Class like a string but returns values depends on get_language.

property DEFAULT
property current
static get_lang()[source]
property iter
update(**kwargs)[source]
update_current(value)[source]
class tof.views.ActionView(**kwargs)[source]

Bases: FormView

ADDITION = 1
CHANGE = 2
DELETION = 3
admin = None
allow_empty = False
answer
as_button = False
classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

callback_template = None
callback_template_name_suffix = 'callback'
cancel(*__, **kwargs)[source]

Send cancel message during process and return None.

cancel_message = 'Action was cancelled'
classmethod check_permissions(request, admin=None)[source]
counter = 0
description = ''
dispatch(admin, request, queryset, *args, **kwargs)[source]
error(cause, **kwargs)[source]
error_message = 'Error {cause}'
extra_context = {'action_checkbox_name': '_selected_action'}
finished(*__, **kwargs)[source]

Send message after process and return None.

finished_message = ''
form_valid(*args, **kwargs)[source]

Make something ready befor processing.

get(request, *args, **kwargs)[source]

Handle GET requests: instantiate a blank version of the form.

classmethod get_as_tuple()[source]
get_callback_template()[source]
get_context_data(**kwargs)[source]

Insert the form into the context dict.

get_form(form_class=None, **kwargs)[source]

Return an instance of the form to be used in this view.

get_object()[source]
get_prefix()[source]

Return the prefix to use for forms.

get_queryset(*args, **kwargs)[source]
get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

info(info, **kwargs)[source]
log(obj, action_flag=2, **kwargs)[source]
logger

alias of LogEntry

model = None
classmethod name()[source]
classmethod patch_request_data(data)[source]
permissions = ()
permissions_message_error = "You don't have enough permissions"
post(request, *args, **kwargs)[source]

Handle POST requests: instantiate a form instance with the passed POST variables and then check if it’s valid.

processing(*args, **kwargs)[source]
processing_message = '{} was change'
queryset = None
classmethod render_as_button()[source]
request = None
setup(admin, request, queryset, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

short_description = ''
template_button = 'core/action_button.html'
template_name = 'core/confirmation.html'
template_name_suffix = 'confirmation'
warning(warning, **kwargs)[source]
class tof.views.ActionViewsMixin[source]

Bases: object

changelist_view(request, extra_context=None)[source]
get_actions(request)[source]
get_changelist_instance(request)[source]
class tof.views.YesNoForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]

Bases: YesNoMixIn, Form

base_fields = {'answer': <django.forms.fields.ChoiceField object>}
button_template = '<button type="{submit}" name="{name}" onclick="document.getElementById(`layer`).style.display = `block`;" value="{value}">{title}</button>'
declared_fields = {'answer': <django.forms.fields.ChoiceField object>}
property media

Return all media required to render the widgets on this form.

prefix = 'YesNoForm'
class tof.views.YesNoMixIn[source]

Bases: object

CHOICES = (('yes', "Yes, I'm sure"), ('no', "No, I'm not sure"))
NEGATIVE = 'no'
NEGATIVE_TEXT = "No, I'm not sure"
POSITIVE = 'yes'
POSITIVE_TEXT = "Yes, I'm sure"
answer_help_text = ''
answer_label = ''
button_negative_template = '<a href="#" class="button cancel-link">{title}</a>'
button_template = '<button type="{submit}" name="answer" value="{value}">{title}</button>'
form_template = 'core/extraform.html'
get_cleaned_data(*args, **kwargs)[source]
get_cleaned_field(field=None, **kwargs)[source]
get_field_name(field=None, **kwargs)[source]
get_request()[source]
is_positiv
method = 'POST'
process_url = ''
render_button_negative()[source]
render_button_positive()[source]
setup(*args, **kwargs)[source]
class tof.widgets.TranslatableFieldHiddenWidget(attrs=None)[source]

Bases: TranslatableFieldWidget

property media

Media for a multiwidget is the combination of all media of the subwidgets.

class tof.widgets.TranslatableFieldWidget(widgets, attrs=None)[source]

Bases: ValueFormatterMixin, MultiWidget

decompress(value)[source]

Return a list of decompressed values for the given compressed value. The given value can be assumed to be valid, but not necessarily non-empty.

get_context(name, value, attrs)[source]
id_for_label(id_)[source]

Return the HTML ID attribute of this Widget for use by a <label>, given the ID of the field. Return an empty string if no ID is available.

This hook is necessary because some widgets have multiple HTML elements and, thus, multiple IDs. In that case, this method should return an ID value that corresponds to the first ID in the widget’s tags.

input_type = 'text'
property media

Media for a multiwidget is the combination of all media of the subwidgets.

static rednder_subwidget(subwidget, **kwargs)[source]
template_name = 'tof/multiwidget.html'
value_from_datadict(data, __, name)[source]

Given a dictionary of data and this widget’s name, return the value of this widget or None if it’s not provided.

value_omitted_from_data(data, files, name)[source]
class tof.widgets.ValueFormatterMixin[source]

Bases: object

format_value(value)[source]