def handle_uploaded_file(f, user): destination = open('/home/manoj/name.txt', 'wb+') i = 0 for line in f: print line print "'''''" log = LogTable() if i == 0: med_id = line[:-1] if med_id == '111': med_id = 'Controller1' elif med_id == '222': med_id = 'Controller2' elif med_id == '333': med_id = 'Reliever' elif med_id == '444': med_id = 'Symptom1' elif med_id == '555': med_id = 'Symptom2' elif med_id == '666': med_id = 'Symptom3' i+=1 elif i == 1: year = line[:-1] if len(year) == 2: year = '20'+year i+=1 elif i == 2: month = line[:-1] if len(month) == 1: month = '0'+month i+=1 elif i == 3: day = line[:-1] if len(day) == 1: day = '0'+day i+=1 elif i == 4: hour = line[:-1] if len(hour) == 1: hour = '0'+hour i+=1 elif i == 5: mins = line[:-1] if len(mins) == 1: mins = '0'+mins secs = randint(0,50) secs = str(secs) if len(secs) == 1: secs = '0'+secs timestamp = year+'-'+month+'-'+day+" "+hour+':'+mins+":"+secs print timestamp print "****" entry = 'username:'******'med_id:'+med_id+" "+'timestamp:'+timestamp log.username = user log.med_id = med_id log.timestamp = timestamp log.save() i = 0
def upload_data(request, user): u = User.objects.get(username=user) t = UserProfile.objects.get(user = u.id) dataReader = csv.reader(open(csv_filepathname), delimiter=',', quotechar='"') i = 0 for row in dataReader: print row log = LogTable() if i == 0: med_id = row[0] if med_id == '111': med_id = 'm1' elif med_id == '222': med_id = 'm2' elif med_id == '333': med_id = 'm3' elif med_id == '444': med_id = 's1' elif med_id == '555': med_id = 's2' elif med_id == '666': med_id = 's3' i+=1 elif i == 1: year = row[0] if len(year) == 2: year = '20'+year i+=1 elif i == 2: month = row[0] if len(month) == 1: month = '0'+month i+=1 elif i == 3: day = row[0] if len(day) == 1: day = '0'+day i+=1 elif i == 4: hour = row[0] if len(hour) == 1: hour = '0'+hour i+=1 elif i == 5: mins = row[0] if len(mins) == 1: mins = '0'+mins secs = randint(0,60) secs = str(secs) if len(secs) == 1: secs = '0'+secs timestamp = year+'-'+month+'-'+day+" "+hour+':'+mins+":"+secs print timestamp entry = 'username:'******'med_id:'+med_id+" "+'timestamp:'+timestamp print entry log.username = u.username log.med_id = med_id log.timestamp = timestamp log.save() i = 0 #print Log success_msg = "Data Upload Successfull!!" return render_to_response('message/pat.html', {'user': u, "type": t, 'success_msg': success_msg }, context_instance=RequestContext(request))