def create_content(**kwargs): content = Content(id=str(Autoincr.get()), timestamp=Services.time.time(), **kwargs) content.save() # Throw in some fake details. We never test this anywhere, but remixes depend on being able to hit some details of their original. fake_details = '{"activity": {"width": 60, "kb": 1, "name": "processed/d763f53f918b20b562a26e9b3e3688109297ce68.png", "height": 25}, "small_square": {"width": 50, "kb": 1, "name": "processed/d763f53f918b20b562a26e9b3e3688109297ce68.png", "height": 25}, "archive": {"width": 50, "kb": 1, "name": "processed/d763f53f918b20b562a26e9b3e3688109297ce68.png", "height": 25}, "gallery": {"width": 50, "kb": 1, "name": "processed/d763f53f918b20b562a26e9b3e3688109297ce68.png", "height": 25}, "giant": {"width": 64, "height": 32, "name": "processed/c72db1199d63872f87e59687f2bb71cef543cd62.png", "kb": 1}, "stream": {"width": 64, "height": 32, "name": "processed/c72db1199d63872f87e59687f2bb71cef543cd62.png", "kb": 1}, "column": {"width": 64, "height": 32, "name": "processed/c72db1199d63872f87e59687f2bb71cef543cd62.png", "kb": 1}, "original": {"width": 64, "height": 32, "name": "original/a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89.png", "kb": 1}, "id": "a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89", "alpha": true, "small_column": {"width": 64, "height": 32, "name": "processed/c72db1199d63872f87e59687f2bb71cef543cd62.png", "kb": 1}, "thumbnail": {"width": 64, "height": 32, "name": "processed/c72db1199d63872f87e59687f2bb71cef543cd62.png", "kb": 1}}' redis.set("content:%s:details" % content.id, fake_details) return content
def create_content(**kwargs): content = Content(id=str(Autoincr.get()), timestamp=Services.time.time(), **kwargs) content.save() # Throw in some fake details. We never test this anywhere, but remixes depend on being able to hit some details of their original. fake_details = "{\"activity\": {\"width\": 60, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"small_square\": {\"width\": 50, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"archive\": {\"width\": 50, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"gallery\": {\"width\": 50, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"giant\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"stream\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"column\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"original\": {\"width\": 64, \"height\": 32, \"name\": \"original/a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89.png\", \"kb\": 1}, \"id\": \"a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89\", \"alpha\": true, \"small_column\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"thumbnail\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}}" redis.set('content:%s:details' % content.id, fake_details) return content
def create_content(ip, fs, data, remix_of, stamps_used, text_used, source_url='', is_quest=False): exclude_types = [] if settings.PROJECT == 'drawquest': if not is_quest: exclude_types = ['homepage_featured'] meta = generate_thumbnails(data, fs=fs, exclude_types=exclude_types) if remix_of: remix_of = Content.all_objects.get(id=remix_of) remix_of.hide_if_unpublished() else: remix_of = None if stamps_used: stamps_used = [Content.all_objects.get_or_none(id=stamp_id) for stamp_id in stamps_used if stamp_id] stamps_used = [stamp for stamp in stamps_used if stamp] try: content = Content.all_objects.get(id=meta['id']) # Don't allow uploading content that has been disabled. if content.visibility == Visibility.DISABLED: return { 'success': False, 'reason': 'This image has been banned.', } except Content.DoesNotExist: url_mapping = ContentUrlMapping() url_mapping.save() content = Content( id = meta['id'], visibility = Visibility.UNPUBLISHED, url_mapping = url_mapping, ip = ip, timestamp = time(), remix_of = remix_of, remix_text = text_used, source_url = source_url, ) update_metadata(content, meta) try: content.save() except IntegrityError: # Race condition, retry return create_content(ip, fs, data, remix_of, stamps_used, text_used, source_url) content.stamps_used.add(*stamps_used) redis.set(content.details_key, util.dumps(meta)) existing_url = content.first_caption and content.first_caption.details().url return {'success': True, 'content': content.details.force(), 'existing_url': existing_url}
def get_user_data(viewer, nav): viewer_is_staff = viewer.is_authenticated() and viewer.is_staff user_can_see_anonymous = (nav.user.id == viewer.id or viewer_is_staff) content_manager = Content.get_appropriate_manager(viewer) posts = [] # Not a banned account, or you're allowed to see banned accounts. if nav.user.is_active or viewer_is_staff: if nav.userpage_type == 'top': if not user_can_see_anonymous: posts = get_user_top_posted(nav.user, content_manager, nav.slice) else: posts = get_user_top_posted(nav.user, content_manager, nav.slice, anonymous=True, namefriend=True) elif user_can_see_anonymous and nav.userpage_type == 'top_anonymous': posts = get_user_top_posted(nav.user, content_manager, nav.slice, anonymous=True, namefriend=False) elif nav.userpage_type == 'new': if user_can_see_anonymous: posts = get_user_posted(nav.user, manager=content_manager, anonymous=True, namefriend=True)[nav.slice] else: posts = get_user_posted(nav.user, manager=content_manager)[nav.slice] elif user_can_see_anonymous and nav.userpage_type == 'new_anonymous': posts = get_user_posted(nav.user, manager=content_manager, anonymous=True, namefriend=False)[nav.slice] elif nav.userpage_type == 'stickered': posts = get_user_stickered(nav.user)[nav.slice] else: raise Http404 return TileDetails.from_queryset_with_viewer_stickers(viewer, posts) return []
def create_content(**kwargs): url_mapping = ContentUrlMapping() url_mapping.save() content = Content( id=str(Autoincr.get()), url_mapping=url_mapping, timestamp=Services.time.time(), **kwargs ) content.save() # Throw in some fake details. We never test this anywhere, but remixes depend on being able to hit some details of their original. fake_details = "{\"activity\": {\"width\": 60, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"small_square\": {\"width\": 50, \"kb\": 1, \"name\": \"processed/d763f53f918b20b562a26e9b3e3688109297ce68.png\", \"height\": 25}, \"giant\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"stream\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"column\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"original\": {\"width\": 64, \"height\": 32, \"name\": \"original/a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89.png\", \"kb\": 1}, \"id\": \"a023129be8f5c3fe3e7f500bc5b21a4f6df6bf89\", \"alpha\": true, \"small_column\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}, \"thumbnail\": {\"width\": 64, \"height\": 32, \"name\": \"processed/c72db1199d63872f87e59687f2bb71cef543cd62.png\", \"kb\": 1}}" redis.set('content:%s:details' % content.id, fake_details) return content
def create_content(ip, fs, data, remix_of, stamps_used, text_used, source_url='', is_quest=False): exclude_types = [] if settings.PROJECT == 'drawquest': if not is_quest: exclude_types = ['homepage_featured'] meta = generate_thumbnails(data, fs=fs, exclude_types=exclude_types) if remix_of: remix_of = Content.all_objects.get(id=remix_of) remix_of.hide_if_unpublished() else: remix_of = None if stamps_used: stamps_used = [ Content.all_objects.get_or_none(id=stamp_id) for stamp_id in stamps_used if stamp_id ] stamps_used = [stamp for stamp in stamps_used if stamp] try: content = Content.all_objects.get(id=meta['id']) # Don't allow uploading content that has been disabled. if content.visibility == Visibility.DISABLED: return { 'success': False, 'reason': 'This image has been banned.', } except Content.DoesNotExist: url_mapping = ContentUrlMapping() url_mapping.save() content = Content( id=meta['id'], visibility=Visibility.UNPUBLISHED, url_mapping=url_mapping, ip=ip, timestamp=time(), remix_of=remix_of, remix_text=text_used, source_url=source_url, ) update_metadata(content, meta) try: content.save() except IntegrityError: # Race condition, retry return create_content(ip, fs, data, remix_of, stamps_used, text_used, source_url) content.stamps_used.add(*stamps_used) redis.set(content.details_key, util.dumps(meta)) existing_url = content.first_caption and content.first_caption.details( ).url return { 'success': True, 'content': content.details.force(), 'existing_url': existing_url }
def create_content(ip, fs, data, remix_of, stamps_used, is_quest=False): from drawquest.apps.content_metadata.models import save_content_metadata_from_legacy_dict util.papertrail.debug('UPLOADS: create_content, is_quest={}'.format(is_quest)) exclude_types = [] if not is_quest: exclude_types = ['homepage_featured'] meta = generate_thumbnails(data, fs=fs, exclude_types=exclude_types) util.papertrail.debug('UPLOADS: thumbnails generated for ID {}'.format(meta['id'])) if remix_of: remix_of = Content.all_objects.get(id=remix_of) remix_of.hide_if_unpublished() else: remix_of = None if stamps_used: stamps_used = [Content.all_objects.get_or_none(id=stamp_id) for stamp_id in stamps_used if stamp_id] stamps_used = [stamp for stamp in stamps_used if stamp] try: util.papertrail.debug('UPLOADS: trying to get existing content with ID {}'.format(meta['id'])) content = Content.all_objects.get(id=meta['id']) util.papertrail.debug('UPLOADS: got existing content for ID {}'.format(meta['id'])) # Don't allow uploading content that has been disabled. if content.visibility == Visibility.DISABLED: return { 'success': False, 'reason': 'This image has been banned.', } except Content.DoesNotExist: util.papertrail.debug('UPLOADS: creating content with ID {}'.format(meta['id'])) content = Content( id = meta['id'], visibility = Visibility.UNPUBLISHED, ip = ip, timestamp = time(), remix_of = remix_of, ) util.papertrail.debug('UPLOADS: instantiated content with ID {}'.format(meta['id'])) try: content.save(force_insert=True) util.papertrail.debug('UPLOADS: saved content with ID {}'.format(meta['id'])) util.papertrail.debug('UPLOADS: saved content with ID {}, has pk {}'.format(meta['id'], content.pk)) util.papertrail.debug('UPLOADS: actual content object for ID {} exists: {}'.format(meta['id'], Content.all_objects.filter(id=meta['id']).exists())) util.papertrail.debug('UPLOADS: actual content object for ID {} exists using pk: {}'.format(meta['id'], Content.all_objects.filter(id=content.pk).exists())) util.papertrail.debug('UPLOADS: actual content object for ID {} exists using pk2: {}'.format(meta['id'], Content.all_objects.filter(pk=content.pk).exists())) except IntegrityError: util.papertrail.debug('UPLOADS: integrity error when trying to create content with ID {}'.format(meta['id'])) # Race condition, retry return create_content(ip, fs, data, remix_of, stamps_used, is_quest=is_quest) content.stamps_used.add(*stamps_used) util.papertrail.debug('UPLOADS: creating metadata for ID {}'.format(meta['id'])) save_content_metadata_from_legacy_dict(content, meta) util.papertrail.debug('UPLOADS: created metadata for ID {}'.format(meta['id'])) util.papertrail.debug('UPLOADS: returning metadata for ID {}'.format(meta['id'])) return {'success': True, 'content': content.details.force()}
def create_content(ip, fs, data, remix_of, stamps_used, is_quest=False): from drawquest.apps.content_metadata.models import save_content_metadata_from_legacy_dict util.papertrail.debug( 'UPLOADS: create_content, is_quest={}'.format(is_quest)) exclude_types = [] if not is_quest: exclude_types = ['homepage_featured'] meta = generate_thumbnails(data, fs=fs, exclude_types=exclude_types) util.papertrail.debug('UPLOADS: thumbnails generated for ID {}'.format( meta['id'])) if remix_of: remix_of = Content.all_objects.get(id=remix_of) remix_of.hide_if_unpublished() else: remix_of = None if stamps_used: stamps_used = [ Content.all_objects.get_or_none(id=stamp_id) for stamp_id in stamps_used if stamp_id ] stamps_used = [stamp for stamp in stamps_used if stamp] try: util.papertrail.debug( 'UPLOADS: trying to get existing content with ID {}'.format( meta['id'])) content = Content.all_objects.get(id=meta['id']) util.papertrail.debug('UPLOADS: got existing content for ID {}'.format( meta['id'])) # Don't allow uploading content that has been disabled. if content.visibility == Visibility.DISABLED: return { 'success': False, 'reason': 'This image has been banned.', } except Content.DoesNotExist: util.papertrail.debug('UPLOADS: creating content with ID {}'.format( meta['id'])) content = Content( id=meta['id'], visibility=Visibility.UNPUBLISHED, ip=ip, timestamp=time(), remix_of=remix_of, ) util.papertrail.debug( 'UPLOADS: instantiated content with ID {}'.format(meta['id'])) try: content.save(force_insert=True) util.papertrail.debug('UPLOADS: saved content with ID {}'.format( meta['id'])) util.papertrail.debug( 'UPLOADS: saved content with ID {}, has pk {}'.format( meta['id'], content.pk)) util.papertrail.debug( 'UPLOADS: actual content object for ID {} exists: {}'.format( meta['id'], Content.all_objects.filter(id=meta['id']).exists())) util.papertrail.debug( 'UPLOADS: actual content object for ID {} exists using pk: {}'. format(meta['id'], Content.all_objects.filter(id=content.pk).exists())) util.papertrail.debug( 'UPLOADS: actual content object for ID {} exists using pk2: {}' .format(meta['id'], Content.all_objects.filter(pk=content.pk).exists())) except IntegrityError: util.papertrail.debug( 'UPLOADS: integrity error when trying to create content with ID {}' .format(meta['id'])) # Race condition, retry return create_content(ip, fs, data, remix_of, stamps_used, is_quest=is_quest) content.stamps_used.add(*stamps_used) util.papertrail.debug('UPLOADS: creating metadata for ID {}'.format( meta['id'])) save_content_metadata_from_legacy_dict(content, meta) util.papertrail.debug('UPLOADS: created metadata for ID {}'.format( meta['id'])) util.papertrail.debug('UPLOADS: returning metadata for ID {}'.format( meta['id'])) return {'success': True, 'content': content.details.force()}