hackforla / hackforla/knowledgebase

MISC: Include primary tool for asset group in asset group tools

未关闭
#82 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
complexity: missing draft feature: missing milestone: missing role: missing size: missing
主要语言
Python
星标
2
派生
5
PR 合并指标
30 天内没有已合并 PR

描述

## Dependencies
- #81

## Overview
As a user when I look at the tools associated with an asset group, I want to see the primary tool included

### Action Items
See Resources below
- [ ] Add logic so when an asset group is created the primary tool will be added to asset group tools
- [ ] Modify logic to do the same when updating an asset group

### How to Manually Verify
1. From the asset group screen, create an asset group with a primary tool
2. Review the list of tools on the asset group screen. It should include the primary tool
3. Update the asset group to refer to a different tool.
4. Review the list of tools on the asset group screen. Two tools should be listed.
5. Try to remove the tool from the asset group that was added in step 3. System should prevent you.
6. Remove the tool from the asset group that was added in step 1. This should be sucssessful.

### Automated Tests

### Resources/Instructions
elow is a summary of changes suggested by ChatGPT. See https://chat.openai.com/share/d20ee9b8-f664-4aee-bc3b-96c2c1abdf9f for the full conversion.

You can achieve this functionality in Django using signals, specifically the post_save signal. (Put this in a file called signals.py in models directory)

```
@receiver(post_save, sender=AssetGroup)
def add_primary_tool_to_asset_group_tool(sender, instance, created, **kwargs):
if created or 'primary_tool' in kwargs['update_fields']:
primary_tool = instance.primary_tool
if primary_tool:
AssetGroupTool.objects.get_or_create(asset_group=instance, tool=primary_tool)
```
In this code:
- @receiver(post_save, sender=AssetGroup) is a decorator that connects the signal handler function (add_primary_tool_to_asset_group_tool) to the post_save signal for the AssetGroup model.
- The add_primary_tool_to_asset_group_tool function checks if a new AssetGroup instance is created or if the primary_tool field is updated. If either condition is met and a primary tool is selected (primary_tool is not None), it adds that tool to the AssetGroupTool table associated with the AssetGroup.

Make sure to register the signal handler in your Django app's apps.py or any other appropriate place to ensure that Django recognizes it during startup. For Knowledge base app you would add following code to `class KnowledgebaseConfig`:
```
def ready(self):
import knowledgeable.models.signals
```
With these changes, whenever you create or update an AssetGroup instance with a primary tool selected, the corresponding entry will automatically be added to the AssetGroupTool table.

贡献指南

打开贡献指南

调研方向

首先定位 AssetGroup 和 AssetGroupTool 模型,以及现有的 asset-group 创建和更新路径。该 issue 建议在 models/signals.py 中添加一个 handler,并从 apps.py 中的 KnowledgebaseConfig.ready 注册它。使用列出的手动步骤验证主工具已添加、已更改的主工具无法删除,以及手动添加的工具可以删除。

由索引模型根据 Issue 内容生成。

评估

技术栈
django, python
领域
backend, database
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。