def program_feature_add(request, *args, **kwargs): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): feature_form = FeatureForm(request.POST) if feature_form.is_valid(): # GET DATA FROM FORM program_obj = Program.objects.get(id=int(request.POST.get('program_id', False))) # CREATE PRICE OBJ feature_obj = feature_form.save(commit=False) feature_obj.program = program_obj feature_obj.save() data = { 'feature_id': feature_obj.id, 'feature_name': feature_obj.name, } return JsonResponse(data) else: data = { 'Form errors': feature_form.errors } return JsonResponse(data) return JsonResponse({})
def bloger_status(request): data = {} if not has_groups(['brandowners',], request): return JsonResponse({"suggestions":[{'value':'', 'data':''}]}) if request.is_ajax(): bloger_id = request.GET.get('bloger_id', None) status = request.GET.get('status', None) bloger_obj = Bloger.objects.get(id=bloger_id) bloger_obj.status = status bloger_obj.save() return JsonResponse(data)
def training_template_create(request, *args, **kwargs): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'GET' and request.is_ajax(): workout_template_obj = WorkoutTemplate.objects.get(id=request.GET.get('workout')) wset_template_obj = WsetTemplate.objects.get(id=request.GET.get('wset')) repetition = int(request.GET.get('repetition')) rest_time_obj = SettingsRestTime.objects.get(value=60) program_obj = Program.objects.get(id=request.GET.get('program_id')) content_owner_obj = program_obj.content_owner workout_occupation_obj = get_or_none(WorkoutOccupation, id=request.GET.get('workout_occupation')) main_muscle_obj = get_or_none(MainMuscle, id=request.GET.get('main_muscle')) other_muscle_obj = get_or_none(OtherMuscle, id=request.GET.get('other_muscle')) exercise_type_obj = get_or_none(ExerciseType, id=request.GET.get('exercise_type')) biomech_obj = get_or_none(Biomech, id=request.GET.get('biomech')) vektor_obj = get_or_none(Vektor, id=request.GET.get('vektor')) equipment_obj = get_or_none(Equipment, id=request.GET.get('equipment')) difficulty_level_obj = get_or_none(DifficultyLevel, id=request.GET.get('difficulty_level')) check_lst = [workout_occupation_obj, main_muscle_obj, other_muscle_obj, exercise_type_obj, biomech_obj, vektor_obj, equipment_obj, difficulty_level_obj] for obj in check_lst: if obj != None: query = make_query( content_owner_obj=None, workout_occupation_obj=None, main_muscle_obj=None, other_muscle_obj=None, exercise_type_obj=None, biomech_obj=None, vektor_obj=None, equipment_obj=None, difficulty_level_obj=None ) if Exercise.objects.filter(query).count() > 0: training_template_obj = TrainingTemplate.objects.create(workout_template=workout_template_obj, wset_template=wset_template_obj,workout_occupation=workout_occupation_obj, main_muscle=main_muscle_obj, other_muscle=other_muscle_obj, exercise_type=exercise_type_obj, biomech=biomech_obj, vektor=vektor_obj, equipment=equipment_obj, difficulty_level=difficulty_level_obj, repetition=repetition, rest_time=rest_time_obj) data = { 'training':training_template_obj.id, 'workout_occupation': training_template_obj.workout_occupation.name if training_template_obj.workout_occupation else '', 'main_muscle': training_template_obj.main_muscle.content if training_template_obj.main_muscle else '', 'other_muscle':training_template_obj.other_muscle.name if training_template_obj.other_muscle else '', 'exercise_type':training_template_obj.exercise_type.content if training_template_obj.exercise_type else '', 'biomech':training_template_obj.biomech.content if training_template_obj.biomech else '', 'vektor':training_template_obj.vektor.content if training_template_obj.vektor else '', 'equipment':training_template_obj.equipment.content if training_template_obj.equipment else '', 'difficulty_level':training_template_obj.difficulty_level.content if training_template_obj.difficulty_level else '', 'repetition':training_template_obj.repetition, } return JsonResponse(data) return JsonResponse({}) return JsonResponse({})
def custom_training_create(request, *args, **kwargs): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): trainingform = CustomTrainingForm(request.POST) if trainingform.is_valid(): # GET DATA FROM FORM content = request.POST.get('content', False) workout_obj = Workout.objects.get(id=int(request.POST.get('workout', False))) wset_obj = Wset.objects.get(id=int(request.POST.get('wset', False))) exercise_id = int(request.POST.get('exercise', False)) exercise_obj = Exercise.objects.get(id=exercise_id) url = exercise_obj.short_video # CREATE TRAINING OBJ training_obj = trainingform.save(commit=False) training_obj.workout = workout_obj training_obj.content = content training_obj.wset = wset_obj training_obj.exercise = exercise_obj training_obj.save() data = { 'training': training_obj.id, 'training_delete': reverse_lazy("subscriptions:custom_training_delete"), 'workout': workout_obj.id, 'wset': wset_obj.id, 'excercise': training_obj.exercise.name, 'content': training_obj.content, 'rest_time': training_obj.rest_time.name, 'url': url, } return JsonResponse(data) else: data = { 'Form errors': trainingform.errors } return JsonResponse(data) else: trainingform = CustomTrainingForm(prefix = 'TrainingForm') data = { 'message': "There is an error." } return JsonResponse(data)
def custom_training_delete(request, *args, **kwargs): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): custom_training_obj = Training.objects.get(id=int(request.POST.get('training', False))) custom_training_obj.delete() data = { 'training': custom_training_obj.id, } return JsonResponse(data) else: data = { 'message': "There is an error." } return JsonResponse(data)
def program_feature_delete(request, *args, **kwargs): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): feature_obj = Feature.objects.get(id=int(request.POST.get('feature_id', False))) feature_obj.delete() data = { 'feature_id': feature_obj.id, } return JsonResponse(data) else: data = { 'message': "There is an error." } return JsonResponse(data)
def program_workout_delete(request): if not has_groups(['brandowners',], request): return JsonResponse({}) if request.method == 'GET' and request.is_ajax(): program_workout_qs = Program.objects.get(id=int(request.GET.get('program_id', False))).workout_set.all() program_workout_qs.delete() data = { 'price_id': '', } return JsonResponse(data) else: data = { 'message': "There is an error." } return JsonResponse(data)
def food_template_delete(request, *args, **kwargs): if not has_groups(['brandowners','trainers','dietologs','main_trainers'], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): food_id = request.POST.get('food', False) eattime_id = request.POST.get('eattime', False) row_delete = request.POST.get('row_delete', False) eattime_delete = request.POST.get('eattime_delete', False) food_obj = FoodTemplate.objects.get(id=food_id) time_obj = TimeTemplate.objects.get(id=eattime_id) if not eattime_delete: # DELETE SUM KBZU FROM TIME OBJ time_obj.weight -= food_obj.weight time_obj.kkal -= food_obj.kkal time_obj.protein -= food_obj.protein time_obj.fat -= food_obj.fat time_obj.carbohydrate -= food_obj.carbohydrate food_obj.delete() time_obj.save() data = { 'time_weight': time_obj.weight, 'time_kkal': time_obj.kkal, 'time_protein': time_obj.protein, 'time_fat': time_obj.fat, 'time_carbohydrate': time_obj.carbohydrate, 'row_delete': row_delete, } else: food_obj.delete() time_obj.delete() data = { 'eattime_delete': eattime_delete, } return JsonResponse(data) else: data = { 'message': "There is an error." } return JsonResponse(data)
def json_template_exercise_list(request, *args, **kwargs): if not has_groups(['brandowners','main_trainers', 'trainers'], request): return JsonResponse({}) if request.method == 'GET' and request.is_ajax(): program_obj = Program.objects.get(id=request.GET.get('program_id')) content_owner_obj = program_obj.content_owner workout_occupation_obj = get_or_none(WorkoutOccupation, id=request.GET.get('workout_occupation')) main_muscle_obj = get_or_none(MainMuscle, id=request.GET.get('main_muscle')) other_muscle_obj = get_or_none(OtherMuscle, id=request.GET.get('other_muscle')) exercise_type_obj = get_or_none(ExerciseType, id=request.GET.get('exercise_type')) biomech_obj = get_or_none(Biomech, id=request.GET.get('biomech')) vektor_obj = get_or_none(Vektor, id=request.GET.get('vektor')) equipment_obj = get_or_none(Equipment, id=request.GET.get('equipment')) difficulty_level_obj = get_or_none(DifficultyLevel, id=request.GET.get('difficulty_level')) # MAKE COMPLEX QUERY query = make_query(content_owner_obj, workout_occupation_obj, main_muscle_obj, other_muscle_obj, exercise_type_obj, biomech_obj, vektor_obj, equipment_obj, difficulty_level_obj) # FILTER RESULTS try: exercise_qs = Exercise.objects.filter(query) except: exercise_qs = Exercise.objects.none() data = {} if exercise_qs.count() == 0: return JsonResponse(data) for exercise in exercise_qs: dct_name = 'dict_{0}'.format(exercise.name) data[dct_name] = {} data[dct_name]['name'] = exercise.name if exercise.main_muscle: data[dct_name]['main_muscle'] = exercise.main_muscle.content else: data[dct_name]['main_muscle'] = None if exercise.workout_occupation: data[dct_name]['workout_occupation'] = exercise.workout_occupation.name else: data[dct_name]['workout_occupation'] = None if exercise.other_muscle: data[dct_name]['other_muscle'] = exercise.other_muscle.name else: data[dct_name]['other_muscle'] = None if exercise.exercise_type: data[dct_name]['exercise_type'] = exercise.exercise_type.content else: data[dct_name]['exercise_type'] = None if exercise.biomech: data[dct_name]['biomech'] = exercise.biomech.content else: data[dct_name]['biomech'] = None if exercise.vektor: data[dct_name]['vektor'] = exercise.vektor.content else: data[dct_name]['vektor'] = None if exercise.equipment: data[dct_name]['equipment'] = exercise.equipment.content else: data[dct_name]['equipment'] = None if exercise.difficulty_level: data[dct_name]['difficulty_level'] = exercise.difficulty_level.content else: data[dct_name]['difficulty_level'] = None print(data) return JsonResponse(data) return JsonResponse({})
def food_template_create(request, *args, **kwargs): if not has_groups(['brandowners','trainers','dietologs','main_trainers'], request): return JsonResponse({}) if request.method == 'POST' and request.is_ajax(): foodform = FoodTemplateForm(request.POST or None) timeform = TimeTemplateForm(request.POST or None) if foodform.is_valid() and timeform.is_valid(): # GET DATA FROM FORM settingstime = timeform.cleaned_data['settingstime'] settingstime_obj = SettingsTime.objects.get(name=str(settingstime.name)[:-3]) foodprogramеtemplate_obj = FoodProgramTemplate.objects.get(id=int(request.POST.get('foodprogram', False))) daytemplate_obj = DayTemplate.objects.get(id=int(request.POST.get('day', False))) product_obj = Product.objects.get(id=int(request.POST.get('product', False))) # CREATE TIME AND FOOD OBJ try: timetemplate_obj, created = TimeTemplate.objects.get_or_create(settingstime=settingstime_obj, day_template=daytemplate_obj) foodtemplate_obj = foodform.save(commit=False) foodtemplate_obj.foodprogram_template = foodprogramеtemplate_obj foodtemplate_obj.day_template = daytemplate_obj foodtemplate_obj.time_template = timetemplate_obj foodtemplate_obj.product = product_obj # UPDATE KBZU 100g foodtemplate_obj.kkal = foodtemplate_obj.product.kbzu_100g.kkal/100*foodtemplate_obj.weight foodtemplate_obj.protein = foodtemplate_obj.product.kbzu_100g.protein/100*foodtemplate_obj.weight foodtemplate_obj.fat = foodtemplate_obj.product.kbzu_100g.fat/100*foodtemplate_obj.weight foodtemplate_obj.carbohydrate = foodtemplate_obj.product.kbzu_100g.carbohydrate/100*foodtemplate_obj.weight product_unit = foodtemplate_obj.product.kbzu_100g.weight # UPDATE KBZU 1PORTION if product_obj.recipe: foodtemplate_obj.kkal = foodtemplate_obj.product.kbzu_1portion.kkal/foodtemplate_obj.product.kbzu_1portion.weight*foodtemplate_obj.weight foodtemplate_obj.protein = foodtemplate_obj.product.kbzu_1portion.protein/foodtemplate_obj.product.kbzu_1portion.weight*foodtemplate_obj.weight foodtemplate_obj.fat = foodtemplate_obj.product.kbzu_1portion.fat/foodtemplate_obj.product.kbzu_1portion.weight*foodtemplate_obj.weight foodtemplate_obj.carbohydrate = foodtemplate_obj.product.kbzu_1portion.carbohydrate/foodtemplate_obj.product.kbzu_1portion.weight*foodtemplate_obj.weight product_unit = foodtemplate_obj.product.kbzu_1portion.weight foodtemplate_obj.save() except Exception as e: print(e) data = { 'food_id': foodtemplate_obj.id, 'food_delete': reverse_lazy("subscriptions:food_template_delete"), 'eattime_id': timetemplate_obj.id, 'product': foodtemplate_obj.product.name, 'product_unit': product_unit, 'weight': foodtemplate_obj.weight, 'time': settingstime_obj.name, 'kkal': foodtemplate_obj.kkal, 'protein': foodtemplate_obj.protein, 'fat': foodtemplate_obj.fat, 'carbohydrate': foodtemplate_obj.carbohydrate, 'time_weight': timetemplate_obj.weight, 'time_kkal': timetemplate_obj.kkal, 'time_protein': timetemplate_obj.protein, 'time_fat': timetemplate_obj.fat, 'time_carbohydrate': timetemplate_obj.carbohydrate, } return JsonResponse(data) else: data = { 'message': "Form is not valid" } return JsonResponse(data) else: foodform = FoodForm(prefix = 'FoodForm') timeform = TimeForm(prefix = 'TimeForm') data = { 'message': "There is an error." } return JsonResponse(data)