Beispiel #1
0
def xml2dict(tag):
    r = {}

    #value
    # tag.text is None, for empty tags.
    if tag.text is not None:
        v = tag.text.strip()
        r['_value'] = v

    #attributes
    if tag.keys():
        r['_attributes'] = {}
    for k in tag.keys():
        _k = remove_ns(k)
        _k = camelcase_to_underscore(_k)
        r['_attributes'][_k] = tag.get(k)

    for child in tag.getchildren():
        ctag = remove_ns(child.tag)
        ctag = camelcase_to_underscore(ctag)
        #assuming every child is potentially a list
        l = r.get(ctag, [])
        l.append(xml2dict(child))
        r[ctag] = l
    return r
Beispiel #2
0
def xml2dict(tag):
    r = {}
    
    #value
    # tag.text is None, for empty tags.
    if tag.text is not None:
        v = tag.text.strip()
        r['_value'] = v
    
    #attributes
    if tag.keys():
        r['_attributes'] = {}
    for k in tag.keys():
        _k = remove_ns(k)
        _k = camelcase_to_underscore(_k)
        r['_attributes'][_k] = tag.get(k)
        
    for child in tag.getchildren():
        ctag = remove_ns(child.tag)
        ctag = camelcase_to_underscore(ctag)
        #assuming every child is potentially a list
        l = r.get(ctag, [])
        l.append(xml2dict(child))
        r[ctag] = l
    return r
    def get_context_data(self, **kwargs):
        context = super(ModalTemplateView, self).get_context_data(**kwargs)
        column = self.kwargs['model']
        name = camelcase_to_underscore(column.__name__)

        context['name'] = name
        context['title'] = getattr(column, '_title', name.replace('_', ' ').title())
        context['single'] = column._is_singleton
        context['modal_template_path'] = name + '_modal.html'

        if name == 'location':
            context['tags'] = models.TAGS

        return context
    def get_context_data(self, **kwargs):
        context = super(ModalTemplateView, self).get_context_data(**kwargs)
        column = self.kwargs['model']
        name = camelcase_to_underscore(column.__name__)

        context['name'] = name
        context['title'] = getattr(column, '_title',
                                   name.replace('_', ' ').title())
        context['single'] = column._is_singleton
        context['modal_template_path'] = name + '_modal.html'

        if name == 'location':
            context['tags'] = models.TAGS

        return context
 def get_column_context(self):
     """
     Return the context for our columns
     """
     context = []
     for column in self.column_schema:
         column_context = {}
         name = camelcase_to_underscore(column.__name__)
         column_context['name'] = name
         column_context['title'] = getattr(column, '_title',
                                           name.replace('_', ' ').title())
         column_context['single'] = column._is_singleton
         column_context['template_path'] = name + '.html'
         column_context['modal_template_path'] = name + '_modal.html'
         column_context['detail_template_path'] = select_template([name + '_detail.html', name + '.html']).name
         context.append(column_context)
     return context
 def get_column_context(self):
     """
     Return the context for our columns
     """
     context = []
     for column in self.column_schema:
         column_context = {}
         name = camelcase_to_underscore(column.__name__)
         column_context['name'] = name
         column_context['title'] = getattr(column, '_title',
                                           name.replace('_', ' ').title())
         column_context['single'] = column._is_singleton
         column_context['template_path'] = name + '.html'
         column_context['modal_template_path'] = name + '_modal.html'
         column_context['detail_template_path'] = select_template(
             [name + '_detail.html', name + '.html']).name
         context.append(column_context)
     return context
Beispiel #7
0
    def build_field_schema(cls):
        field_schema = []
        for fieldname in cls._get_fieldnames_to_serialize():
            if fieldname in ['id', 'patient_id']:
                continue

            getter = getattr(cls, 'get_field_type_for_' + fieldname, None)
            if getter is None:
                field = cls._get_field_type(fieldname)
                if field in [models.CharField, ForeignKeyOrFreeText]:
                    field_type = 'string'
                else:
                    field_type = camelcase_to_underscore(field.__name__[:-5])
            else:
                field_type = getter()

            field_schema.append({'name': fieldname, 'type': field_type})

        return field_schema
    def build_field_schema(cls):
        field_schema = []
        for fieldname in cls._get_fieldnames_to_serialize():
            if fieldname in ['id', 'patient_id']:
                continue

            getter = getattr(cls, 'get_field_type_for_' + fieldname, None)
            if getter is None:
                field = cls._get_field_type(fieldname)
                if field in [models.CharField, ForeignKeyOrFreeText]:
                    field_type = 'string'
                else:
                    field_type = camelcase_to_underscore(field.__name__[:-5])
            else:
                field_type = getter()

            field_schema.append({'name': fieldname, 'type': field_type})

        return field_schema
Beispiel #9
0
    def register_plugin(self, plugincls):
        """Complete Skype events list:

        ['ApplicationConnecting', 'ApplicationDatagram',
         'ApplicationReceiving', 'ApplicationSending',
         'ApplicationStreams', 'AsyncSearchUsersFinished',
         'AttachmentStatus', 'AutoAway', 'CallDtmfReceived',
         'CallHistory', 'CallInputStatusChanged', 'CallSeenStatusChanged',
         'CallStatus', 'CallTransferStatusChanged',
         'CallVideoReceiveStatusChanged', 'CallVideoSendStatusChanged',
         'CallVideoStatusChanged', 'ChatMemberRoleChanged',
         'ChatMembersChanged', 'ChatWindowState', 'ClientWindowState',
         'Command', 'ConnectionStatus', 'ContactsFocused', 'Error',
         'FileTransferStatusChanged', 'GroupDeleted', 'GroupExpanded',
         'GroupUsers', 'GroupVisible', 'MessageHistory', 'MessageStatus',
         'Mute', 'Notify', 'OnlineStatus', 'PluginEventClicked',
         'PluginMenuItemClicked', 'Reply', 'SilentModeStatusChanged',
         'SmsMessageStatusChanged', 'SmsTargetStatusChanged',
         'UserAuthorizationRequestReceived', 'UserMood', 'UserStatus',
         'VoicemailStatus', 'WallpaperChanged', ]
        """
        if plugincls not in set(self._plugins):
            raise Exception("Invalid plugin class %s" % plugincls)

        pluginobj = plugincls(parent=self)

        # Set of dispensable attributes.
        s = set(dir(object)).union(["__module__", "__dict__", "__weakref__"])

        # TODO: this could use some optimization.
        for event in set(dir(Skype4Py.skype.SkypeEvents)).difference(s):
            handler_name = "on_" + camelcase_to_underscore(event)
            try:
                handler = getattr(pluginobj, handler_name)
            except AttributeError:
                pass
            else:
                if callable(handler):
                    self.skype.RegisterEventHandler(event, handler)

        self._plugin_objects.append(pluginobj)
        return pluginobj
Beispiel #10
0
 def get_api_name(cls):
     return camelcase_to_underscore(cls._meta.object_name)
Beispiel #11
0
 def template_dir(self):
     return utils.camelcase_to_underscore(self.__class__.__name__)
Beispiel #12
0
from django.conf.urls import patterns, url
from utils import camelcase_to_underscore
from patients import models, views

urlpatterns = patterns('',
    url(r'^$', views.patient_list_and_create_view),
    url(r'^(?P<pk>\d+)/?$', views.patient_detail_view),
)

for subrecord_model in models.Subrecord.__subclasses__():
    sub_url = camelcase_to_underscore(subrecord_model.__name__)
    urlpatterns += patterns('',
        url(r'^%s/?$' % sub_url, views.subrecord_create_view, {'model': subrecord_model}),
        url(r'^%s/(?P<pk>\d+)/?$' % sub_url, views.subrecord_detail_view, {'model': subrecord_model}),
    )
 def get_api_name(cls):
     return camelcase_to_underscore(cls._meta.object_name)