combo/combo/apps/momo/views.py

49 lines
1.7 KiB
Python

# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.encoding import force_text
from django.views.generic import TemplateView, UpdateView
from .models import MomoOptions
from .utils import generate_manifest, GenerationError, GenerationInfo
class MomoManagerView(TemplateView):
template_name = 'momo/manager_home.html'
def generate(request, **kwargs):
try:
generate_manifest(request)
except GenerationError as e:
messages.error(request, force_text(e))
except GenerationInfo as e:
messages.info(request, force_text(e))
return HttpResponseRedirect(reverse('momo-manager-homepage'))
class OptionsUpdateView(UpdateView):
model = MomoOptions
fields = '__all__'
def get_object(self, *args, **kwargs):
return MomoOptions.get_object()
def get_success_url(self):
return reverse('momo-manager-homepage')