Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action in related_view invoking action in show screen when i use show_cascade.html #2054

Open
vasudevkrish opened this issue Jun 9, 2023 · 2 comments

Comments

@vasudevkrish
Copy link

I am facing the issue in using show_cascade.html

I have 2 views(ContactModelView and GroupModelView) with actions and added ContactModelView as related_views in GroupModelView.
I am trying to invoke the actions of ContactModelView in GroupModelView show screen.
But, I see the action of GroupModelView is getting invoked.

view.py

from flask_appbuilder import action
from app import appbuilder
from ..model.models import Contact, ContactGroup
from flask_appbuilder import CompactCRUDMixin, ModelView
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask import redirect, render_template

class ContactModelView(ModelView):
datamodel = SQLAInterface(Contact)

label_columns = {'contact_group':'Contacts Group'}
list_columns = ['name','personal_cellphone','birthday']
show_fieldsets = [
    (
        'Summary',
        {'fields': ['name', 'address']}
    ),
    (
        'Personal Info',
        {'fields': ['birthday', 'personal_phone', 'personal_cellphone'], 'expanded': False}
    ),
]

@action("dispviewname", "Disp related view name", "Do you really display relatediew name?", "fa-rocket")
def myaction(self, items):
    print('action in related view')
    name = ''
    if isinstance(items, list):
        print('multi')
        name = items[0].name

    else:
        print('single')
        name = items.name
    return render_template("method3.html", para3=name, base_template=appbuilder.base_template,
                           appbuilder=appbuilder)

@action("muldelete", "Delete", "Delete all Really?", "fa-rocket")
def muldelete(self, items):
    if isinstance(items, list):
        print('multi')
        self.datamodel.delete_all(items)
        self.update_redirect()
    else:
        print('single')
        self.datamodel.delete(items)
    return redirect(self.get_redirect())

class GroupModelView(CompactCRUDMixin, ModelView):
datamodel = SQLAInterface(ContactGroup)

show_template = "appbuilder/general/model/show_cascade.html"
list_columns = ["name", "extra_col"]

@action("dispname", "Do something on this record", "Do you really want to show?", "fa-rocket")
def showaction(self, item):
    print('action in group model')
    return render_template("method3.html", para3=item.name, base_template=appbuilder.base_template,
                           appbuilder=appbuilder)


related_views = [ContactModelView]

appbuilder.add_view(
GroupModelView,
"Contact Group",
icon = "fa-envelope",
category = "Contacts"
)
appbuilder.add_view(
ContactModelView,
"List Contacts",
icon = "fa-envelope",
category = "Contacts"
)

models.py

from flask_appbuilder import Model
from sqlalchemy import Column, Date, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
class ContactGroup(Model):
id = Column(Integer, primary_key=True)
name = Column(String(50), unique=True, nullable=False)

def extra_col(self):
    return "EXTRA {0}".format(self.id)



def __repr__(self):
    return self.name

class Contact(Model):
id = Column(Integer, primary_key=True)
name = Column(String(150), unique = True, nullable=False)
address = Column(String(564), default='Street ')
birthday = Column(Date)
personal_phone = Column(String(20))
personal_cellphone = Column(String(20))
contact_group_id = Column(Integer, ForeignKey("contact_group.id"), nullable=False)
contact_group = relationship("ContactGroup")

def __repr__(self):
    return self.name
@ThomasP0815
Copy link
Contributor

I also faced the same problem !

@ThomasP0815
Copy link
Contributor

PR #2219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants