|
1 | 1 | import json |
2 | 2 | import typing |
| 3 | +import uuid |
3 | 4 |
|
4 | 5 | from classytags.arguments import Argument, MultiKeywordArgument |
5 | 6 | from classytags.core import Options, Tag |
|
11 | 12 | from django.contrib.contenttypes.models import ContentType |
12 | 13 | from django.core.serializers.json import DjangoJSONEncoder |
13 | 14 | from django.db import models |
| 15 | +from django.http import HttpRequest |
14 | 16 | from django.template.defaultfilters import safe |
15 | 17 | from django.utils.encoding import force_str |
16 | 18 | from django.utils.functional import Promise |
@@ -77,11 +79,14 @@ def get_attributes(attribute_field, *add_classes): |
77 | 79 | @register.simple_tag(takes_context=True) |
78 | 80 | def set_html_id(context: template.Context, instance: FrontendUIItem) -> str: |
79 | 81 | if instance.html_id is None: |
80 | | - request = context["request"] |
81 | | - key = "frontend_plugins_counter" |
82 | | - counter = getattr(request, key, 0) + 1 |
83 | | - instance.html_id = f"frontend-plugins-{counter}" |
84 | | - setattr(request, key, counter) |
| 82 | + request = context.get("request") |
| 83 | + if isinstance(request, HttpRequest): |
| 84 | + key = "frontend_plugins_counter" |
| 85 | + counter = getattr(request, key, 0) + 1 |
| 86 | + instance.html_id = f"frontend-plugins-{counter}" |
| 87 | + setattr(request, key, counter) |
| 88 | + else: |
| 89 | + instance.html_id = f"uuid4={uuid.uuid4()}" |
85 | 90 | return instance.html_id |
86 | 91 |
|
87 | 92 |
|
|
0 commit comments