Skip to content

Commit

Permalink
Fix a few other misc importer cases
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbelesky committed Feb 5, 2017
1 parent cdcd2f9 commit 56612b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion tabbycat/importer/templates/add_institutions.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<em>Full Name,Nickname</em>. For example:<br><br>
<em>Victoria University of Wellington,VIC<br>
University of Melbourne,MUDS<br>
Universiti Teknologi MARA,UTMARA</em>
Universiti Teknologi MARA,UTMARA</em><br><br>
Note that teams that use an institutional prefix will use the Nickname for this purpose, ie "MUDS 1".
</p>
</div>

Expand Down
4 changes: 2 additions & 2 deletions tabbycat/importer/templates/edit_venues.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

<label class="col-sm-1 control-label">Priority</label>
<div class="col-sm-2">
<input class="form-control" type="text" name="venue_priorities"
value="{{ venue.priority }}" />
<input class="form-control" name="venue_priorities" step="1"
value="{{ venue.priority }}" type="number" min="1" />
</div>

{% if venue.group %}
Expand Down
40 changes: 31 additions & 9 deletions tabbycat/importer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def edit_institutions(request, t):
institutions = []
institution_lines = request.POST['institutions_raw'].rstrip().split('\n')
for line in institution_lines:
if "," not in line or line.split(',')[1].strip() == "":
messages.error(request, "Institution '%s' could not be processed \
because it did not have a code" % line)
continue

full_name = line.split(',')[0].strip()
full_name = enforce_length(full_name, 'name', Institution, request)
short_name = line.split(',')[1].strip()
Expand All @@ -48,10 +53,15 @@ def edit_institutions(request, t):
institution = Institution(name=full_name, code=short_name)
institutions.append(institution)

return render(request, 'edit_institutions.html',
dict(institutions=institutions,
full_name_max=Institution._meta.get_field('name').max_length - 1,
code_max=Institution._meta.get_field('code').max_length - 1))
if len(institutions) == 0:
messages.warning(request, "No institutions were added")
return render(request, 'data_index.html')
else:
max_name = Institution._meta.get_field('name').max_length - 1
max_code = Institution._meta.get_field('code').max_length - 1
return render(request, 'edit_institutions.html', dict(
institutions=institutions,
full_name_max=max_name, code_max=max_code))


@admin_required
Expand Down Expand Up @@ -100,7 +110,10 @@ def edit_venues(request, t):
name = line.split(',')[0].strip()
else:
name = line.strip()
name = enforce_length(name, 'name', Venue, request)
if name:
name = enforce_length(name, 'name', Venue, request)
else:
continue

# Allow people to not specify a priority when copy pasting
if "," in line:
Expand All @@ -116,7 +129,11 @@ def edit_venues(request, t):
else:
venues.append({'name': name, 'priority': priority})

return render(request, 'edit_venues.html', dict(venues=venues,
if len(venues) == 0:
messages.error(request, "No data was entered was entered in the form")
return render(request, 'data_index.html')
else:
return render(request, 'edit_venues.html', dict(venues=venues,
max_name_length=Venue._meta.get_field('name').max_length - 1))


Expand Down Expand Up @@ -147,9 +164,14 @@ def confirm_venues(request, t):
else:
venue_tournament = t

venue = Venue(name=venue_names[i], priority=venue_priorities[i],
group=venue_group, tournament=venue_tournament)
venue.save()
priority = venue_priorities[i]
if not priority or not float(priority).is_integer():
messages.warning(request, "Venue %s could not be saved because \
it did not have a valid priority number" % venue_names[i])
else:
venue = Venue(name=venue_names[i], priority=venue_priorities[i],
group=venue_group, tournament=venue_tournament)
venue.save()

messages.success(request, "%s Venues have been added" % len(venue_names))
return render(request, 'data_index.html')
Expand Down

0 comments on commit 56612b8

Please sign in to comment.