Beispiel #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)
Beispiel #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')
Beispiel #3
0
    def handle(self, *args, **options):
        cursor = connection.cursor()
        
        start = dateutil.parser.parse(options['start'])
        end = dateutil.parser.parse(options['end'])
        
        cursor.execute("""
            SELECT device_id, COUNT(DISTINCT session_key)
            FROM stats_hit
            WHERE full_path = '/' AND requested >= '%s' AND requested < '%s'
            GROUP BY device_id""" % (start.isoformat(), end.isoformat()))
            
        platforms = {}
        for row in cursor.fetchall():
            device, id_, model = None, row[0], None
            while id_:
                try:
                    device = devices.select_id(id_)
                except:
                    id_ = '_'.join(id_.split('_')[:-1])
                else:
                    break
            else:
                device = devices.select_id('generic')
            
            operating_system = self.operating_system_topics.get(device.device_os, L(device.device_os) or None)
            manufacturer = self.manufacturer_topics.get(device.brand_name, (L(device.brand_name) or None, None))
            if isinstance(manufacturer, tuple):
                manufacturer, model = manufacturer
            if model is None:
                model = self.marketing_name_topics.get((device.brand_name, device.marketing_name))
            if model is None:
                model = self.model_topics.get((device.brand_name, device.model_name))
            if model is None:
                model = self.marketing_name_topics.get(device.marketing_name)
            if model is None:
                model = self.model_topics.get(device.model_name, L(device.model_name) or None)
            if isinstance(model, tuple):
                manufacturer, model = model
                
            sig = (manufacturer, model, operating_system)
            count, device_ids = platforms.get(sig, (0, set()))
            device_ids.add(id_)
            platforms[sig] = count + row[1], device_ids

        g = rdflib.ConjunctiveGraph()
        g.namespace_manager.bind('scv', SCV)
        g.namespace_manager.bind('dct', DCT)
        g.namespace_manager.bind('mox', MOX)
        g.namespace_manager.bind('void', VOID)
        g.namespace_manager.bind('sdmx', SDMX)
        g.namespace_manager.bind('dcat', DCAT)
        g.namespace_manager.bind('dc', DC)
        
        g.parse(StringIO.StringIO(DEFINITION % options), format='n3')
        dataset = rdflib.URIRef(options['dataset'])
        duration = end - start
        time_period = rdflib.BNode()
        g.add((time_period, SCV.min, rdflib.Literal(start)))
        g.add((time_period, SCV.max, rdflib.Literal(end)))
        
        incomplete = {}
        for (manufacturer, model, operating_system), (count, device_ids) in platforms.items():
            item = rdflib.BNode()
            g.add((item, RDF.type, SCV.Item))
            g.add((item, SCV.dataset, dataset))
            g.add((item, RDF.value, rdflib.Literal(int(count))))
            
            g.add((item, MOX.manufacturer, self.dbpedia(g, manufacturer)))
            g.add((item, MOX.userAgent, self.dbpedia(g, model)))
            g.add((item, MOX.operatingSystem, self.dbpedia(g, operating_system)))
            g.add((item, SDMX.timePeriod, time_period))
            
            for device_id in device_ids:
                g.add((item, DC.identifier, rdflib.Literal(device_id)))
            
            if isinstance(manufacturer, L) or isinstance(model, L) or isinstance(operating_system, L):
                incomplete[(manufacturer, model, operating_system)] = count
        
        #pprint.PrettyPrinter().pprint(incomplete)
        print g.serialize(format='pretty-xml')