Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labelize newest pictures instead of the oldest #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions recognition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ def labelize_picture_left_sides(request):
Shows the HTML page for labelizing unlabeled left-sides of pictures.
"""
form_set = modelformset_factory(Picture, form=PictureLeftLabelizerForm, extra=0)
pics = Picture.objects.filter(left_label__isnull=True).order_by('created_at')[0:50]
if request.method == 'POST':
formset = form_set(request.POST, request.FILES, queryset=pics)
formset = form_set(request.POST, request.FILES)
if formset.is_valid():
formset.save()
return redirect('left_labelizer')
else:
# Prefere pictures with right label but without left label
pics = Picture.objects.filter(left_label__isnull=True, right_label__isnull=False)
if not pics.exists():
# But no pictures are missing just the left label then fetch all unlabeled ones
pics = Picture.objects.filter(left_label__isnull=True)

pics = pics.order_by('-created_at')[0:50]
formset = form_set(queryset=pics)
return render(request, 'labelizer.html', {
'labelizer_side': 'left',
Expand All @@ -33,13 +39,19 @@ def labelize_picture_right_sides(request):
Shows the HTML page for labelizing unlabeled right-sides of pictures.
"""
form_set = modelformset_factory(Picture, form=PictureRightLabelizerForm, extra=0)
pics = Picture.objects.filter(right_label__isnull=True).order_by('created_at')[0:50]
if request.method == 'POST':
formset = form_set(request.POST, request.FILES, queryset=pics)
formset = form_set(request.POST, request.FILES)
if formset.is_valid():
formset.save()
return redirect('right_labelizer')
else:
# Prefere pictures with right label but without left label
pics = Picture.objects.filter(right_label__isnull=True, left_label__isnull=False)
if not pics.exists():
# But no pictures are missing just the left label then fetch all unlabeled ones
pics = Picture.objects.filter(right_label__isnull=True)

pics = pics.order_by('-created_at')[0:50]
formset = form_set(queryset=pics)
return render(request, 'labelizer.html', {
'labelizer_side': 'right',
Expand Down