Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the feedback app to improve code quality, reduce duplication, and enhance maintainability. The changes consolidate repetitive view logic, simplify control flow patterns, and modernize code conventions.
Key changes:
- Introduced a
generic_showfeedbackhelper function to eliminate duplicated permission checking and rendering logic across multiple views - Refactored
recordsignfeedbackto handle both glosses and morphemes through a single code path using anis_morphemeparameter - Simplified form handling patterns by inverting conditionals (checking for POST early and returning)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| signbank/feedback/views.py | Core refactoring: consolidated duplicate view logic, simplified control flow with early returns, modernized string formatting to f-strings |
| signbank/feedback/urls.py | Cleaned up imports by removing unused dependencies |
| signbank/feedback/templates/feedback/show_feedback_signs.html | Fixed display of sign languages to properly iterate and comma-separate values |
| signbank/feedback/models.py | Reorganized imports, simplified conditional expressions, removed unused __init__ method, updated to modern super() syntax |
| signbank/feedback/admin.py | Minor formatting cleanup removing extra blank lines |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
signbank/feedback/views.py
Outdated
| return render(request, template_name, context) | ||
|
|
||
|
|
||
| def generic_showfeedback(request: QueryDict, extra_context: dict, template_name: str) -> HttpResponse: |
There was a problem hiding this comment.
The request parameter should be typed as HttpRequest, not QueryDict. QueryDict is the type for request.GET and request.POST, not the request object itself.
signbank/feedback/views.py
Outdated
| extra_context = {'morphfb': (MorphemeFeedback.objects | ||
| .filter(morpheme__lemma__dataset__in=get_selected_datasets(request)) | ||
| .filter(status__in=('unread', 'read')))} | ||
| return generic_showfeedback(request, extra_context,"feedback/show_feedback_morphemes.html") |
There was a problem hiding this comment.
Missing space after comma before the template name argument.
signbank/feedback/views.py
Outdated
| else: | ||
| gloss = get_object_or_404(Gloss, id=glossid, archived=False) | ||
| return recordsignfeedback(request, glossid) | ||
| return recordsignfeedback(request, glossid, is_morpheme=False) |
There was a problem hiding this comment.
The parameter name glossid is inconsistent with the updated function signature which uses id. Consider renaming the parameter in glossfeedback and morphemefeedback to id for consistency.
signbank/feedback/views.py
Outdated
| value = request.POST.get('value', '') | ||
|
|
||
| (what, fbid) = field.split('_') | ||
| _, id = field.split('_') |
There was a problem hiding this comment.
The variable id shadows the function parameter with the same name. Use a different name like feedback_id to avoid confusion.
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(SignFeedbackForm, self).__init__(*args, **kwargs) | ||
| super().__init__(*args, **kwargs) |
There was a problem hiding this comment.
The MorphemeFeedbackForm.__init__ method was removed, but it should be retained if there's any initialization logic needed for consistency with other form classes. If truly unnecessary, this is fine.
|
A lot of improvements. The original code was very weird, especially now seeing it next to the new code.
Is this being used for the feedback? The code runs great! It looks like users have been using the feedback! Just that question about that function. I can't get the review thing to work for me. It won't let me comment in specific places. |
Woseseltops
left a comment
There was a problem hiding this comment.
Thanks for cleaning up! Almost 200 lines of code less with the same functionality must be a great improvement to maintainability :)
| </div> | ||
| <form action="{{PREFIX_URL}}/feedback/missingsign/delete/{{fb.pk}}" method='post'> | ||
| {% csrf_token %} | ||
| <input type='hidden' name='id' value='deletefeedbackmissingn_{{fb.pk}}'> |
There was a problem hiding this comment.
Are you sure this doesn't do anything? I would guess this is an essential parameter to communicate which feedback needs deleting.
There was a problem hiding this comment.
The ID of the Feedback instance that is to be deleted, is send through the url in the form action. As far as I can tell the hidden input is never used in
Global-signbank/signbank/feedback/views.py
Lines 207 to 226 in 39df090
There was a problem hiding this comment.
Yes, I couldn't find it either.
signbank/feedback/views.py
Outdated
| missing_sign_feedback = MissingSignFeedback(user=request.user) | ||
| if 'signlanguage' in form.cleaned_data: | ||
| missing_sign_feedback.signlanguage = form.cleaned_data['signlanguage'] | ||
| if 'video' in form.cleaned_data and form.cleaned_data['video'] is not None: | ||
| missing_sign_feedback.video = form.cleaned_data['video'] | ||
| if 'sentence' in form.cleaned_data and form.cleaned_data['sentence'] is not None: | ||
| missing_sign_feedback.sentence = form.cleaned_data['sentence'] | ||
| missing_sign_feedback.meaning = form.cleaned_data['meaning'] | ||
| missing_sign_feedback.comments = form.cleaned_data['comments'] |
There was a problem hiding this comment.
How about
cleaned_data = form.cleaned_data
missing_sign_feedback = MissingSignFeedback(
user=request.user,
meaning=cleaned_data['meaning'],
comments=cleaned_data['comments'],
signlanguage=cleaned_data.get('signlanguage'),
video=cleaned_data.get('video'),
sentence=cleaned_data.get('sentence')
)There was a problem hiding this comment.
Since the fields signlanguage, video and sentence can handle None as input (I checked), this should also work. It is a nice improvement. I will apply it.
|
This is the comments for my review. Not sure if you looked at these. @vanlummelhuizen can you check this code?
Can the above be deleted from the feedback? I'm working on the communication emails and there is a context variable that uses As well as other that use code:
This is actually WRONG, it yields:
(from the database) So the wrong thing is ending up in the emails... |
This is an attempt at making the code of the feedback app more clean, DRY-er, easier to read and to maintain. Please let me know what you think.