def collection(apps, slug, background_image=True, **kw): region = REGIONS_DICT[kw.get('region', 'restofworld')].id colorname = kw.get('color', random.choice(COLLECTION_COLORS.keys())) co = FeedCollection.objects.create( type=kw.get('type', 'listing'), color=colorname, background_color=COLLECTION_COLORS[colorname], slug=slug, description=kw.get('description', '')) name = kw.get('name', 'Collection %s' % co.pk) if background_image: gen = pydenticon.Generator(8, 8, foreground=foreground) img = gen.generate(name, 128, 128, output_format='png') with storage.open(co.image_path(''), 'wb') as f: f.write(img) image_hash = hashlib.md5(img).hexdigest()[:8] else: image_hash = None co.name = name co.image_hash = image_hash co.save() for a in apps: FeedCollectionMembership.objects.create(obj=co, app=a) FeedItem.objects.create(item_type='collection', collection=co, region=region) return co
def collection(apps, slug, background_image=True, **kw): region = REGIONS_DICT[kw.get('region', 'restofworld')].id colorname = kw.get('color', random.choice(COLLECTION_COLORS.keys())) co = FeedCollection.objects.create( type=kw.get('type', 'listing'), color=colorname, background_color=COLLECTION_COLORS[colorname], slug=slug, description=kw.get('description', '')) name = kw.get('name', 'Collection %s' % co.pk) if background_image: gen = pydenticon.Generator(8, 8, foreground=foreground) img = gen.generate(name, 128, 128, output_format='png') with public_storage.open(co.image_path(''), 'wb') as f: f.write(img) image_hash = hashlib.md5(img).hexdigest()[:8] else: image_hash = None co.name = name co.image_hash = image_hash co.save() for a in apps: FeedCollectionMembership.objects.create(obj=co, app=a) FeedItem.objects.create(item_type='collection', collection=co, region=region) return co
def app_item(a, type, **kw): region = REGIONS_DICT[kw.get('region', 'restofworld')].id colorname = kw.get('color', random.choice(COLLECTION_COLORS.keys())) gen = pydenticon.Generator(8, 8, foreground=foreground) img = gen.generate(a.app_slug, 128, 128, output_format='png') ap = FeedApp.objects.create( app=a, description=kw.get('description', rand_text(12)), type=type, color=colorname, preview=kw.get('preview', None), pullquote_attribution=kw.get('pullquote_attribution', None), pullquote_rating=kw.get('pullquote_rating', None), pullquote_text=kw.get('pullquote_text', None), background_color=COLLECTION_COLORS[colorname], slug=kw.get('slug', 'feed-app-%d' % a.pk)) with public_storage.open(ap.image_path(''), 'wb') as f: f.write(img) image_hash = hashlib.md5(img).hexdigest()[:8] ap.update(image_hash=image_hash) FeedItem.objects.create(item_type='app', app=ap, region=region) return ap
def app_item(a, type, **kw): region = REGIONS_DICT[kw.get('region', 'restofworld')].id colorname = kw.get('color', random.choice(COLLECTION_COLORS.keys())) gen = pydenticon.Generator(8, 8, foreground=foreground) img = gen.generate(a.app_slug, 128, 128, output_format='png') ap = FeedApp.objects.create( app=a, description=kw.get('description', rand_text(12)), type=type, color=colorname, preview=kw.get('preview', None), pullquote_attribution=kw.get('pullquote_attribution', None), pullquote_rating=kw.get('pullquote_rating', None), pullquote_text=kw.get('pullquote_text', None), background_color=COLLECTION_COLORS[colorname], slug=kw.get('slug', 'feed-app-%d' % a.pk)) with storage.open(ap.image_path(''), 'wb') as f: f.write(img) image_hash = hashlib.md5(img).hexdigest()[:8] ap.update(image_hash=image_hash) FeedItem.objects.create(item_type='app', app=ap, region=region) return ap
""" Generate Feed-related objects. """ import random from mpconstants.collection_colors import COLLECTION_COLORS from factory import app, carrier, preview, region from factory.constants import AUTHORS, SAMPLE_BG from factory.utils import rand_bool, rand_text, text counter = 0 COLLECTION_COLORS = COLLECTION_COLORS.items() FEED_APP_TYPES = [ 'icon', 'image', 'description', 'quote', 'preview' ] def feed_item(**kw): global counter counter += 1 return dict({ 'app': feed_app(),
""" Generate Feed-related objects. """ import random from mpconstants.collection_colors import COLLECTION_COLORS from factory import app, carrier, preview, region from factory.constants import AUTHORS, SAMPLE_BG from factory.utils import rand_bool, rand_text, text counter = 0 COLLECTION_COLORS = COLLECTION_COLORS.items() FEED_APP_TYPES = [ 'icon', 'image', 'description', 'quote', 'preview' ] def feed_item(**kw): global counter counter += 1 return dict({ 'app': feed_app(),