Skip to content

Conversation

@stefansc1
Copy link

implements #283

Add new "AssetTemplate" model with page in Django admin.
Add "template" section to asset modal, collapsed by default.
In this section, a user can save a template for a) just this project or b) their account. In addition, they may request to make it available to all users. Users can give their templates a name and an optional description. For admin purposes, asset type, creation date, associated project and user are also saved. Asset data is saved as JSON in DB.
A user may also load an existing template (if one exists with a matching asset type and visibility), filling out all asset form fields. The asset form must still be saved manually (in case the user wants to make any changes, which has no effect on the template).

Differences to proposal, general observations:

  • currently, there is no place for a user to manage their templates. They can only add new ones, but not change existing ones. Only Django admins may manage templates, including making them publicly visible.
  • saving a template with the same name as another (regardless of different user or not) is allowed. This does not change the other template. Templates are differentiated in the database by an integer ID. I added the proposed suffixes anyway to better differentiate templates.
  • description is only shown in template dropdown selection as hover tooltip, creation date and user are not shown (but saved in DB)
  • as of now, the checkbox "request to make this standard" is not doing much. This needs some internal procedure. How do we want to handle these requests?
  • selected timeseries are saved and loaded as well, but plot does not refresh
  • problem: timeseries are referenced by ID. In the DB, they are linked to a user and a scenario (not a project). When deleting either that user or that scenario, the timeseries is deleted as well, invalidating all derived assets. This seems to be a general issue with how timeseries are saved and handled.

@stefansc1 stefansc1 requested a review from paulapreuss October 21, 2025 14:59
Copy link

@paulapreuss paulapreuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! 🚀
I think it will be a cool feature once it is done. I agree about the need to have some sort of management over the created template, I created a dedicated issue here #403. We can already use the changes in this PR to start testing on the staging server and collect feedback about how the feature should be further developed / how the handling should be for the things that are unclear. Once the functionality is clear, we can start to implement the design suggestions from #283.

Copy link

@paulapreuss paulapreuss Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you are adding the template fields in the raw html instead of implementing it through a ModelForm from AssetTemplate? That would probably be easier to style given our current formats and there is less maintenance to be done if we end up changing any of the fields.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the template code to be explicit and readable and did not intend to use a Django form to send template data back when saving. If it were part of AssetCreateForm, the fields would be rendered alongside the other fields, so I would have needed some more custom filters. If it were not (making this its own form), it's even more complicated, since the HTML is replaced and part of another form. And I would have needed to send that other form data for each request.
I found it easier to just build the necessary fields myself and then simply posting data back via fetch. Building new FormData is required because we need to differentiate between asset data and template data (like template name and description). I am reluctant to send both in the same payload and splitting information server-side. Easier to just dump the asset data in the frontend and appending that as a neat little package to our post, so the backend does not need to actually do inspection and can just save to DB. Also, building FormData from scratch is nothing new, the same mechanic is used when saving assets.
Styling should actually be easier because we have direct access to all fields, without Django magic in-between.

if (typeof value === "string")
data[key] = value;
});
const templateFormData = new FormData();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like here, for example, it seems like it would be cleaner to already have the form data instead of creating a new object here and populating it.

- make templates available for storage assets
- show templates even if saving asset failed
@stefansc1 stefansc1 requested a review from paulapreuss October 23, 2025 11:01
@stefansc1 stefansc1 requested review from Bachibouzouk and removed request for paulapreuss November 20, 2025 09:18
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

Successfully merging this pull request may close these issues.

Enable the creation of new components/fascades Design choice concerning components and default values

3 participants