Statistics
| Branch: | Tag: | Revision:

root / cloudcms / admin.py @ a13220f8

History | View | Annotate | Download (3.8 kB)

1 52271184 Kostas Papadimitriou
# Copyright 2012 GRNET S.A. All rights reserved.
2 52271184 Kostas Papadimitriou
#
3 52271184 Kostas Papadimitriou
# Redistribution and use in source and binary forms, with or
4 52271184 Kostas Papadimitriou
# without modification, are permitted provided that the following
5 52271184 Kostas Papadimitriou
# conditions are met:
6 52271184 Kostas Papadimitriou
#
7 52271184 Kostas Papadimitriou
#   1. Redistributions of source code must retain the above
8 52271184 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
9 52271184 Kostas Papadimitriou
#      disclaimer.
10 52271184 Kostas Papadimitriou
#
11 52271184 Kostas Papadimitriou
#   2. Redistributions in binary form must reproduce the above
12 52271184 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
13 52271184 Kostas Papadimitriou
#      disclaimer in the documentation and/or other materials
14 52271184 Kostas Papadimitriou
#      provided with the distribution.
15 52271184 Kostas Papadimitriou
#
16 52271184 Kostas Papadimitriou
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 52271184 Kostas Papadimitriou
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 52271184 Kostas Papadimitriou
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 52271184 Kostas Papadimitriou
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 52271184 Kostas Papadimitriou
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 52271184 Kostas Papadimitriou
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 52271184 Kostas Papadimitriou
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 52271184 Kostas Papadimitriou
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 52271184 Kostas Papadimitriou
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 52271184 Kostas Papadimitriou
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 52271184 Kostas Papadimitriou
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 52271184 Kostas Papadimitriou
# POSSIBILITY OF SUCH DAMAGE.
28 52271184 Kostas Papadimitriou
#
29 52271184 Kostas Papadimitriou
# The views and conclusions contained in the software and
30 52271184 Kostas Papadimitriou
# documentation are those of the authors and should not be
31 52271184 Kostas Papadimitriou
# interpreted as representing official policies, either expressed
32 52271184 Kostas Papadimitriou
# or implied, of GRNET S.A.
33 52271184 Kostas Papadimitriou
34 52271184 Kostas Papadimitriou
35 c1468bcc Kostas Papadimitriou
from django.contrib import admin
36 deb708bf Kostas Papadimitriou
from django.conf.urls.defaults import patterns
37 deb708bf Kostas Papadimitriou
from django.views.generic.simple import direct_to_template
38 deb708bf Kostas Papadimitriou
from django.http import HttpResponse
39 deb708bf Kostas Papadimitriou
from django.shortcuts import redirect
40 deb708bf Kostas Papadimitriou
from django.contrib import messages
41 deb708bf Kostas Papadimitriou
42 deb708bf Kostas Papadimitriou
43 60441a7f Kostas Papadimitriou
from feincms.translations import admin_translationinline, short_language_code
44 60441a7f Kostas Papadimitriou
45 c1468bcc Kostas Papadimitriou
from cloudcms import models
46 c1468bcc Kostas Papadimitriou
47 c1468bcc Kostas Papadimitriou
48 c1468bcc Kostas Papadimitriou
class ApplicationAdmin(admin.ModelAdmin):
49 52abca01 Kostas Papadimitriou
    raw_id_fields = ('logo', 'favicon')
50 c1468bcc Kostas Papadimitriou
51 c1468bcc Kostas Papadimitriou
52 511913cb Kostas Papadimitriou
class ClientVersionSourceAdminInline(admin.StackedInline):
53 511913cb Kostas Papadimitriou
    model = models.ClientVersionSource
54 511913cb Kostas Papadimitriou
    raw_id_fields = ('logo',)
55 511913cb Kostas Papadimitriou
    extra = 1
56 511913cb Kostas Papadimitriou
57 60441a7f Kostas Papadimitriou
58 511913cb Kostas Papadimitriou
class ClientAdmin(admin.ModelAdmin):
59 511913cb Kostas Papadimitriou
    inlines = [ClientVersionSourceAdminInline]
60 511913cb Kostas Papadimitriou
61 511913cb Kostas Papadimitriou
62 60441a7f Kostas Papadimitriou
ServiceTranslationInline = admin_translationinline(models.ServiceTranslation,
63 60441a7f Kostas Papadimitriou
        prepopulated_fields={'slug': ('title',)})
64 60441a7f Kostas Papadimitriou
65 60441a7f Kostas Papadimitriou
class ServiceAdmin(admin.ModelAdmin):
66 60441a7f Kostas Papadimitriou
    inlines = [ServiceTranslationInline]
67 60441a7f Kostas Papadimitriou
68 60441a7f Kostas Papadimitriou
69 c1468bcc Kostas Papadimitriou
admin.site.register(models.Application, ApplicationAdmin)
70 511913cb Kostas Papadimitriou
admin.site.register(models.Client, ClientAdmin)
71 60441a7f Kostas Papadimitriou
admin.site.register(models.Service, ServiceAdmin)
72 c1468bcc Kostas Papadimitriou
73 deb708bf Kostas Papadimitriou
74 deb708bf Kostas Papadimitriou
from cloudcms.forms import RstZipImportForm
75 deb708bf Kostas Papadimitriou
76 deb708bf Kostas Papadimitriou
def import_from_sphinx(request):
77 deb708bf Kostas Papadimitriou
    if not request.user.is_superuser:
78 deb708bf Kostas Papadimitriou
        return HttpResponse(status=401)
79 deb708bf Kostas Papadimitriou
80 deb708bf Kostas Papadimitriou
    context = {}
81 deb708bf Kostas Papadimitriou
    form = RstZipImportForm()
82 deb708bf Kostas Papadimitriou
83 d240ebcb Kostas Papadimitriou
    if request.GET.get('form_saved'):
84 d240ebcb Kostas Papadimitriou
        context['save_log'] = request.session.get('save_log')
85 d240ebcb Kostas Papadimitriou
    else:
86 d240ebcb Kostas Papadimitriou
        if request.session.get('save_log'):
87 d240ebcb Kostas Papadimitriou
            del request.session['save_log']
88 d240ebcb Kostas Papadimitriou
89 deb708bf Kostas Papadimitriou
    if request.method == 'POST':
90 deb708bf Kostas Papadimitriou
        form = RstZipImportForm(request.POST, request.FILES)
91 deb708bf Kostas Papadimitriou
        if form.is_valid():
92 deb708bf Kostas Papadimitriou
            try:
93 d240ebcb Kostas Papadimitriou
                saved, log = form.save(request.user)
94 d240ebcb Kostas Papadimitriou
                if saved:
95 d240ebcb Kostas Papadimitriou
                    messages.add_message(request, messages.INFO, 'Form saved')
96 d240ebcb Kostas Papadimitriou
                    request.session['save_log'] = log.replace("\n", "<br />")
97 daf1154c Kostas Papadimitriou
                    return redirect('/cmsmanage/rstimport/' + '?form_saved=1')
98 d240ebcb Kostas Papadimitriou
                else:
99 d240ebcb Kostas Papadimitriou
                    messages.add_message(request, messages.ERROR, 'Form failed')
100 d240ebcb Kostas Papadimitriou
                    context['save_log'] = log.replace("\n", "<br />")
101 deb708bf Kostas Papadimitriou
            except Exception, e:
102 d240ebcb Kostas Papadimitriou
                context['save_log'] = e
103 deb708bf Kostas Papadimitriou
104 deb708bf Kostas Papadimitriou
        else:
105 deb708bf Kostas Papadimitriou
            context['error'] = True
106 deb708bf Kostas Papadimitriou
107 deb708bf Kostas Papadimitriou
    context['form'] = form
108 deb708bf Kostas Papadimitriou
109 deb708bf Kostas Papadimitriou
    return direct_to_template(request, 'cms/admin_import_guide_faq.html', context)
110 deb708bf Kostas Papadimitriou
111 deb708bf Kostas Papadimitriou
sphinx_import = admin.site.admin_view(import_from_sphinx)