示例#1
0
 def convert(self, value):
     value = native_str(value)
     if isinstance(value, str):
         if value[-2:] == self.unit:
             value = value[:-2]
         elif value[-1:] == self.unit:
             value = value[:-1]
         value = float(value)
     if isinstance(value, (int, float)):
         value = round(value, 4)
         ivalue = int(value)
         if self.unit == 'px':
             return ivalue
         else:
             return ivalue if ivalue == value else value
     else:
         raise TypeError('Cannot convert %s to Size', value)
示例#2
0
    def app_for_model(self, model, all=False, root=False):
        '''Fetch an :class:`djpcms.views.Application` for a given *model*.

:parameter all: if ``True`` it returns a list of all matched applications,
    otherwise it return the first found.
:parameter root: if ``True`` the search will start from the root site,
    otherwise it starts from the current site.
    Defaulr: ``False``.
'''
        if model == self.model:
            return self.view.appmodel
        else:
            model = native_str(model)
            site = self.view.root if root else self.view.site
            if isinstance(model, str):
                return site.for_hash(model, all=all)
            elif model is not None:
                return site.for_model(model, all=all)
            else:
                return None
示例#3
0
    def app_for_model(self, model, all=False, root=False):
        '''Fetch an :class:`djpcms.views.Application` for a given *model*.

:parameter all: if ``True`` it returns a list of all matched applications,
    otherwise it return the first found.
:parameter root: if ``True`` the search will start from the root site,
    otherwise it starts from the current site.
    Defaulr: ``False``.
'''
        if model == self.model:
            return self.view.appmodel
        else:
            model = native_str(model)
            site = self.view.root if root else self.view.site
            if isinstance(model, str):
                return site.for_hash(model, all=all)
            elif model is not None:
                return site.for_model(model, all=all)
            else:
                return None