-
Notifications
You must be signed in to change notification settings - Fork 2
#17 display header in column #46
#17 display header in column #46
Conversation
Merge develop from uma-tech parrot
# Conflicts: # templates/admin/http_stubs/change_form.html # templates/admin/http_stubs/includes/fieldset.html
Codecov Report
@@ Coverage Diff @@
## develop #46 +/- ##
===========================================
+ Coverage 95.96% 96.32% +0.35%
===========================================
Files 5 5
Lines 124 136 +12
Branches 5 6 +1
===========================================
+ Hits 119 131 +12
Misses 4 4
Partials 1 1
Continue to review full report at Codecov.
|
@@ -16,7 +16,7 @@ | |||
{% else %} | |||
{{ field.label_tag }} | |||
{% if field.is_readonly %} | |||
<div class="readonly">{{ field.contents }}</div> | |||
{% if field.field.name == 'headers' %}<ul class="readonly">{% for header in field.contents|str_to_list:"', " %}<li>{{ header|cut:"'" }}</li>{% endfor %}</ul>{% else %}<div class="readonly">{{ field.contents }}</div>{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach looks extremely clumsy. With every change we just lay over one more layer of unreadable template code.
I'd suggest trying something else.
For the forms in general, django-crispy-forms is excellent.
And just for this case, for example, we may try using a separate field type or something.
But just adding ad-hoc conditions for every field will soon make the source harder to understand and maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, django-crispy-forms aren't not very good friends with simpleui, but if I used crispy I would make a template for this field.
I made custom change templates for every model. And set the attribute change_form_template in admin model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, unfortunately, I never worked with simpleui, and it's a long time since I've last worked with Django forms.
I need some time to experiment myself with Django built-in functionality and/or crispy.
Crispy forms allow to use any custom template for any field as far as I remember, although this might also look a bit clumsy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to leave it as it is.
http_stubs/templatetags/stub_tags.py
Outdated
@@ -16,3 +18,15 @@ def get_absolute_url_tag(context: Dict, url: Url) -> Url: | |||
:returns: absolute url | |||
""" | |||
return context.get('request').build_absolute_uri(url) | |||
|
|||
|
|||
@register.filter(name='headers_to_list') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: if we call function headers_to_list
, then we won't have to specify the name as the register argument. There's no need to give distinct names to the function and the filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this will break if some header contains separator. I think this is highly probable for the text headers, maybe using json module for proper loading of the headers would be more robust?..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
@register.filter(name='headers_to_list') | ||
@stringfilter | ||
def get_headers_list(headers: AnyStr, separator: AnyStr) -> List: | ||
"""Filter that creates a list from a string of headers(dict). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd start from Python str.split description because it is more clear. E.g.:
Return a list of the lines in the string representation of the request headers, using sep as the delimiter string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
http_stubs/templatetags/stub_tags.py
Outdated
def get_headers_list(headers: AnyStr, separator: AnyStr) -> List: | ||
"""Filter that creates a list from a string of headers(dict). | ||
|
||
:param headers: string of headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param headers: string of headers | |
:param headers: string representation of the request headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
http_stubs/templatetags/stub_tags.py
Outdated
"""Filter that creates a list from a string of headers(dict). | ||
|
||
:param headers: string of headers | ||
:param separator: separator to separate string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param separator: separator to separate string | |
:param separator: delimiter string |
(also from str.split docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted this part of code.
http_stubs/templatetags/stub_tags.py
Outdated
|
||
:param headers: string of headers | ||
:param separator: separator to separate string | ||
:returns: list of headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:returns: list of headers | |
:returns: list of individual headers string representation |
(nit: unsure, but list of headers is too vague in my opinion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
deploy/app/start-django-dev.sh
Outdated
@@ -2,4 +2,4 @@ | |||
|
|||
wait-for-it "${PARROT_DB_HOST:-parrot-database}":5432 -s -t 180 \ | |||
&& python /app/src/manage.py migrate --noinput \ | |||
&& python /app/src/manage.py runserver 0.0.0.0:8042 | |||
&& python /app/src/manage.py runserver 127.0.0.1:8042 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it should be in a separate PR or a debug change that made its way into production code. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
{% block writable_field %} | ||
{{ field.field }} | ||
{# added request url for path field(issue #35) #} | ||
{% if field.field.name == 'path' %}<div class="readonly"><div id="full-path">{% absolute field.field.value %}</div><div id="path-copied-alert">Скопировано!</div></div>{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cyrillic characters still remain. Also, HTML doesn't impose the requirement to have everything in one extremely long line.
HTML can be broken at almost any boundary, this can greatly enhance readability of this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks!
@PetrS12 could you please rebase this branch |
# Conflicts: # templates/admin/http_stubs/includes/fieldset.html
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
closes #17