from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import UpdateView
from .models import GradingSettings
from .forms import GradingSettingsForm

class SettingsUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
    model = GradingSettings
    form_class = GradingSettingsForm
    template_name = "settingsapp/form.html"
    success_url = "/"

    def get_object(self, queryset=None):
        return GradingSettings.get()

    def test_func(self):
        return self.request.user.is_staff
