def upload_data(request): if request.method == 'POST': form = UploadDataForm(request.POST, request.FILES) if form.is_valid(): judge_errors = room_errors = team_errors = [] importName = '' results = '' if 'team_file' in request.FILES: team_errors = import_teams.import_teams( request.FILES['team_file']) importName += request.FILES['team_file'].name + ' ' if len(team_errors) > 0: results += 'Team Import Errors (Please Check These Manually):\n' for e in team_errors: results += ' ' + e + '\n' if 'judge_file' in request.FILES: judge_errors = import_judges.import_judges( request.FILES['judge_file']) importName += request.FILES['judge_file'].name + ' ' if len(judge_errors) > 0: results += 'Judge Import Errors (Please Check These Manually):\n' for e in judge_errors: results += ' ' + e + '\n' if 'room_file' in request.FILES: room_errors = import_rooms.import_rooms( request.FILES['room_file']) importName += request.FILES['room_file'].name + ' ' if len(room_errors) > 0: results += 'Room Import Errors (Please Check These Manually):\n' for e in room_errors: results += ' ' + e + '\n' return render_to_response('thanks.html', { 'data_type': "Database data", 'data_name': importName, 'data_modification': "INPUT", 'results': True, 'data_results': results }, context_instance=RequestContext(request)) else: form = UploadDataForm() return render_to_response('data_entry.html', { 'form': form, 'title': 'Upload Input Files' }, context_instance=RequestContext(request))
def upload_data(request): if request.method == 'POST': form = UploadDataForm(request.POST, request.FILES) if form.is_valid(): judge_errors = room_errors = team_errors = [] importName = '' results = '' #TODO: Could probably turn these checks into a loop if 'team_file' in request.FILES: team_errors = import_teams.import_teams(request.FILES['team_file']) importName += request.FILES['team_file'].name + ' ' if len(team_errors) > 0: results += 'Team Import Errors (Please Check These Manually):\n' for e in team_errors: results += ' ' + e + '\n' if 'judge_file' in request.FILES: judge_errors = import_judges.import_judges(request.FILES['judge_file']) importName += request.FILES['judge_file'].name + ' ' if len(judge_errors) > 0: results += 'Judge Import Errors (Please Check These Manually):\n' for e in judge_errors: results += ' ' + e + '\n' if 'room_file' in request.FILES: room_errors = import_rooms.import_rooms(request.FILES['room_file']) importName += request.FILES['room_file'].name + ' ' if len(room_errors) > 0: results += 'Room Import Errors (Please Check These Manually):\n' for e in room_errors: results += ' ' + e + '\n' return render_to_response('thanks.html', {'data_type': "Database data", 'data_name': importName, 'data_modification': "INPUT", 'results': True, 'data_results': results}, context_instance=RequestContext(request)) else: form = UploadDataForm() return render_to_response('data_entry.html', {'form': form, 'title': 'Upload Input Files'}, context_instance=RequestContext(request))
def upload_data(request): team_info = {"errors": [], "uploaded": False} judge_info = {"errors": [], "uploaded": False} room_info = {"errors": [], "uploaded": False} scratch_info = {"errors": [], "uploaded": False} if request.method == "POST": form = UploadDataForm(request.POST, request.FILES) if form.is_valid(): if "team_file" in request.FILES: team_info["errors"] = import_teams.import_teams( request.FILES["team_file"]) team_info["uploaded"] = True if "judge_file" in request.FILES: judge_info["errors"] = import_judges.import_judges( request.FILES["judge_file"]) judge_info["uploaded"] = True if "room_file" in request.FILES: room_info["errors"] = import_rooms.import_rooms( request.FILES["room_file"]) room_info["uploaded"] = True if "scratch_file" in request.FILES: scratch_info["errors"] = import_scratches.import_scratches( request.FILES["scratch_file"]) scratch_info["uploaded"] = True if not team_info["errors"] + judge_info["errors"] + \ room_info["errors"] + scratch_info["errors"]: return redirect_and_flash_success(request, "Data imported successfully") else: form = UploadDataForm() return render( request, "common/data_upload.html", { "form": form, "title": "Upload Input Files", "team_info": team_info, "judge_info": judge_info, "room_info": room_info, "scratch_info": scratch_info })
def upload_data(request): if request.method == 'POST': form = UploadDataForm(request.POST, request.FILES) if form.is_valid(): errors = [] if 'team_file' in request.FILES: team_errors = import_teams.import_teams(request.FILES['team_file']) errors += team_errors if 'judge_file' in request.FILES: judge_errors = import_judges.import_judges(request.FILES['judge_file']) errors += judge_errors if 'room_file' in request.FILES: room_errors = import_rooms.import_rooms(request.FILES['room_file']) errors += room_errors if not errors: return redirect_and_flash_success(request, "Data imported successfully") else: for e in errors: messages.error(request, e) else: form = UploadDataForm() return render(request, 'common/data_entry.html', {'form': form, 'title': 'Upload Input Files'})
import settings # Assumed to be in the same directory. except ImportError: import sys sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) sys.exit(1) def sep(): print("#"*80) if __name__ == "__main__": setup_environ(settings) from mittab.libs.data_import import import_judges, import_teams, import_scratches print("Importing Judges") sep() try: import_judges.import_judges("../JudgeEntry.xls") except: print("There was an error importing judges") sep() try: import_teams.import_teams("../TeamEntry.xls") except: print("There was an error importing teams") sep() try: import_scratches.import_scratches("../ScratchEntry.xls") except: print("There was an error importing scratches") sep()
sys.stderr.write( "Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) sys.exit(1) def sep(): print("#" * 80) if __name__ == "__main__": setup_environ(settings) from mittab.libs.data_import import import_judges, import_teams, import_scratches print("Importing Judges") sep() try: import_judges.import_judges("../JudgeEntry.xls") except: print("There was an error importing judges") sep() try: import_teams.import_teams("../TeamEntry.xls") except: print("There was an error importing teams") sep() try: import_scratches.import_scratches("../ScratchEntry.xls") except: print("There was an error importing scratches") sep()