コード例 #1
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def set_category_sort():
    """
    Sets the order of the categories.
    """
    if 'categories' not in request.json:
        return api_error('Invalid form.')
    categories = request.json['categories']
    for data in categories:
        category = Category.get(data['id'])
        category.sort_order = data['sort_order']
        category.save()
    return jsonify(Category.all())
コード例 #2
0
def set_category_sort():
    """
    Sets the order of the categories.
    """
    if 'categories' not in request.json:
        return api_error('Invalid form.')
    categories = request.json['categories']
    for data in categories:
        category = Category.get(data['id'])
        category.sort_order = data['sort_order']
        category.save()
    return jsonify(Category.all())
コード例 #3
0
def create_category():
    """
    Create a category. Must be an admin.
    """
    form = CategoryForm()
    if not form.validate_on_submit():
        return api_error(form.errors)

    name = form.name.data
    description = form.description.data

    category = Category(name=name, description=description)
    category.save()
    return '', 201
コード例 #4
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def create_category():
    """
    Create a category. Must be an admin.
    """
    form = CategoryForm()
    if not form.validate_on_submit():
        return api_error(form.errors)

    name = form.name.data
    description = form.description.data

    category = Category(name=name, description=description)
    category.save()
    return '', 201
コード例 #5
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def update_category(category_id):
    """
    Update an category.
    """
    category = Category.get(category_id)
    if not category:
        return api_error('Category not found', 404)
    form = CategoryForm(
        validate_unique_name=category.name != request.json.get('name')
    )
    if not form.validate_on_submit():
        return api_error(form.errors)

    category.name = form.name.data
    category.description = form.description.data

    if 'services' in request.json:
        services = request.json['services']
        for data in services:
            service = Service.get(data['id'])
            service.sort_order = data['sort_order']
            service.save()

    category.save()
    return '', 200
コード例 #6
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def delete_category(category_id):
    """
    Delete an category.
    """
    category = Category.get(category_id)
    if not category:
        return api_error('Category not found', 404)
    category.delete()
    return '', 200
コード例 #7
0
def delete_category(category_id):
    """
    Delete an category.
    """
    category = Category.get(category_id)
    if not category:
        return api_error('Category not found', 404)
    category.delete()
    return '', 200
コード例 #8
0
ファイル: service.py プロジェクト: 15thnight/15thnight
def create_service():
    """
    Create a service. Must be an admin.
    """
    form = ServiceForm()
    if not form.validate_on_submit():
        return api_error(form.errors)

    service = Service(
        name=form.name.data,
        description=form.description.data,
        category=Category.get(form.category.data)
    )
    service.save()
    return '', 201
コード例 #9
0
ファイル: service.py プロジェクト: spectralsun/15thnight
def update_service(service_id):
    """
    Update an service.
    """
    service = Service.get(service_id)
    if not service:
        return api_error("Service not found", 404)
    form = ServiceForm(validate_unique_name=service.name != request.json.get("name"))
    if not form.validate_on_submit():
        return api_error(form.errors)

    service.name = form.name.data
    service.description = form.description.data
    service.category = Category.get(form.category.data)

    service.save()
    return "", 200
コード例 #10
0
def update_category(category_id):
    """
    Update an category.
    """
    category = Category.get(category_id)
    if not category:
        return api_error('Category not found', 404)
    form = CategoryForm(
        validate_unique_name=category.name != request.json.get('name'))
    if not form.validate_on_submit():
        return api_error(form.errors)

    category.name = form.name.data
    category.description = form.description.data

    if 'services' in request.json:
        services = request.json['services']
        for data in services:
            service = Service.get(data['id'])
            service.sort_order = data['sort_order']
            service.save()

    category.save()
    return '', 200
コード例 #11
0
def get_category(category_id):
    """
    Gets a category.
    """
    return jsonify(Category.get(category_id))
コード例 #12
0
def get_categories():
    """
    Gets the list of categories.
    """
    # TODO: pagination
    return jsonify(Category.all())
コード例 #13
0
ファイル: manage.py プロジェクト: markdav-is/15thnight
def seed_services():
    """Seed some categories and services."""

    food = Category.get_by_name("Food")
    if not food:
        food = Category()
        food.name = "Food"
        food.description = ""
        food.save()
    food_delivery = Service.get_by_name("Delivery")
    if not food_delivery:
        food_delivery = Service()
        food_delivery.name = "Delivery"
        food_delivery.description = "Quick for those hungry children"
        food_delivery.category = food
        food_delivery.save()

    shelter = Category.get_by_name("Shelter")
    if not shelter:
        shelter = Category()
        shelter.name = "Shelter"
        shelter.description = "Housing for a limited time."
        shelter.save()
    shelter_one_night = Service.get_by_name("One night")
    if not shelter_one_night:
        shelter_one_night = Service()
        shelter_one_night.name = "One night"
        shelter_one_night.description = "A bed for the night"
        shelter_one_night.category = shelter
        shelter_one_night.save()

    clothing = Category.get_by_name("Clothing")
    if not clothing:
        clothing = Category()
        clothing.name = "Clothing"
        clothing.description = "Shirts, shoes, and all things."
        clothing.save()
    clothing_young = Service.get_by_name("0-5 clothing")
    if not clothing_young:
        clothing_young = Service()
        clothing_young.name = "0-5 clothing"
        clothing_young.description = "Clothing for chidren ages 0 to 5"
        clothing_young.category = clothing
        clothing_young.save()

    return (food_delivery, shelter_one_night, clothing_young)
コード例 #14
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def get_category(category_id):
    """
    Gets a category.
    """
    return jsonify(Category.get(category_id))
コード例 #15
0
ファイル: forms.py プロジェクト: spectralsun/15thnight
 def validate_name(self, field):
     if self.validate_unique_name and Category.get_by_name(field.data):
         raise ValidationError('This service name is already in use.')
コード例 #16
0
ファイル: manage.py プロジェクト: spectralsun/15thnight
def seed_services():
    """Seed some categories and services."""

    food = Category.get_by_name("Food")
    if not food:
        food = Category()
        food.name = "Food"
        food.description = ""
        food.save()
    food_delivery = Service.get_by_name("Delivery")
    if not food_delivery:
        food_delivery = Service()
        food_delivery.name = "Delivery"
        food_delivery.description = "Quick for those hungry children"
        food_delivery.category = food
        food_delivery.save()

    shelter = Category.get_by_name("Shelter")
    if not shelter:
        shelter = Category()
        shelter.name = "Shelter"
        shelter.description = "Housing for a limited time."
        shelter.save()
    shelter_one_night = Service.get_by_name("One night")
    if not shelter_one_night:
        shelter_one_night = Service()
        shelter_one_night.name = "One night"
        shelter_one_night.description = "A bed for the night"
        shelter_one_night.category = shelter
        shelter_one_night.save()

    clothing = Category.get_by_name("Clothing")
    if not clothing:
        clothing = Category()
        clothing.name = "Clothing",
        clothing.description = "Shirts, shoes, and all things."
        clothing.save()
    clothing_young = Service.get_by_name("0-5 clothing")
    if not clothing_young:
        clothing_young = Service()
        clothing_young.name = "0-5 clothing"
        clothing_young.description = "Clothing for chidren ages 0 to 5"
        clothing_young.category = clothing
        clothing_young.save()

    return (food_delivery, shelter_one_night, clothing_young)
コード例 #17
0
 def validate_name(self, field):
     if self.validate_unique_name and Category.get_by_name(field.data):
         raise ValidationError('This service name is already in use.')
コード例 #18
0
 def __init__(self, *args, **kwargs):
     super(ServiceForm, self).__init__(*args, **kwargs)
     self.category.choices = [(category.id, category.name)
                              for category in Category.all()]
     self.validate_unique_name = kwargs.get('validate_unique_name', True)
コード例 #19
0
ファイル: forms.py プロジェクト: spectralsun/15thnight
 def __init__(self, *args, **kwargs):
     super(ServiceForm, self).__init__(*args, **kwargs)
     self.category.choices = [
         (category.id, category.name) for category in Category.all()
     ]
     self.validate_unique_name = kwargs.get('validate_unique_name', True)
コード例 #20
0
ファイル: category.py プロジェクト: spectralsun/15thnight
def get_categories():
    """
    Gets the list of categories.
    """
    # TODO: pagination
    return jsonify(Category.all())