Example #1
0
def adding_saved_meal(user_id, meal_id, meal_name):
    check_user = do_user_check(user_id)
    if check_user:
        saved_meal = Meal(user_id=user_id,
                          meal_id=meal_id,
                          meal_name=meal_name,
                          meal_image=request.json['meal_image'])
        Meal.save(saved_meal)
        flash("You saved the meal successfully", "success")
        return redirect(f'/users/{user_id}/meals/{meal_id}/view/{meal_name}')
    else:
        return redirect("/")
Example #2
0
def meal_new(request, *args, **kwargs):
    if request.method == 'POST':
        meal_form = MealForm(request.POST)
        if meal_form.is_valid():
            restaurant = meal_form.cleaned_data['restaurant']
            value = meal_form.cleaned_data['value']
            date = meal_form.cleaned_data['date']

            meal = Meal(meal_value=value, meal_date=date, meal_restaurant=restaurant)
            meal.save()
    else:
        meal_form = MealForm()
    return render(request, 'meal_new.html', {'meal_form': meal_form})
Example #3
0
    def form_valid(self, form):
        def grab(s):
            return form.cleaned_data[s]

        m = Meal(
            eater=Player.logged_in_player(self.request),
            eaten=Player.current_players().get(feed=grab("feedcode")),
            time=grab("time"),
            location=grab("location"),
            description=grab("description"),
        )
        m.full_clean()
        m.save()

        return super(EatView, self).form_valid(form)
Example #4
0
 def form_valid(self, form):
     def grab(s):
         return form.cleaned_data[s]
     zombie = Player.logged_in_player(self.request)
     victim = Player.current_players().select_for_update().get(feed=grab("feedcode"))
     m = Meal(
         eater=zombie,
         eaten=victim,
         time=grab('time'),
         location=grab("location"),
         description=grab("description"),
     )
     m.full_clean()
     m.save()
     
     
     return super(EatView, self).form_valid(form)
Example #5
0
def create_base():
    path = __file__[:-10] + 'data/'
    with open(path + 'delivery_categories.csv', "r") as file:
        lines = file.readlines()
        for i in range(1, len(lines)):
            data = lines[i].split(",")
            category = Category(category_id=int(data[0]), title=data[1].rstrip())
            category.save()

    # id,title,price,description,picture,category_id
    with open(path + 'meals.csv', "r") as file:
        lines = file.readlines()
        for i in range(1, len(lines)):
            data = lines[i].split(";")
            item = Meal(meal_id=int(data[0]), title=data[1], price=int(data[2]),
                        description=data[3], picture=data[4], category_id=int(data[5].rstrip()),
                        category=Category.objects(category_id=int(data[5].rstrip())).first())
            item.save()

    admin = User(name='admin', mail='*****@*****.**', role='admin')
    admin.password = Config.PASSWORD
    guest = User(name='guest')
    guest.save()
    admin.save()
Example #6
0
from models import User, Category, Meal

with open("../../untitled/data/delivery_categories.csv", "r") as file:
    lines = file.readlines()
    for i in range(1, len(lines)):
        data = lines[i].split(",")
        print(data)
        category = Category(category_id=int(data[0]), title=data[1].rstrip())
        category.save()

# id,title,price,description,picture,category_id
with open("../../untitled/data/meals.csv", "r") as file:
    lines = file.readlines()
    for i in range(1, len(lines)):
        data = lines[i].split(";")
        print(data)
        item = Meal(meal_id=int(data[0]),
                    title=data[1],
                    price=int(data[2]),
                    description=data[3],
                    picture=data[4],
                    category_id=int(data[5].rstrip()),
                    category=Category.objects(
                        category_id=int(data[5].rstrip())).first())
        item.save()

admin = User(name='admin', mail='*****@*****.**', role='admin')
admin.password = '******'
guest = User(name='guest')
guest.save()
admin.save()