# Bloom SMS component # # Kevin Tom # Copyright 2008 Handi Mobility # www.handimobility.ca import types from django.conf import settings from bloom.sms.models import SentSMS, ReceivedSMS from bloom.utils import get_setting SMS_PROVIDER_UPSIDE = 'UPSIDE' SMS_SERVICE_PROVIDER = get_setting('SMS_SERVICE_PROVIDER') if SMS_SERVICE_PROVIDER == SMS_PROVIDER_UPSIDE: from bloom.sms.lib.upside.connector import UpsideConnector from bloom.sms.lib.upside.connector import upside_receive_sms SMS_SERVICE_USERNAME = get_setting('SMS_SERVICE_USERNAME') SMS_SERVICE_PASSWORD = get_setting('SMS_SERVICE_PASSWORD') SMS_RECORD_SENT = get_setting('SMS_RECORD_SENT', override=False) SMS_RECORD_RECEIVED = get_setting('SMS_RECORD_RECEIVED', override=False) class SendSMS(object): def __init__(self): if SMS_SERVICE_PROVIDER == SMS_PROVIDER_UPSIDE: self.connector = UpsideConnector(SMS_SERVICE_USERNAME, SMS_SERVICE_PASSWORD)
>>> path_to_device_atlas_json = '/Users/johnboxall/djcode/deviceatlas/DeviceAtlas.json' >>> tree = da.getTreeFromFile(path_to_device_atlas_json) >>> da.getTreeRevision(tree) 2590 >>> ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3' >>> da.getProperties(tree, ua) {u'gprs': '1', u'memoryLimitDownload': '0', u'mpeg4': '1', u'image.Png': '1', u'memoryLimitEmbeddedMedia': '0', u'umts': '0', u'displayWidth': '320', u'mp3': '1', u'usableDisplayHeight': '360', u'markup.xhtmlMp10': '1', u'cookieSupport': '0', u'markup.xhtmlMp12': '1', u'isSpam': '0', u'image.Gif89a': '1', u'h263Type3InVideo': '0', u'midiPolyphonic': '0', u'image.Gif87': '1', u'isChecker': '0', u'markup.xhtmlMp11': '1', u'csd': '0', u'3gpp': '0', u'drmOmaForwardLock': '0', u'qcelp': '0', u'wmv': '0', u'id': '205202', u'markup.xhtmlBasic10': '1', u'aacLtpInVideo': '0', u'amrInVideo': '0', u'qcelpInVideo': '0', u'https': '1', u'memoryLimitMarkup': '0', u'3gpp2': '0', u'hscsd': '0', u'aacInVideo': '1', u'drmOmaSeparateDelivery': '0', u'displayColorDepth': '8', u'vendor': 'Apple', u'image.Jpg': '1', u'uriSchemeTel': '1', u'isRobot': '1', u'mobileDevice': '1', u'isBrowser': '0', '_unmatched': 'one; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3', u'isFilter': '0', u'isDownloader': '0', u'hsdpa': '0', u'amr': '0', u'model': 'iPhone', u'drmOmaCombinedDelivery': '0', u'aac': '1', u'mpeg4InVideo': '1', u'awbInVideo': '0', u'edge': '1', u'usableDisplayWidth': '320', u'h263Type0InVideo': '0', u'displayHeight': '480', u'midiMonophonic': '0', '_matched': 'Mozilla/5.0 (iPh'} """ import time from distutils.sysconfig import get_python_lib from django.conf import settings from deviceatlas.api import DaApi from bloom.utils import get_setting device_atlas = DaApi() default_da_path = "%s/deviceatlas/DeviceAtlas.json" % get_python_lib() DEVICE_ATLAS_PATH = get_setting('DEVICE_ATLAS_PATH', override=default_da_path) try: device_atlas_tree = device_atlas.getTreeFromFile(DEVICE_ATLAS_PATH) except Exception: raise Exception("Couldn\'t find Device Atlas JSON Library. Check BLOOM_DEVICE_ATLAS_PATH") def get_device(request): ua = request.META.get('HTTP_USER_AGENT', '') return device_atlas.getPropertiesAsTyped(device_atlas_tree, ua)
2590 >>> ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3' >>> da.getProperties(tree, ua) {u'gprs': '1', u'memoryLimitDownload': '0', u'mpeg4': '1', u'image.Png': '1', u'memoryLimitEmbeddedMedia': '0', u'umts': '0', u'displayWidth': '320', u'mp3': '1', u'usableDisplayHeight': '360', u'markup.xhtmlMp10': '1', u'cookieSupport': '0', u'markup.xhtmlMp12': '1', u'isSpam': '0', u'image.Gif89a': '1', u'h263Type3InVideo': '0', u'midiPolyphonic': '0', u'image.Gif87': '1', u'isChecker': '0', u'markup.xhtmlMp11': '1', u'csd': '0', u'3gpp': '0', u'drmOmaForwardLock': '0', u'qcelp': '0', u'wmv': '0', u'id': '205202', u'markup.xhtmlBasic10': '1', u'aacLtpInVideo': '0', u'amrInVideo': '0', u'qcelpInVideo': '0', u'https': '1', u'memoryLimitMarkup': '0', u'3gpp2': '0', u'hscsd': '0', u'aacInVideo': '1', u'drmOmaSeparateDelivery': '0', u'displayColorDepth': '8', u'vendor': 'Apple', u'image.Jpg': '1', u'uriSchemeTel': '1', u'isRobot': '1', u'mobileDevice': '1', u'isBrowser': '0', '_unmatched': 'one; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3', u'isFilter': '0', u'isDownloader': '0', u'hsdpa': '0', u'amr': '0', u'model': 'iPhone', u'drmOmaCombinedDelivery': '0', u'aac': '1', u'mpeg4InVideo': '1', u'awbInVideo': '0', u'edge': '1', u'usableDisplayWidth': '320', u'h263Type0InVideo': '0', u'displayHeight': '480', u'midiMonophonic': '0', '_matched': 'Mozilla/5.0 (iPh'} """ import time from distutils.sysconfig import get_python_lib from django.conf import settings from deviceatlas.api import DaApi from bloom.utils import get_setting device_atlas = DaApi() default_da_path = "%s/deviceatlas/DeviceAtlas.json" % get_python_lib() DEVICE_ATLAS_PATH = get_setting('DEVICE_ATLAS_PATH', override=default_da_path) try: device_atlas_tree = device_atlas.getTreeFromFile(DEVICE_ATLAS_PATH) except Exception: raise DeviceAtlasJSONNotFoundException( "Couldn\'t find Device Atlas JSON Library. Check BLOOM_DEVICE_ATLAS_PATH" ) def get_device(request): ua = request.META['HTTP_USER_AGENT'] return device_atlas.getPropertiesAsTyped(device_atlas_tree, ua)
# Copyright 2008 Handi Mobility # www.handimobility.ca from urllib2 import urlopen from urllib import urlencode try: # Python >= 2.5 from hashlib import md5 except ImportError: # Python < 2.5 import md5 from bloom.utils import get_setting DEBUG = get_setting("AD_ADMOB_DEBUG") SITE_ID = get_setting("AD_ADMOB_SITE_ID") def get_admob(request, admob_params=None): """ Given a Django `request` object and dict of admob parameters returns a Admob ad. If no ad can be retrieved displays a one pixel Admob tracker image. Usage: def my_view(request): admob_dict = {}
# John Boxall # Copyright 2008 Handi Mobility # www.handimobility.ca from urllib2 import urlopen from urllib import urlencode try: # Python >= 2.5 from hashlib import md5 except ImportError: # Python < 2.5 import md5 from bloom.utils import get_setting DEBUG = get_setting("AD_ADMOB_DEBUG") SITE_ID = get_setting("AD_ADMOB_SITE_ID") def get_admob(request, admob_params=None): """ Given a Django `request` object and dict of admob parameters returns a Admob ad. If no ad can be retrieved displays a one pixel Admob tracker image. Usage: def my_view(request):
# Models for Bloom Share component # # Kevin Tom # Copyright 2008 Handi Mobility # www.handimobility.ca from django.db import models from django.contrib import admin from django.contrib.auth.models import User from bloom.utils import get_setting SHARE_BASE_URL = get_setting('SHARE_BASE_URL') class SharedLink(models.Model): sharer = models.ForeignKey(User,related_name='sharedlink_set') original_url = models.URLField() generated_slug = models.CharField(max_length=40, unique=True) sharee = models.ForeignKey(User,related_name='receivedlink_set') ctime = models.DateTimeField(auto_now_add=True) utime = models.DateTimeField(auto_now=True) medium = models.CharField(max_length=10) def __unicode__(self): return "%s -> %s" % (self.generated_slug, self.original_url,) def get_shared_url(self): return "%s/%s" % (SHARE_BASE_URL, self.generated_slug,) class Admin: pass
# Bloom SMS component # # Kevin Tom # Copyright 2008 Handi Mobility # www.handimobility.ca import types from django.conf import settings from bloom.sms.models import SentSMS, ReceivedSMS from bloom.utils import get_setting SMS_PROVIDER_UPSIDE = "UPSIDE" SMS_SERVICE_PROVIDER = get_setting("SMS_SERVICE_PROVIDER") if SMS_SERVICE_PROVIDER == SMS_PROVIDER_UPSIDE: from bloom.sms.lib.upside.connector import UpsideConnector from bloom.sms.lib.upside.connector import upside_receive_sms SMS_SERVICE_USERNAME = get_setting("SMS_SERVICE_USERNAME") SMS_SERVICE_PASSWORD = get_setting("SMS_SERVICE_PASSWORD") SMS_RECORD_SENT = get_setting("SMS_RECORD_SENT", override=False) SMS_RECORD_RECEIVED = get_setting("SMS_RECORD_RECEIVED", override=False) class SendSMS(object): def __init__(self): if SMS_SERVICE_PROVIDER == SMS_PROVIDER_UPSIDE: self.connector = UpsideConnector(SMS_SERVICE_USERNAME, SMS_SERVICE_PASSWORD)
# www.handimobility.ca import random, string from django.conf import settings from django.shortcuts import get_object_or_404 from django.core.mail import send_mail from django.template import Context from django.template.loader import render_to_string from bloom.sms import send_sms from bloom.utils import get_setting from bloom.share.models import SharedLink from bloom.user.utils import get_or_create_user_by_phonenumber, get_or_create_user_by_email SHARE_BASE_URL = get_setting('SHARE_BASE_URL') SHARE_SLUG_LENGTH = get_setting('SHARE_SLUG_LENGTH', override=5) VALID_CHARS = string.ascii_lowercase + string.ascii_uppercase + string.digits def lookup_url(request, slug): "Returns the URL belonging to this slug if it exists" queryresults = get_object_or_404(SharedLink, generated_slug=slug) return queryresults.original_url def share_url(sharer, url, medium, sharee): for i in range(1,10): slug = generate_slug(settings.BLOOM_SHARE_SLUG_LENGTH) share_dict = {'sharer':sharer, 'original_url':url, 'medium':medium, 'sharee':sharee} slink, created = SharedLink.objects.get_or_create(generated_slug=slug, defaults=share_dict)