Beispiel #1
0
class UserAppBase(views.Application):
    '''Base class for user applications. Defines several
utility methods for dealing with users and user data.'''
    name = 'accounts'
    userpage = False
    exclude_links = ('login', 'logout')
    #
    home = views.SearchView()
    login = LoginView(in_nav=0)
    logout = LogoutView(in_nav=0)
    add = views.AddView(in_nav=0, form=HtmlAddUserForm, force_redirect=True)
    register = views.AddView('/register',
                             in_nav=0,
                             linkname=lambda r: 'register',
                             form=HtmlRegisterForm,
                             force_redirect=True)

    def userhomeurl(self, request):
        '''The user home page url'''
        user = getattr(request, 'user', None)
        if user and user.is_authenticated():
            if self.userpage:
                view = self.getview('userhome')
            else:
                view = self.getview('home')
            if view:
                djp = view(request, instance=user)
                return djp.url

    def on_bound(self):
        '''Set the user model in the application site'''
        self.root.internals['User'] = self.mapper
Beispiel #2
0
class GroupApplication(views.Application):
    '''An application group. NOT YET READ NOR TESTED'''
    home = views.View()
    search = views.SearchView('<group>')
    add = views.AddView()
    view = views.ViewView()
    change = views.ChangeView()
    delete = views.DeleteView()
Beispiel #3
0
class DesignApplication(views.Application):
    pagination = html.Pagination(('id', 'timestamp'))
    home = views.SearchView()
    add = views.AddView(form=AddThemeHtml, has_plugins=True, name='Add theme')
    view = views.ViewView()
    forms_view = views.View('/forms')

    def render_instance_default(self, request, instance, **kwargs):
        return get_form(request, ThemeInputsHtml)
Beispiel #4
0
class Application(vanilla.Application):
    storage = None
    tumbnail_height = 128
    tumbnail_width = 128
    form = FileUploadForm

    add = views.AddView()

    def __init__(self, *args, **kwargs):
        self.storage = kwargs.pop('storage', self.storage)
        super(Application, self).__init__(*args, **kwargs)

    def registration_done(self):
        storage = self.storage
        if hasattr(storage, '__call__'):
            storage = storage(self.site.settings)
        if storage:
            self.site.storage = storage
        self.model.register_signals()

    def save_file(self, name, file):
        return self.model(name=name,
                          size=file.size,
                          content_type=file.content_type).save()

    def objectfunction__thumbnail(self, instance):
        storage = self.site.storage
        if storage:
            ct = instance.content_type
            cts = ct.split('/')
            if cts[0] == 'image':
                name = instance.name
                tname = 'T_{0}x{1}_{2}'.format(self.tumbnail_width,
                                               self.tumbnail_height, name)
                if not storage.exists(tname) and Image:
                    f = storage.open(name)
                    im = Image.open(f.file)
                    im.thumbnail((self.tumbnail_width, self.tumbnail_height),
                                 Image.ANTIALIAS)
                    buff = BytesIO()
                    fn = im.save(buff, format=cts[1])
                    storage.save(files.File(buff, tname,
                                            instance.content_type))

                if storage.exists(tname):
                    turl = storage.url(tname)
                    #url = storage.url(instance.name)
                    return '<img src="{0}"/>'.format(turl)
Beispiel #5
0
class AdminApplication(views.Application):
    has_plugins = False
    views_ordering = {'description': 0,
                      'change': 1}
    pagination = html.Pagination(('__str__',))

    home = views.SearchView()
    add = views.AddView()
    delete_all = views.DeleteAllView()
    view = TabView(in_nav=0)
    description = views.ObjectView('/description',
                                   in_nav=0,
                                   parent_view='view',
                                   renderer=lambda r, **kwargs:\
                                   r.appmodel.render_instance(r, **kwargs))
    change = views.ChangeView(force_redirect=False)
    delete = views.DeleteView()
Beispiel #6
0
class SiteMapApplication(views.Application):
    '''Application to use for admin sitemaps'''
    has_plugins = False
    form = HtmlPageForm
    description = 'Site-map'
    pagination = Pagination(
        ('url', 'view', 'layout', 'inner_template', 'in_navigation',
         table_header('doc_type', attrname='doctype'), 'soft_root'),
        bulk_actions=[views.bulk_delete])
    list_display_links = ('id', 'url', 'page')

    home = SiteMapView()
    pages = views.SearchView('pages/',
                             icon='th-list',
                             title=lambda r: 'Pages',
                             linkname=lambda r: 'pages')
    add = views.AddView(force_redirect=True, linkname=lambda r: 'add page')
    view = views.ViewView()
    change = PageChangeView(force_redirect=True,
                            title=lambda djp: 'editing',
                            linkname=lambda djp: 'edit page',
                            body_class='editable')
    delete = views.DeleteView()

    def on_bound(self):
        self.root.internals['Page'] = self.mapper

    def view_for_instance(self, request, instance):
        return self.views['change']

    def instance_field_value(self, request, page, field_name, val=''):
        if field_name == 'view':
            node = request.tree.get(page.url)
            view = node.view
            if not isinstance(view, pageview):
                return view.code
            else:
                return ''
        else:
            return escape(val)
Beispiel #7
0
class Application(views.Application):
    search = views.SearchView()
    add = views.AddView()
    view = views.ViewView()
    change = views.ChangeView()
    delete = views.DeleteView()
Beispiel #8
0
class ContactUs(views.Application):
    name = 'Contact Us'
    contact = views.AddView('/', has_plugins=True, form=HtmlContactForm)