# Path: app/timetables/models.py
# class Dish(SlugifyMixin, TimestampMixin):
#     """
#     Model representing the actual food served.
# 
#     A dish represents the actual food served as a given
#     course of a meal on a cycle day in a timetable.
#     E.g, Coconut rice garnished with fish stew and chicken or just
#     Ice-cream.
#     """
# 
#     name = models.CharField(max_length=255, verbose_name='Dish Name')
#     slug = models.SlugField(max_length=255, unique=True, null=True, editable=False)
#     description = models.TextField(blank=True)
# 
#     slugify_field = 'name'
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Dishes'
# 
# Path: app/api/cruds/utils.py
# def get_errors(e):
#     # transform django errors to redux errors
#     # django: {"key1": [value1], {"key2": [value2]}}
#     # redux: ["key1", "value1", "key2", "value2"]
#     fields = e.message_dict.keys()
#     messages = ['; '.join(m) for m in e.message_dict.values()]
#     errors = [i for pair in zip(fields, messages) for i in pair]
#     return errors
# 
# def get_object(object_name, relayId, otherwise=None):
#     try:
#         return object_name.objects.get(pk=from_global_id(relayId)[1])
#     except:
#         return otherwise
# 
# def load_object(instance, args, exception=['id']):
#     if instance:
#         [setattr(instance, key, value) for key, value in args.items() if key not in exception]
# 
#     return instance


from app.timetables.models import Dish
from django.core.exceptions import ValidationError
from graphene_django import DjangoObjectType
from django_filters import OrderingFilter, FilterSet
from .utils import get_errors, get_object, load_object
import graphene
        name = graphene.String(required=False)
        description = graphene.String(required=False)

    dish = graphene.Field(DishNode)
    errors = graphene.List(graphene.String)

    @classmethod
    def mutate_and_get_payload(cls, args, context, info):
        dish = get_object(Dish, args.get('id'))
        dish = load_object(dish, args)
        try:
            if dish:
                dish.full_clean()
                dish.save()
            return cls(dish=dish)
        except ValidationError as e:
            return cls(dish=dish, errors=get_errors(e))


class DeleteDish(graphene.relay.ClientIDMutation):

    class Input:
        id = graphene.String(required=True)

    deleted = graphene.Boolean()
    dish = graphene.Field(DishNode)

    @classmethod
    def mutate_and_get_payload(cls, args, context, info):
        try:

# Path: app/timetables/models.py
# class Dish(SlugifyMixin, TimestampMixin):
#     """
#     Model representing the actual food served.
# 
#     A dish represents the actual food served as a given
#     course of a meal on a cycle day in a timetable.
#     E.g, Coconut rice garnished with fish stew and chicken or just
#     Ice-cream.
#     """
# 
#     name = models.CharField(max_length=255, verbose_name='Dish Name')
#     slug = models.SlugField(max_length=255, unique=True, null=True, editable=False)
#     description = models.TextField(blank=True)
# 
#     slugify_field = 'name'
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Dishes'
# 
# Path: app/api/cruds/utils.py
# def get_errors(e):
#     # transform django errors to redux errors
#     # django: {"key1": [value1], {"key2": [value2]}}
#     # redux: ["key1", "value1", "key2", "value2"]
#     fields = e.message_dict.keys()
#     messages = ['; '.join(m) for m in e.message_dict.values()]
#     errors = [i for pair in zip(fields, messages) for i in pair]
#     return errors
# 
# def get_object(object_name, relayId, otherwise=None):
#     try:
#         return object_name.objects.get(pk=from_global_id(relayId)[1])
#     except:
#         return otherwise
# 
# def load_object(instance, args, exception=['id']):
#     if instance:
#         [setattr(instance, key, value) for key, value in args.items() if key not in exception]
# 
#     return instance


# Path: app/api/cruds/dish_crud.py
from app.timetables.models import Dish
from django.core.exceptions import ValidationError
from graphene_django import DjangoObjectType
from django_filters import OrderingFilter, FilterSet
from .utils import get_errors, get_object, load_object
import graphene

        name = graphene.String(required=False)
        description = graphene.String(required=False)

    dish = graphene.Field(DishNode)
    errors = graphene.List(graphene.String)

    @classmethod
    def mutate_and_get_payload(cls, args, context, info):
        dish = get_object(Dish, args.get('id'))
        dish = load_object(dish, args)
        try:
            if dish:
                dish.full_clean()
                dish.save()
            return cls(dish=dish)
        except ValidationError as e:
            return cls(dish=dish, errors=get_errors(e))


class DeleteDish(graphene.relay.ClientIDMutation):

    class Input:
        id = graphene.String(required=True)

    deleted = graphene.Boolean()
    dish = graphene.Field(DishNode)

    @classmethod
    def mutate_and_get_payload(cls, args, context, info):
        try:

            dish = get_object(Dish, args.get('id'))