from django.shortcuts import render, redirect
from django.contrib import messages
from .models import Business
from .forms import BusinessForm
from core.decorators import role_required


@role_required('owner')
def business_profile(request):
    business = Business.get()
    if request.method == 'POST':
        form = BusinessForm(request.POST, request.FILES, instance=business)
        if form.is_valid():
            form.save()
            messages.success(request, 'Business profile updated.')
            return redirect('business:profile')
    else:
        form = BusinessForm(instance=business)
    return render(request, 'business/profile.html', {'form': form})