Exemple #1
0
    def build_attrs(self, extra_attrs=None, **kwargs):
        """Overwritten helper function for building an attribute dictionary.
        This helper also takes care passing the used dojo modules to the
        collector. Furthermore it mixes in the used field attributes into the
        attributes of this widget.
        """
        # gathering all widget attributes
        attrs = dict(self.attrs, **kwargs)
        field_attr = self.default_field_attr_map.copy(
        )  # use a copy of that object. otherwise changed field_attr_map would overwrite the default-map for all widgets!
        field_attr.update(self.field_attr_map
                          )  # the field-attribute-mapping can be customzied
        if extra_attrs:
            attrs.update(extra_attrs)
        # assigning dojoType to our widget
        dojo_type = getattr(self, "dojo_type", False)
        if dojo_type:
            attrs["dojoType"] = dojo_type  # add the dojoType attribute

        # fill the global collector object
        if getattr(self, "alt_require", False):
            dojo_collector.add_module(self.alt_require)
        elif dojo_type:
            dojo_collector.add_module(self.dojo_type)
        extra_requires = getattr(self, "extra_dojo_require", [])
        for i in extra_requires:
            dojo_collector.add_module(i)

        # mixin those additional field attrs, that are valid for this widget
        extra_field_attrs = attrs.get("extra_field_attrs", False)
        if extra_field_attrs:
            for i in self.valid_extra_attrs:
                field_val = extra_field_attrs.get(i, None)
                new_attr_name = field_attr.get(i, None)
                if field_val is not None and new_attr_name is not None:
                    attrs = self._mixin_attr(attrs, new_attr_name, field_val)
            del attrs["extra_field_attrs"]

        # now encode several attributes, e.g. False = false, True = true
        for i in attrs:
            if isinstance(attrs[i], bool):
                attrs[i] = json_encode(attrs[i])
        return attrs
Exemple #2
0
    def build_attrs(self, extra_attrs=None, **kwargs):
        """Overwritten helper function for building an attribute dictionary.
        This helper also takes care passing the used dojo modules to the
        collector. Furthermore it mixes in the used field attributes into the
        attributes of this widget.
        """
        # gathering all widget attributes
        attrs = dict(self.attrs, **kwargs)
        field_attr = self.default_field_attr_map.copy() # use a copy of that object. otherwise changed field_attr_map would overwrite the default-map for all widgets!
        field_attr.update(self.field_attr_map) # the field-attribute-mapping can be customzied
        if extra_attrs:
            attrs.update(extra_attrs)
        # assigning dojoType to our widget
        dojo_type = getattr(self, "dojo_type", False)
        if dojo_type:
            attrs["dojoType"] = dojo_type # add the dojoType attribute

        # fill the global collector object
        if getattr(self, "alt_require", False):
            dojo_collector.add_module(self.alt_require)
        elif dojo_type:
            dojo_collector.add_module(self.dojo_type)
        extra_requires = getattr(self, "extra_dojo_require", [])
        for i in extra_requires:
            dojo_collector.add_module(i)

        # mixin those additional field attrs, that are valid for this widget
        extra_field_attrs = attrs.get("extra_field_attrs", False)
        if extra_field_attrs:
            for i in self.valid_extra_attrs:
                field_val = extra_field_attrs.get(i, None)
                new_attr_name = field_attr.get(i, None)
                if field_val is not None and new_attr_name is not None:
                    attrs = self._mixin_attr(attrs, new_attr_name, field_val)
            del attrs["extra_field_attrs"]

        # now encode several attributes, e.g. False = false, True = true
        for i in attrs:
            if isinstance(attrs[i], bool):
                attrs[i] = json_encode(attrs[i])
        return attrs
Exemple #3
0
def main(request):
    forms = [energyForm(auto_id=False),teploForm(auto_id=False)]
    dojo_collector.add_module('dijit.Dialog')
    dojo_collector.add_module('dijit.layout.StackContainer')
    dojo_collector.add_module('dijit.form.Form')
    dojo_collector.add_module('dijit.form.HorizontalSlider')
    dojo_collector.add_module('dijit.layout.BorderContainer')
    dojo_collector.add_module('dijit.layout.TabContainer')
    dojo_collector.add_module('dijit.MenuBar')
    dojo_collector.add_module('dijit.MenuBarItem')
    dojo_collector.add_module('dijit.PopupMenuBarItem')
    dojo_collector.add_module("dojox.charting.widget.Chart2D")
    dojo_collector.add_module("dojox.charting.widget.Legend")
    dojo_collector.add_module("dojox.charting.themes.PlotKit.green")
    dojo_collector.add_module("dojox.charting.themes.Claro")
    dojo_collector.add_module("dojox.charting.DataSeries")
    dojo_collector.add_module("dojox.charting.widget.SelectableLegend")
    dojo_collector.add_module("dojox.charting.action2d.Tooltip")
    dojo_collector.add_module("dojo.date.locale")
#    dojo_collector.add_module("dojo.data.ItemFileReadStore")
    return render_to_response('main.html', {'forms':forms},context_instance=RequestContext(request))
Exemple #4
0
    def render(self, context):
        opts = {}
        global disp_list_guid
        disp_list_guid = disp_list_guid + 1
        # add dojo modules
        add_module("dojox.data.QueryReadStore")
        add_module("dojox.grid.DataGrid")
        
        # Setable options, not listed: label, query, search, nosort
        if self.model:
            opts['list_display'] = [x.attname for x in self.model._meta.fields]
        opts['width'] = {}
        opts['label'] = {}
        opts['default_width'] = "auto"
        opts['width'] = "100%"
        opts['height'] = "100%"
        opts['query']={}
        opts['query']['inclusions']=[]
        
        opts['id'] = "disp_list_%s_%s" % (disp_list_guid,random.randint(10000,99999))
        try:
            # reverse lookup of the datagrid-list url (see dojango/urls.py)
            if self.model:
                opts['json_store_url'] = reverse("dojango-datagrid-list", args=(self.app_name, self.model_name))
        except NoReverseMatch:
            pass
        
        # User overrides
        if self.options:
            opts.update(extract_nodelist_options(self.options,context))
        if not opts['query'].has_key('inclusions'): opts['query']['inclusions'] = []
            
        # we must ensure that the json_store_url is defined
        if not opts.get('json_store_url', False):
            raise TemplateSyntaxError, "Please enable the url 'dojango-datagrid-list' in your urls.py or pass a 'json_store_url' to the datagrid templatetag."
        
        # Incase list_display was passed as tuple, turn to list for mutability
        if not self.model and not opts.get('list_display', False):
            raise TemplateSyntaxError, "'list_display' not defined. If you use your own 'json_store_url' you have to define which fields are visible."
        opts['list_display'] = list(opts['list_display'])
        
        # Config for template
        opts['headers'] = []

        # Get field labels using verbose name (take into account i18n), will be used
        # for column labels
        verbose_field_names = {}
        if self.model:
            verbose_field_names = dict([(f.name, f.verbose_name) for f in self.model._meta.fields])

        for field in opts['list_display']:
            ret = {'attname':field}
            for q in FIELD_ATTRIBUTES:
                if opts.has_key(q) and opts[q].has_key(field):
                     ret[q] = opts[q][field]
            # custom default logic
            if not ret.has_key('label'):
                ret['label'] = verbose_field_names.get(field, field.replace('_', ' '))
            if not ret.has_key('column_width'):
                ret['column_width']= opts['default_width']
            # add as inclusion if not a attribute of model
            if self.model and not field in map(lambda x: x.attname, self.model._meta.fields):
                opts['query']['inclusions'].append(field)
            # add to header
            opts['headers'].append(ret)
              
        # no sort fields
        if opts.has_key("nosort"): 
            opts['nosort'] = "".join(["||row==%s"%(opts['list_display'].index(r)+1) for r in opts['nosort']])
        
        # additional context info/modifications
        opts["model_name"] = self.model_name
        opts["app_name"] = self.app_name
        opts['query']['inclusions'] = ",".join(opts['query']['inclusions'])
        if opts.has_key('search'):
            opts['search_fields'] = ",".join(opts['search'])
            opts['show_search'] = opts.get('show_search', True)
        else:
            opts['show_search'] = False

        # return rendered template
        return get_template("dojango/templatetag/datagrid_disp.html").render(template.Context(opts))
Exemple #5
0
def show_tab_container(request):
    dojo_collector.add_module("dijit.layout.ContentPane")
    dojo_collector.add_module("dijit.layout.TabContainer")
    return render_to_response("core/show_tab_container.html", locals(), context_instance=RequestContext(request))