def load_csv(self): # import codecs # reader = codecs.getreader('utf-8') reader = csv.reader(open('./data/base_ex_women.csv', 'r')) print(repr(reader)) print(dir(reader)) try: i = True while True: row = reader.next() row = [unicode(s, "utf-8") for s in row] # for row in reader.next(): if i: i = False continue logging.error(row) c = Exercise() # row = map(str, row) row = row + ([''] * 5) logging.error(row) c.title = row[0] c.description = row[1] c.image_link = row[2] c.link_to = row[3] c.video_link = row[4] c.for_women = True c.save() except Exception, e: pass
def create(self, validated_data): e = Exercise(name=validated_data['name'], order=validated_data['order'], repsStart=validated_data['repsStart'], repsEnd=validated_data['repsEnd'], setsStart=validated_data['setsStart'], setsEnd=validated_data['setsEnd'], workout_id=validated_data['workout_id'], owner=validated_data['owner']) e.save() return e
def add_exercise(request, workout): if not request.user.is_authenticated(): return redirect(index) elif request.method == 'POST': form = ExerciseForm(request.POST) name = request.POST['name'] if form.is_valid(): e = Exercise(name=name, owner=request.user, workout=Workout.objects.get(id=workout)) e.save() return redirect(index) else: print(form.errors) else: form = ExerciseForm() return render(request, 'add_exercise.html', {'form': form})
def submit_exercise(self, title, description, content): exercise = Exercise(title=title, description=description, content=content) exercise.save() return True