Ejemplo n.º 1
0
        pk = getattr(self.org_obj, self.org_obj._meta.pk.attname)
        model_fields = [str(pk) + '-' + f.name for f in self.opts.fields]
        fields = [f[len(str(pk)) + 1:] for f in request.POST.keys() if f in model_fields]

        defaults = {
            "form": forms.ModelForm,
            "fields": fields,
            "formfield_callback": self.formfield_for_dbfield,
        }
        form_class = modelform_factory(self.model, **defaults)
        form = form_class(instance=self.org_obj, data=request.POST, files=request.FILES)
        form.prefix = str(pk)

        result = {}
        if form.is_valid():
            form.save(commit=True)
            result['result'] = 'success'
            result['new_data'] = form.cleaned_data
            result['new_html'] = dict([(f, self.get_new_field_html(f)) for f in fields])
        else:
            result['result'] = 'error'
            result['errors'] = JsonErrorDict(form.errors, form).as_json()

        return self.render_response(result)

site.register_plugin(EditablePlugin, ListAdminView)
site.register_modelview(r'^(.+)/patch/$', EditPatchView, name='%s_%s_patch')


Ejemplo n.º 2
0
            for i, yfname in enumerate(self.y_fields):
                yf, yattrs, yv = lookup_field(yfname, obj, self)
                datas[i]["data"].append((value, yv))

        option = {'series': {'lines': { 'show': True }, 'points': { 'show': False }},
                'grid': { 'hoverable': True, 'clickable': True }}
        try:
            xfield = self.opts.get_field(self.x_field)
            if type(xfield) in (models.DateTimeField, models.DateField, models.TimeField):
                option['xaxis'] = { 'mode': "time", 'tickLength': 5}
                if type(xfield) is models.DateField:
                    option['xaxis']['timeformat'] = "%y/%m/%d";
                elif type(xfield) is models.TimeField:
                    option['xaxis']['timeformat'] = "%H:%M:%S";
                else:
                    option['xaxis']['timeformat'] = "%y/%m/%d %H:%M:%S";
        except Exception:
            pass
            
        option.update(self.chart.get('option', {}))

        content = {'data': datas, 'option': option}
        json = simplejson.dumps(content, cls=JSONEncoder, ensure_ascii=False)

        return HttpResponse(json)

site.register_plugin(ChartsPlugin, ListAdminView)
site.register_modelview(r'^chart/(.+)/$', ChartsView, name='%s_%s_chart')


Ejemplo n.º 3
0
from exadmin.sites import site

from base import BaseAdminPlugin, BaseAdminView, CommAdminView, ModelAdminView, filter_hook

from list import ListAdminView
from edit import CreateAdminView, UpdateAdminView, ModelFormAdminView
from delete import DeleteAdminView
from detail import DetailAdminView
from dashboard import Dashboard, BaseWidget, widget_manager
from website import IndexView, LoginView, LogoutView, UserSettingView

# admin site-wide views
site.register_view(r'^$', IndexView, name='index')
site.register_view(r'^login/$', LoginView, name='login')
site.register_view(r'^logout/$', LogoutView, name='logout')

site.register_view(r'^settings/user$', UserSettingView, name='user_settings')

site.register_modelview(r'^$', ListAdminView, name='%s_%s_changelist')
site.register_modelview(r'^add/$', CreateAdminView, name='%s_%s_add')
site.register_modelview(r'^(.+)/delete/$', DeleteAdminView, name='%s_%s_delete')
site.register_modelview(r'^(.+)/update/$', UpdateAdminView, name='%s_%s_change')
site.register_modelview(r'^(.+)/detail/$', DetailAdminView, name='%s_%s_detail')
Ejemplo n.º 4
0
        if not self.title:
            self.title = unicode(bookmark)

        req = self.make_get_request("", data.items())
        self.list_view = self.get_view_class(ListAdminView, model, list_per_page=10, list_editable=[])(req)

    def has_perm(self):
        return True

    def context(self, context):
        list_view = self.list_view
        list_view.make_result_list()

        base_fields = list_view.base_list_display
        if len(base_fields) > 5:
            base_fields = base_fields[0:5]

        context['result_headers'] = [c for c in list_view.result_headers().cells if c.field_name in base_fields]
        context['results'] = [[o for i,o in \
            enumerate(filter(lambda c:c.field_name in base_fields, r.cells))] \
            for r in list_view.results()]
        context['result_count'] = list_view.result_count
        context['page_url'] = self.bookmark.url

site.register(Bookmark, BookmarkAdmin)
site.register_plugin(BookmarkPlugin, ListAdminView)
site.register_modelview(r'^bookmark/$', BookmarkView, name='%s_%s_bookmark')


Ejemplo n.º 5
0
    def do_action_func(self, __):
        def _method():
            self.revision_context_manager.set_user(self.user)
            action_view = self.admin_view
            comment = action_view.description % model_format_dict(self.opts)

            self.revision_context_manager.set_comment(comment)
            return __()
        return _method

    def do_action(self, __, queryset):
        return self.revision_context_manager.create_revision(manage_manually=False)(self.do_action_func(__))()

site.register(Revision)
site.register(Version)

site.register_modelview(r'^recover/$', RecoverListView, name='%s_%s_recoverlist')
site.register_modelview(r'^recover/([^/]+)/$', RecoverView, name='%s_%s_recover')
site.register_modelview(r'^([^/]+)/revision/$', RevisionListView, name='%s_%s_revisionlist')
site.register_modelview(r'^([^/]+)/revision/([^/]+)/$', RevisionView, name='%s_%s_revision')

site.register_plugin(ReversionPlugin, ListAdminView)
site.register_plugin(ReversionPlugin, ModelFormAdminView)
site.register_plugin(ReversionPlugin, DeleteAdminView)

site.register_plugin(InlineRevisionPlugin, InlineModelAdmin)
site.register_plugin(ActionRevisionPlugin, BaseActionView)