def image_view(request, id): athlete = Athlete.all().filter("bibNum =",int(id)).get() if athlete and athlete.picture: response = HttpResponse() response['Content-Type'] = 'image/png' response.write(athlete.picture) return response else: raise Http404('Sorry, I couldnt find that image!')
def show_athletes_by_country(request, key): country = Country.get(key) return object_list(request, Athlete.gql("WHERE country = :1", country))
def show_team(request, key): team = Team.get(key) return object_list(request,Athlete.gql("WHERE team = :1", team))
def show_athlete(request, key): return object_detail(request,Athlete.all(),key)
def show_athletes(request): return object_list(request,Athlete.all(),paginate_by = 10)
def race_upload(request): errmsg = [] if request.method == 'POST': errmsg += ['beginning import'] import re import os from bios.models import Country, Athlete, Crew file = request.FILES['csv'] uploadfile=file.name; file_contents = request.FILES['csv'].read().strip() p = re.compile('\r', re.IGNORECASE) file_contents = p.sub('\n',file_contents) #file_contents = self.request.get('lif').strip() import csv imported = [] importReader = csv.reader(file_contents.split('\n')) for row in importReader: imported += [row] #validate data structure ci = 0 selectedEvent = None selectedRace = None errmsg += ['in the loop'] for r in imported: try: if selectedEvent is not None and selectedEvent.eventString != r[0] or selectedEvent is None: #does this event already exist? evtest = Event.all().filter("eventString =",r[0]).fetch(1) #print evtest if len(evtest) > 0: selectedEvent = evtest[0] #print "re-using event" else: #print "making new event" eventInfo = [x.strip() for x in r[0].split('-')] event = Event() event.eventClass=eventInfo[0] event.gender=eventInfo[1] event.distance=eventInfo[2] event.eventString=r[0] event.put() selectedEvent = event if selectedRace is not None and (selectedRace.event != selectedEvent or selectedRace.heatNumber != r[1]) or selectedRace is None: #print "making new race" #check and re-use old races. ractest = Race.all().filter("event =",selectedEvent).filter("heatNumber =",r[1]).fetch(1) if len(ractest) > 0: selectedRace = ractest[0] else: race = Race() race.event = selectedEvent race.heatNumber = r[1] race.hasResults = False race.put() selectedRace = race #athelte or crew? athcrew = None if len(r) > 6 and r[6] != '': if len(r) >8 and r[7] != '': """ it's a 4 man crew """ fourteam = Athlete.all().filter("bibNum IN",[int(r[5]),int(r[6]),int(r[7]),int(r[8])]).fetch(4) crew = Crew() crew.athletes = fourteam crew.put() athcrew = crew else: """ it's a crew@@ """ #crew = Crew() twoteam = Athlete.all().filter("bibNum IN",[int(r[5]),int(r[6])]).fetch(2) crew = Crew() crew.athletes = twoteam crew.put() athcrew = crew else: selath = Athlete.all().filter("bibNum =", int(r[5])).fetch(1) athcrew = selath[0] if len(selath)>0 else None result = Results() #print athcrew.__class__.__name__ if athcrew.__class__.__name__ is "Crew": #print "its crew" result.crew = athcrew elif athcrew.__class__.__name__ is "Athlete": #print "its athlete" result.athlete = athcrew #result.athlete = selath[0] if len(selath)>0 else None result.laneNumber = r[2] selc = Country.all().filter("code =", r[3]).fetch(1) result.country = selc[0] if len(selc)>0 else None result.race = selectedRace result.put() ci = ci + 1 #if ci > 100: # return UA_direct(request, 'results/race-upload.html') #print result #print r except: errmsg += ["Error on Line :%s of CSV, line looks like: %s" % (ci,r)] errmsg += ["%s rows imported<br/>" % ci] return render_to_response(request, 'results/race-upload.html', extra_context={"errmsg":errmsg})
def populate_races(request): errmsg = [] if request.method == 'POST': errmsg += ['beginning import'] import re import os from bios.models import Country, Athlete, Crew file_contents = request.FILES['evt'].read().strip() #file_contents = self.request.get('lif').strip() import csv imported = [] importReader = csv.reader(file_contents.split('\n')) for row in importReader: imported += [row] selectedEvent = None selectedRace = None for row in imported: if len(row) == 4: fields = row[3].strip().split(" ") evtStr = "%s-%s-%s" % (fields[2],fields[3],fields[4].strip("m")) selectedEvent = Event.all().filter("eventString =", evtStr).fetch(1)[0] selectedRace = Race.all().filter("raceNumber =", int(row[0])).fetch(1)[0] print selectedRace.raceNumber print selectedEvent else: #print row[1] """ is it an athlete or a crew for the result? check class? if it's an athlete, search bibNumber set Result with lane number and athlete if it's a crew, search for the bibNum participating in the event and insert that crew into a new result containing the lane number """ newResult = Results() newResult.race = selectedRace chkRace = Race.all().filter("event =", selectedEvent).fetch(1)[0] if len(chkRace.results_race) > 0 and chkRace.results_race[0].crew is not None: #find and assign crew chkAthlete = Athlete.all().filter("bibNum =",int(row[1])).fetch(1) #print chkAthlete for crew in chkAthlete[0].crew_athlete: for result in crew.result_crew: if result.race.event == selectedEvent: newResult.crew = crew else: newResult.athlete = Athlete.all().filter("bibNum =", int(row[1])).fetch(1)[0] newResult.laneNumber = row[2] selc = Country.all().filter("code =", row[5]).fetch(1)[0] newResult.country = selc newResult.put() errmsg += [newResult] return render_to_response(request, 'results/populate.html', {'errmsg':errmsg})
def bio_delete_athlete(request): list = Athlete.all(keys_only=True).fetch(250) db.delete(list) return UA_direct(request, 'homepage.html')
def show_crew(request, key): crew = Crew.get(key) return UA_object_list(request,Athlete.gql("WHERE crew = :1", crew), extra_context={'crew':crew})
def show_athlete(request, identifier): athlete = Athlete.all().filter("bibNum =",int(identifier)).get() crews = athlete.get_crews() return UA_object_detail(request,Athlete.all(),slug_field="bibNum",slug=long(identifier), template_name="mobile-bioAthleteDetail.html", template_object_name = "athlete", extra_context={'crews':crews})
def show_athletes_all_country(request, country): countryQ = Country.gql("WHERE code = :cc", cc=country) selectedCountry = countryQ.get() data = UA_object_list(request,Athlete.all().filter("country =",selectedCountry), template_name="mobile-bioAthleteList.html", extra_context={'country':selectedCountry}) return data
def bio_upload(request): errmsg = [] if request.method == 'POST': errmsg += ["entering upload phase"] import re import os file = request.FILES['bios'] uploadfile=file.name; file_contents = request.FILES['bios'].read().strip() #file_contents = self.request.get('lif').strip() import csv imported = [] importReader = csv.reader(file_contents.split('\n')) for row in importReader: imported += [row] #validate data structure ci = 0 selectedCountry = None for r in imported: try: if len(r) is 2: name = [x.strip() for x in r[1].split('-')] #print name country = Country(name = name[0], code = name[1], countryNumber = ci) ci = ci + 1 country.put() selectedCountry = country else: #print r athlete = Athlete() athlete.bibNum=int(r[0]) if r[0] is not '' else int(81) athlete.firstName=r[1] athlete.lastName=r[3] athlete.gender="Male" if r[4] is "M" else "Female" athlete.country = selectedCountry if len(r) > 8: athlete.birthDate = r[8] athlete.accred = r[9] if len(r) > 11: athlete.homeTown = smart_unicode(r[10]) athlete.bio = smart_unicode(r[11]) athlete.put() except: errmsg += [r] errmsg += ["finished"] return direct_to_template(request, 'bios/upload.html', extra_context={'errmsg':errmsg})