def create_gif_content(**kwargs): content = create_content(**kwargs) key = "content:%s:details" % content.id details = util.loads(redis.get(key)) details["original"]["animated"] = True redis.set(key, util.dumps(details)) return content
def create_gif_content(**kwargs): content = create_content(animated=True, **kwargs) key = 'content:%s:details' % content.id details = util.loads(redis.get(key)) details['original']['animated'] = True redis.set(key, util.dumps(details)) return content
def update(self, fs=None, web=None): """ Renders the footer image and saves it to the filesystem (i.e. S3 in production). `web` is an optional perf optimization. """ from canvas.thumbnailer import generate_thumbnails data = self.render_image().getvalue() footer_meta = generate_thumbnails(data, fs=fs, image_type='footer', filename=self.get_path()) # Update the Content details. content_key = self.comment.reply_content.details_key old_raw_meta = redis.get(content_key) if old_raw_meta: meta = util.loads(old_raw_meta) else: meta = {} meta.update(footer_meta) redis.set(content_key, util.dumps(meta)) self.comment.reply_content.details.force() self.comment.details.force() return meta
def set_as_current_quest(self): redis.set('dq:current_scheduled_quest', self.id) self.appeared_on = Services.time.time() self.save() self.quest.details.force() self._publish_quest_of_the_day()
def update_freeze(): id_ = redis.get('dq:comment_freeze_id') if id_ is None: return new_id = get_latest_before_unjudged_id() redis.set('dq:comment_freeze_id', new_id) return new_id
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 enable(from_id=None): if from_id is None: from_id = get_latest_before_unjudged_id() if from_id is None: from_id = 0 redis.set('dq:comment_freeze_id', from_id) invalidate_namespace('comments')
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 update(fs, content, image_type, save_to_db=True): filename = content.details()['original']['name'] # Prevent issues with unicode filenames. filename = filename.encode('ascii') data = fs.read(filename) thumbnailer = Thumbnailer(fs) meta = util.loads(redis.get(content.details_key)) meta.update(thumbnailer.store(data, image_type)) update_metadata(content, meta) if save_to_db: content.save() redis.set(content.details_key, util.dumps(meta)) content.details.force()
def comment_freeze(request): ctx = {} if request.method == 'POST': ts = request.POST['comment_freeze_ts'] if ts: redis.set('dq:comment_freeze_ts', ts) else: redis.delete('dq:comment_freeze_ts') signals.comment_freeze_ts_changed.send(None) ctx['comment_freeze_ts'] = redis.get('dq:comment_freeze_ts') or '' return r2r_jinja('comment_freeze/comment_freeze.html', ctx, request)
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 set_headers(request, color_packs_header, colors_header): color_packs_header = color_packs_header or '' colors = colors_header or '' redis.set('color_packs_header', color_packs_header) redis.set('colors_header', colors_header)
def enable_auto_curate(): redis.set('dq:auto_curate', backend_dumps(True))