Beispiel #1
0
def dish_edit(request, dish):
    user = have_permission(request)
    if user:
        obj_dict = dish.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in obj_dict:
                if value:
                    obj_dict[key] = value
        try:
            if image:
                dish.image = image
        except AttributeError:
            pass
        dish.author = user
        dish.save()
        if contain_ingredients(request.POST):
            delete_all_ingredients(dish)
            add_ing_dish_relations(request.POST, dish)
        return dish.id
    else:
        return False
Beispiel #2
0
def create_dish(request):
    user = have_permission(request)
    if user:
        dish = Post.objects.create(author=user)
        dish_dict = dish.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in dish_dict:
                if value:
                    dish_dict[key] = value
        try:
            if image:
                dish.image = image
        except AttributeError:
            pass
        dish.save()
        if contain_ingredients(request.POST):
            add_ing_dish_relations(request.POST, dish)
        return dish.id
    else:
        return False
Beispiel #3
0
def create_shares(request):
    user = have_permission(request)
    if user:
        share = Shares.objects.create(author=user)
        share_dict = share.__dict__
        request_dict = request.POST
        end_date = request.POST.get('end_date')
        start_date = request.POST.get('start_date')
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in share_dict:
                if value:
                    share_dict[key] = value
        try:
            if image:
                share.image = image
        except AttributeError:
            pass
        try:
            if end_date and start_date:
                share.end_date = end_date
                share.start_date = start_date
            else:
                share.end_date = timezone.now()
                share.start_date = timezone.now()
        except AttributeError:
            pass
        share.save()
        return share.id
    else:
        return False
Beispiel #4
0
def create_dish(request):
    user = have_permission(request)
    if user:
        dish = Post.objects.create(author=user)
        dish_dict = dish.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in dish_dict:
                if value:
                    dish_dict[key] = value
        try:
            if image:
                dish.image = image
        except AttributeError:
            pass
        dish.save()
        if contain_ingredients(request.POST):
            add_ing_dish_relations(request.POST, dish)
        return dish.id
    else:
        return False
Beispiel #5
0
def dish_edit(request, dish):
    user = have_permission(request)
    if user:
        obj_dict = dish.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in obj_dict:
                if value:
                    obj_dict[key] = value
        try:
            if image:
                dish.image = image
        except AttributeError:
            pass
        dish.author = user
        dish.save()
        if contain_ingredients(request.POST):
            delete_all_ingredients(dish)
            add_ing_dish_relations(request.POST, dish)
        return dish.id
    else:
        return False
Beispiel #6
0
 def save_object(self, **kwargs):
     instance = super(ScheduleForm, self).save(commit=False)
     request = kwargs['request']
     instance.author = request.user
     image = get_image_from_request(request)
     if image:
         instance.image = image
     instance.save()
     return instance
Beispiel #7
0
 def save_object(self, **kwargs):
     instance = super(PostForm, self).save(commit=False)
     request = kwargs['request']
     instance.author = request.user
     image = get_image_from_request(request)
     if image:
         instance.image = image
     instance.save()
     for ing_r in IngDishRelation.objects.filter(dish=instance):
         ing_r.delete()
     quantity_list = request.POST.getlist('quantity')
     for (item, quantity) in zip(self.cleaned_data.get('ingredients'), quantity_list):
         ing_r = IngDishRelation.objects.create(dish=instance, ingredient=item, amount=quantity)
         ing_r.save()
     return instance
Beispiel #8
0
def create_contact(request):
    user = have_permission(request)
    if user:
        contact = Contacts.objects.create(author=user)
        contact_dict = contact.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in contact_dict:
                if value:
                    contact_dict[key] = value
        try:
            if image:
                contact.image = image
        except AttributeError:
            pass
        contact.save()
        return contact.id
    else:
        return False
Beispiel #9
0
def shares_edit(request, share):
    user = have_permission(request)
    if user:
        obj_dict = share.__dict__
        request_dict = request.POST
        image = get_image_from_request(request)
        if 'image' in request.POST:
            del request.POST['image']
        for item in request_dict.items():
            key, value = item
            if key in obj_dict:
                if value:
                    obj_dict[key] = value
        try:
            if image:
                share.image = image
        except AttributeError:
            pass
        share.author = user
        share.save()
        return share.id
    else:
        return False