You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
# -*- coding: utf-8 -*-
|
|
from django.http import HttpResponseRedirect
|
|
from django.conf import settings
|
|
# models and forms
|
|
from models import MetaSetting
|
|
from forms import MetaForm, MetaFilterForm
|
|
from functions.admin_views import AdminListView, AdminView
|
|
|
|
|
|
|
|
class MetaListView(AdminListView):
|
|
template_name = 'c_admin/meta/meta_list.html'
|
|
form_class = MetaFilterForm
|
|
model = MetaSetting
|
|
|
|
class MetaView(AdminView):
|
|
form_class = MetaForm
|
|
model = MetaSetting
|
|
success_url = '/admin/meta/all/'
|
|
template_name = 'c_admin/meta/meta_setting.html'
|
|
|
|
def form_valid(self, form):
|
|
self.set_obj()
|
|
expo = form.save(obj=self.obj)
|
|
|
|
return HttpResponseRedirect(self.success_url)
|
|
|
|
def get_form(self, form_class):
|
|
if self.request.POST:
|
|
return super(MetaView, self).get_form(form_class)
|
|
obj = self.set_obj()
|
|
if obj:
|
|
data = {'name':obj.name}
|
|
|
|
for code, name in settings.LANGUAGES:
|
|
trans_obj = self.model._meta.translations_model.objects.get(language_code = code,master__id=obj.id) #access to translated fields
|
|
data['title_%s' % code] = trans_obj.title
|
|
data['description_%s' % code] = trans_obj.description
|
|
data['keywords_%s' % code] = trans_obj.keywords
|
|
data['h1_%s' % code] = trans_obj.h1
|
|
|
|
form = form_class(initial=data)
|
|
return form
|
|
else:
|
|
return form_class()
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(MetaView, self).get_context_data(**kwargs)
|
|
obj = self.set_obj()
|
|
return context
|
|
|