import django_tables2 as tables from dbsynce.models import * from dbsynce.models import * from django.contrib.auth import get_user_model from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ class TransactionsWalletTable(tables.Table): # id = tables.Column(order_by=True) id = tables.Column( verbose_name='#', orderable=False, attrs={ "td": {"width": "5%"} } ) wallet = tables.Column( verbose_name=_('Owner'), orderable=False, attrs={ "td": {"width": "15%"} } ) name_operation = tables.Column( verbose_name=_('Service'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) price = tables.Column( verbose_name=_('Points'), attrs={ "class": "row", "td": {"width": "10%"} } ) date_operation = tables.Column( verbose_name=_('Registration date'), attrs={ "td": {"width": "30%"} } ) is_carried_out = tables.BooleanColumn( verbose_name=_('Status'), orderable=False, yesno=_("Successful, not successful"), attrs={ "td": {"width": "20%"} } ) class Meta: # model = TransactionsWallets attrs = { "class": "table table-striped" } exclude = ( "balance_before", "amount", "metaservice_id", "transaction_type", "doc_num", "service_id" ) def render_name_operation(self, value, record): return format_html( "{}", record.get_absolute_url(), value ) class PartnersTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) legal_name = tables.Column( verbose_name=_('Legal entity'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) repr = tables.Column( accessor='repr.full_name', order_by=('repr.first_name', 'repr.last_name'), verbose_name=_('Responsible'), attrs={ "td": {"width": "15%"} } ) status = tables.Column( verbose_name=_('Status'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name='', attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) # paginate_by = 10 class Meta: model = Company attrs = { "class": "table table-layout-fixed" } exclude = ( 'inn', 'kpp', 'ogrn', 'bank_name', 'bik', 'ks', 'rs', 'address', 'requirements', 'id_metaservice', 'is_global', 'is_visible', 'ticket_status' ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id ) class ResourcesTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) # В user ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form user = tables.Column( accessor='user.get_full_name', order_by=('user.first_name', 'user.last_name'), verbose_name=_('Responsible'), attrs={ "td": {"width": "15%"} } ) status = tables.Column( verbose_name=_('Status'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name='', attrs={ 'th': {'scope': 'col'}, "td": {"width": "40%"} } ) # paginate_by = 10 class Meta: model = Resource attrs = { "class": "table table-layout-fixed" } exclude = ( 'id_metaservice', 'resource_type', 'requirements', 'is_global', 'is_visible', 'ticket_status' ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id ) # class ResourcesTable(tables.Table): # id = tables.Column( # verbose_name=_('ID'), # attrs={ # "td": {"width": "5%"} # } # ) # user = tables.Column( # accessor='user.get_full_name', # order_by=('user.first_name', 'user.last_name'), # verbose_name=_('Responsible'), # attrs={ # "td": {"width": "15%"} # } # ) # status = tables.Column( # verbose_name=_('Status'), # attrs={ # 'th': {'scope': 'col'}, # "td": {"width": "20%"} # } # ) # activation = tables.Column( # verbose_name=_('Активация'), # attrs={ # 'th': {'scope': 'col'}, # "td": {"width": "40%"} # Увеличим ширину для размещения 4 кнопок # } # ) # class Meta: # model = Resource # attrs = { # "class": "table table-layout-fixed custom-table" # Добавлен кастомный класс для стилей # } # exclude = ( # 'id_metaservice', # 'resource_type', # 'requirements', # 'is_global', # 'is_visible', # 'ticket_status' # ) # def render_activation(self, value, record): # # Чекбокс для текущего статуса # checkbox = format_html( # '', # record.id, record.id, 'checked' if record.status == 'active' else '' # ) # # 4 кнопки-картинки без href, полагаемся на AJAX # buttons = [ # format_html( # '' # 'Action 1', # record.id, self.get_image_url('logo.png') # ), # format_html( # '' # 'Action 2', # record.id, self.get_image_url('logo.png') # ), # format_html( # '' # 'Action 3', # record.id, self.get_image_url('logo.png') # ), # format_html( # '' # 'Action 4', # record.id, self.get_image_url('logo.png') # ) # ] # # Объединяем чекбокс и кнопки # return format_html('{} {}', checkbox, ' '.join(buttons)) # def get_image_url(self, filename): # # Путь к изображениям # return f"{settings.STATIC_URL}sharix_admin/img/{filename}" class ProvidersTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) user = tables.Column( accessor='user.full_name', order_by=('user.first_name', 'user.last_name'), verbose_name=_('Full Name'), attrs={ "td": {"width": "15%"} } ) status = tables.Column( verbose_name=_('Status'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name='', attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) paginate_by = 10 class Meta: model = Provider attrs = { "class": "table table-layout-fixed" } exclude = ( 'id_metaservice', 'gap', 'requirements', 'status', 'service_status', 'location_type', 'default_location', 'is_global', 'is_visible' ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id ) class ServiceTariffsTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) service_category = tables.LinkColumn( 'sharix_admin:service_tariff/edit/', verbose_name=_('Name of the tariff'), text=lambda record: record.service_category.caption, args=[tables.A('pk')], attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) ticket_status = tables.Column( verbose_name=_('Name of the service scheme'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name=_('Activity'), orderable=False, attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) class Meta: model = Service attrs = { "class": "table table-layout-fixed" } exclude = ( 'resource', 'price_type', 'price_min', 'price_amount', 'id_metaservice', 'requirements', 'price_km', 'is_global', 'is_visible', 'status' ) def render_check(self, value, record): if record.status == 'active': return format_html('_(Delete)') # def render_name_operation(self, value, record): # return format_html("{}", record.get_absolute_url(), value) class ServiceTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) service_category = tables.Column( verbose_name=_('Description of the service'), accessor='service_category.caption', attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"}} ) # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}}) # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}}) # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}}) price_km = tables.Column( verbose_name=_('Cost km.'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) price_min = tables.Column( verbose_name=_('Cost min.'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"}} ) price_amount = tables.Column( verbose_name=_('Cost of service'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) class Meta: model = Service attrs = { "class": "table table-layout-fixed" } exclude = ( 'resource', 'requirements', 'id_metaservice', 'price_type', 'ticket_status', 'is_global', 'is_visible' ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id ) class UserInfoTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) class Meta: model = get_user_model() attrs = { "class": "table table-layout-fixed" } exclude = ( 'password', 'phone_number', 'last_login', 'is_staff', 'is_superuser', 'date_joined' ) class PermissionsTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) user = tables.Column( accessor='user.full_name', order_by=('user.first_name', 'user.last_name'), verbose_name=_('User'), attrs={ "td": {"width": "15%"} } ) id_permissions = tables.Column( verbose_name=_('Permission'), attrs={ "td": {"width": "15%"} } ) status = tables.Column( verbose_name=_('Status'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name='', attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) # paginate_by = 10 class Meta: model = Permissions attrs = { "class": "table table-layout-fixed" } exclude = ( 'check_date', 'expire_date', 'check_level', 'checked_by', 'ticket_status' ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id ) class RelationshipTable(tables.Table): id = tables.Column( verbose_name=_('ID'), attrs={ "td": {"width": "5%"} } ) user_who = tables.Column( accessor='user_who.full_name', order_by=('user_who.first_name', 'user_who.last_name'), verbose_name=_('Initiator'), attrs={ "td": {"width": "15%"} } ) user_whom = tables.Column( accessor='user_whom.full_name', order_by=('user_whom.first_name', 'user_whom.last_name'), verbose_name=_('Goal'), attrs={ "td": {"width": "15%"} } ) neg_type = tables.Column( verbose_name=_('Neg Type'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) status = tables.Column( verbose_name=_('Status'), attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) check = tables.BooleanColumn( verbose_name='', attrs={ 'th': {'scope': 'col'}, "td": {"width": "20%"} } ) paginate_by = 10 class Meta: model = Relationship attrs = { "class": "table table-layout-fixed" } exclude = ( 'ticket_status', ) def render_check(self, value, record): if record.status == 'active': return format_html( '', record.id ) else: return format_html( '', record.id )