using virtual environment to develop your project

本文详细介绍了在Horizon项目中遇到的Virtualenv问题,如何解决,并提供了针对ironic client改进的方法。此外,文章还讨论了DataTable、Row、BatchAction、LinkAction、Form等组件的使用细节,以及如何在模板中正确处理数据。通过实例分析,读者可以更好地理解Horizon框架的工作原理和实现方式。

做horizon和其他项目联调的时候,遇到了一个问题折磨了我很久,由于我想改client的东西,比如ironic client或者nova client,可是我在client里面做的改动,在

virtual environment中就是不起作用,开始并不知道是virtual env的原因,编译代码,重启服务都不行,后来我推出virtual env时发现改动实际上是有效的,

于是我计入.venv/lib/python2.7/site-packages,顿时明白了,各个模块的client在这里,调用的时候是用virtual evn下面的client调用的,初衷可能是避免开发环境中没有

安装client。。。

终于找到原因了!


但是ironic 的client现在比较弱,返回数据的时候格式比较傻,比如调用vendor_passthru时,如果是node_vendor_passthru

就会返回<Node xxxx>

是driver_vendor_passthru就会返回<Driver xxx>,其实这很不合理,通过vendor_passthru返回的数据肯定是自己定义的结构,强加Node或者Driver的标志,

并不合适,本来想实现自己的方法返回原始数据,结果有上面virtual env的问题,干脆用正则表达式把数据滤出来,省得我去修改client了


由于使用字符串更加方便,又兼得dict的结构,使用eval将字符串转成dict


使用horizon时,表格和行的操作时,可能会对行操作点击时传入的数据比较疑惑,待续:

1. DataTable的子类

class TestTable(tables.DataTable):

    def get_object_id(self, datum):#datum是数据类
           return datum.id #row的id,以后row action时传入的id为此id


2. row类型

1.class UpdateRow(tables.Row):
    ajax = True

    def get_data(self, request, obj_id):#此处obj_id为数据类的id,上面table中指定了id的值
            return datum


3. BatchAction子类:

class Test(tables.BatchAction):
 
    def allowed(self, request, datum):#这里的datum是数据类       
    
    def action(self, request, obj_id):#这里的obj_id是row数据类的id


4. LinkAction子类:

class TestLinkAction(tables.LinkAction):

    def allowed(self, request, datum):#此处datum和BatchAction中一样,是数据类

5. Form使用:

class TestFormView(forms.ModalFormView):
   
    def get_context_data(self, **kwargs):
       kwargs是点击按钮后传入的数据,一般为{'obj_id':xxxxxxx}

       obj_id是什么值呢,根据定义的url中?P<obj_id>而来,如果url中pattern是image_id则此处为image_id

    @memoized.memoized_method
    def get_object(self):
       行数据,其中self.kwargs,和get_context_data中kwargs一致

    def get_initial(self):
        form中需要初始化一些数据,可能需要隐藏的row,这个时候将一些参数初始化传递到form中,

class TestForm(forms.SelfHandlingForm):

  def __init__(self, request, *args, **kwargs):
        super(TestForm, self).__init__(request, *args, **kwargs)     
        kwargs['initial']是上面get_initial中传入的内容

    def handle(self, request, data):

              data是表单中的数据,直接用data['A'], A为表单中行的key值, get_initial可以传入数据放置在隐藏row中,这时候也可以拿出来


6.template中的数据

class OverviewTab(tabs.Tab):
    name = _("Overview")
    slug = "overview"
    template_name = "xxx"

    def get_context_data(self, request):
          return {'datum': datum}

         template中传入的数据为datum,则在template中可以使用datum.property访问数据,对dict类型的数据,直接用datum.xxxx访问


其实这样的情况很多,刚接触新的类时,除了参考horizon现有的实现,另一个方法是直接在virtual env中使用“print”打印一下就知道各个字段

分别表示什么。


btw:被几个问题深深的坑了很久

1. 一般情况下,对horizon的代码改动,virtual env会自动重启,但有时候修改并没有生效,这个时候停掉virtual,重新启动service就可以了,被这个坑了很久!

2. 实现自己的form时,继承自forms.SelfHandlingForm,initial时候穿进去的key-value值,要保证key值和隐藏的row名称相同才可以!

image_id = forms.CharField(widget=forms.HiddenInput())

那么initial传进去的key一定要是image_id!




In this project, your team (a one-person team of yourself or a team of three or fewer students) will develop an interactive data app using streamlit and other data science packages we have learned in this semester to tell a story with real-world data. Your team should choose a dataset from Kaggle.com. Try to find the dataset with the following characteristics: has detailed data description and high quality (use Kaggle usability score as a reference) has real business value has enough data points (minimal 500) is not too large (use the following code to sample some data or use https://docs.streamlit.io/library/api-reference/performance/st.cache to cache the data) - NOTE: if the data file is too large, you may not be able to push it to Github - in real situation, a database should be used for large datasets. Sample Datasets Some sample datasets are listed below for your reference (you don’t have to choose those): NFT dataset (by me): https://www.kaggle.com/datasets/harrywang/crypto-coven TMDB 5000 Movie Dataset: https://www.kaggle.com/datasets/tmdb/tmdb-movie-metadata Top Spotify songs from 2010-2019: https://www.kaggle.com/datasets/leonardopena/top-spotify-songs-from-20102019-by-year Uber Fares Dataset: https://www.kaggle.com/datasets/yasserh/uber-fares-dataset TripAdvisor Restaurants Info for 31 Euro-Cities: https://www.kaggle.com/datasets/damienbeneschi/krakow-ta-restaurans-data-raw Requirements The app should help users understand your dataset and show useful insights about your dataset based on your analysis. You app should meet the following basic requirements: At least two different queries/questions and display the answers using the data science tools we learned. Some sample questions is shown below: (for housing dataset) Based on ocean proximity, analyze the relationship between the average income and average housing price, and draw some conclusions. (for the titanic dataset) Is gender affecting the survival rate? Do any other features (columns) significantly affect the survival rate? At least three different types of plots (such as line chart, histogram, etc.) must be developed to show some EDA results of your dataset (use legends, colors, labels, titles, as appropriate) At least two different type of filtering widgets (slider, input box, single or multi select, etc.) to interact with your dataset The code of your app must be pushed to a Github repo with a detailed readme file Your Github repo must be published using Github Pages as a website Your app must be fully deployed in Streamlit Cloud and fully functional
10-22
"Mstar Bin Tool"是一款专门针对Mstar系列芯片开发的固件处理软件,主要用于智能电视及相关电子设备的系统维护与深度定制。该工具包特别标注了"LETV USB SCRIPT"模块,表明其对乐视品牌设备具有兼容性,能够通过USB通信协议执行固件读写操作。作为一款专业的固件编辑器,它允许技术人员对Mstar芯片的底层二进制文件进行解析、修改与重构,从而实现系统功能的调整、性能优化或故障修复。 工具包中的核心组件包括固件编译环境、设备通信脚本、操作界面及技术文档等。其中"letv_usb_script"是一套针对乐视设备的自动化操作程序,可指导用户完成固件烧录全过程。而"mstar_bin"模块则专门处理芯片的二进制数据文件,支持固件版本的升级、降级或个性化定制。工具采用7-Zip压缩格式封装,用户需先使用解压软件提取文件内容。 操作前需确认目标设备采用Mstar芯片架构并具备完好的USB接口。建议预先备份设备原始固件作为恢复保障。通过编辑器修改固件参数时,可调整系统配置、增删功能模块或修复已知缺陷。执行刷机操作时需严格遵循脚本指示的步骤顺序,保持设备供电稳定,避免中断导致硬件损坏。该工具适用于具备嵌入式系统知识的开发人员或高级用户,在进行设备定制化开发、系统调试或维护修复时使用。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值