Esempio n. 1
0
    def process_request(self, request):
        ua = request.META.get('HTTP_USER_AGENT', '').decode('ascii', 'ignore')

        try:
            request.browser = devices.select_ua(
                ua,
                search=vsa
            )
        except (KeyError, DeviceNotFound):
            request.browser = devices.select_id('generic_xhtml')

        if 'HTTP_X_OPERAMINI_PHONE' in request.META:
            opera_device = request.META['HTTP_X_OPERAMINI_PHONE'].decode('ascii', 'ignore')
            request.device = devices.select_ua(
                opera_device,
                search=vsa
            )
        if 'HTTP_X_SKYFIRE_PHONE' in request.META:
            request.browser = devices.select_id('generic_skyfire')
            skyfire_device = request.META['HTTP_X_SKYFIRE_PHONE'].decode('ascii', 'ignore')
            request.device = devices.select_ua(
                skyfire_device,
                search=vsa
            )
            try:
                request.device.resolution_width, request.device.resolution_height = \
                    map(int, request.META['HTTP_X_SKYFIRE_SCREEN'].split(','))[2:4]
            except (KeyError, ValueError):
                pass
        else:
            request.device = request.browser

        request.map_width = min(320, request.device.resolution_width - 10)
        request.map_height = min(320, request.device.resolution_height - 10)
Esempio n. 2
0
    def handle_GET(self, request, context):
        if not getattr(self.conf, 'expose_view', False):
            raise Http404
        ua = request.GET.get('ua', request.META.get('HTTP_USER_AGENT', ''))
        ua = ua.decode('ascii', 'ignore')

        try:
            device = devices.select_ua(
                ua,
                search=vsa
            )
        except (KeyError, DeviceNotFound):
            device = devices.select_id('generic_xhtml')

        accepts = self.parse_accept_header(request.META.get('HTTP_ACCEPT', ''))
        renderers = MediaType.resolve(accepts, self.FORMATS_BY_MIMETYPE)
        formats = [renderer.format for renderer in renderers]

        context.update({
            'id': device.devid,
            'is_mobile': not 'generic_web_browser' in device_parents[device.devid],
            'brand_name': device.brand_name,
            'model_name': device.model_name,
            'ua': ua,
            'matched_ua': device.devua,
            'accept': request.META.get('HTTP_ACCEPT', ''),
            'formats': formats
        })

        if request.GET.get('capabilities') == 'true':
            context['capabilities'] = dict((k, getattr(device, k)) for k in dir(device) if (not k.startswith('_') and not k.startswith('dev') and not k in ('groups','children')))

        return self.render(request, context, 'wurfl/index')