<commit_before>from datetime import datetime, timedelta
from mobile_portal.wurfl import device_parents

from mobile_portal.weather.models import Weather
from mobile_portal.core.models import UserMessage

DEVICE_SPECIFIC_MEDIA = {
#    'apple_iphone_ver1': {
#        'js': frozenset(['js/devices/apple_iphone.js']),
#        'css': frozenset(['css/devices/apple_iphone.css']),
#    },
#    'blackberry_generic_ver4_sub10': {
#        'js': frozenset(),
#        'css': frozenset(['css/devices/rim_blackberry.css']),
#    },
#    'generic': { # Firefox, actually
#        'js': frozenset(['js/devices/apple_iphone.js']),
#        'css': frozenset(['css/devices/apple_iphone.css']),
#    }
}


DEVICE_SPECIFIC_MEDIA_SET = frozenset(DEVICE_SPECIFIC_MEDIA)

def device_specific_media(request):
    """
    Uses DEVICE_SPECIFIC_MEDIA as a basis to pass extra context when the
    wurfl-detected device is a child of a given device id.
    """

    device, browser = request.device, request.browser
    
    if browser.devid == 'generic_skyfire':
        style_group = "dumb"
    if device.brand_name == 'Apple' and tuple(map(int, device.device_os_version.split('.'))) >= (1,):
        style_group = "smart"
    elif device.device_os == 'Symbian' and tuple(map(int, device.device_os_version.split('.'))) >= 9.2 : 
        style_group = "smart"
    elif device.brand_name == 'RIM' :
        style_group = 'smart'
    elif device.device_os == 'Android' :
        style_group = 'smart'
    elif device.device_os == 'Web OS' :
        style_group = 'smart'
    elif browser.brand_name == 'Opera':
        style_group = 'smart'
    elif 'generic_web_browser' in device_parents[browser.devid]:
        style_group = 'smart'
    else:
        style_group = "dumb"
    return {
        'style_group': style_group,
    }    

def geolocation(request):
    """
    Provides location-based information to the template (i.e. lat/long, google
    placemark data, and whether we would like to request the device's location
    information.
    """
    
    # Use the epoch in the place of -inf; a time it has been a while since.
    epoch = datetime(1970,1,1, 0, 0, 0)
    
    # Only request a location if our current location is older than one minute
    # and the user isn't updating their location manually.
    # The one minute timeout applies to the more recent of a request and an
    # update.
    
    location = request.preferences['location']
    requested = location['requested'] or epoch
    updated = location['updated'] or epoch
    method = location['method'] or epoch
    
    if max(requested, updated) + timedelta(0, 60) < datetime.now() and method in ('html5', 'gears', None):
        require_location = True
        location['requested'] = datetime.now()<commit_msg>Pull changeset 1630 to tag 0.2<commit_after>from datetime import datetime, timedelta
from mobile_portal.wurfl import device_parents

from mobile_portal.weather.models import Weather
from mobile_portal.core.models import UserMessage

DEVICE_SPECIFIC_MEDIA = {
#    'apple_iphone_ver1': {
#        'js': frozenset(['js/devices/apple_iphone.js']),
#        'css': frozenset(['css/devices/apple_iphone.css']),
#    },
#    'blackberry_generic_ver4_sub10': {
#        'js': frozenset(),
#        'css': frozenset(['css/devices/rim_blackberry.css']),
#    },
#    'generic': { # Firefox, actually
#        'js': frozenset(['js/devices/apple_iphone.js']),
#        'css': frozenset(['css/devices/apple_iphone.css']),
#    }
}


DEVICE_SPECIFIC_MEDIA_SET = frozenset(DEVICE_SPECIFIC_MEDIA)

def device_specific_media(request):
    """
    Uses DEVICE_SPECIFIC_MEDIA as a basis to pass extra context when the
    wurfl-detected device is a child of a given device id.
    """

    device, browser = request.device, request.browser
    
    # Skyfire
    if browser.devid == 'generic_skyfire':
        style_group = "dumb"
        
    # Apple products
    elif device.brand_name == 'Apple' :
        style_group = "smart"
        
    # Symbian S60 v3 and above (iresspective of browser)
    elif device.device_os == 'Symbian' and tuple(map(int, device.device_os_version.split('.'))) >= 9.2 : 
        style_group = "smart"
    # Nokia Maemo 
    elif device.brand_name == 'Nokia' and device.device_os == 'Linux Smartphone OS'
        style_group = "smart"
        
    # Blackberries 
    elif device.brand_name == 'RIM' :
        style_group = 'smart'
        
    # Android
    elif device.device_os == 'Android' :
        style_group = 'smart'
        
    # Palm Web OS
    elif device.device_os == 'Web OS' :
        style_group = 'smart'
        
    # Opera Mini/Mobile Browsers
    elif browser.brand_name == 'Opera':
        style_group = 'smart'
        
    # Desktop browsers
    elif 'generic_web_browser' in device_parents[browser.devid]:
        style_group = 'smart'
        
    # All Others
    else:
        style_group = "dumb"
    return {
        'style_group': style_group,
    }    

def geolocation(request):
    """
    Provides location-based information to the template (i.e. lat/long, google
    placemark data, and whether we would like to request the device's location
    information.
    """
    
    # Use the epoch in the place of -inf; a time it has been a while since.
    epoch = datetime(1970,1,1, 0, 0, 0)
    
    # Only request a location if our current location is older than one minute
    # and the user isn't updating their location manually.
    # The one minute timeout applies to the more recent of a request and an
    # update.
    
    location = request.preferences['location']
    requested = location['requested'] or epoch
    updated = location['updated'] or epoch
    method = location['method'] or epoch
    
    if max(requested, updated) + timedelta(0, 60) < datetime.now() and method in ('html5', 'gears', None):
        require_location = True
        location['requested'] = datetime.now()
{'fraction_non_alphanumeric': 0.11470140416173236, 'fraction_numerical': 0.008120453391981051, 'mean_word_length': 2.907468605419696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986845', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1825, 'n_words': 497}