Skip to content

Commit

Permalink
Add the replace_existing_version option on the admin side #12
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed May 27, 2024
1 parent 5c49a0c commit cc3c6ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ <h1>Add {% trans opts.verbose_name %} to a product</h1>
The Product provides you with a group of {% trans opts.verbose_name_plural|title %} that are used together, so that
you can generate Attribution documentation for all of the {% trans opts.verbose_name_plural|title %} in that Product.
</p>
<p style="margin-bottom: 10px;">
<div style="margin-bottom: 10px;">
{{ form.non_field_errors }}
<label for="id_product">Product:</label>
{{ form.product.errors }}
{{ form.product }}
<div style="margin-top:15px;margin-bottom:15px;">
{{ form.replace_existing_version }}
{{ form.replace_existing_version.label }}
<p class="grp-help">{{ form.replace_existing_version.help_text }}</p>
</div>
{% if perms.product_portfolio.add_product %}
<a href="{% url 'admin:product_portfolio_product_add' %}" class="add-another"></a>
{% endif %}
{{ form.ct }}
{{ form.ids }}
</p>
</div>
<p id="description" style="margin-bottom: 10px;"></p>
<div class="grp-content-container g-d-c">
<div class="grp-module">
Expand Down
8 changes: 7 additions & 1 deletion component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,15 @@ def form_valid(self, form):
created_count, updated_count, unchanged_count = form.save()
model_name = self.model._meta.model_name
product_name = form.cleaned_data["product"].name
msg = f"{created_count} {model_name}(s) added to {product_name}."

msg = ""
if created_count:
msg = f"{created_count} {model_name}(s) added to {product_name}."
if updated_count:
msg += f" {updated_count} {model_name}(s) updated on {product_name}."
if unchanged_count:
msg += f" {unchanged_count} {model_name}(s) were already assigned."

messages.success(self.request, msg)
return super().form_valid(form)

Expand Down

0 comments on commit cc3c6ab

Please sign in to comment.