<s> from __future__ import unicode_literals <EOL> import os <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . db import models <EOL> from django . utils import timezone <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from django . utils . html import escape <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from djblets . util . templatetags . djblets_images import thumbnail <EOL> from reviewboard . site . urlresolvers import local_site_reverse <EOL> @ python_2_unicode_compatible <EOL> class Screenshot ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> caption = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> draft_caption = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , blank = True ) <EOL> image = models . ImageField ( _ ( "<STR_LIT:image>" ) , <EOL> upload_to = os . path . join ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ property <EOL> def filename ( self ) : <EOL> """<STR_LIT>""" <EOL> return os . path . basename ( self . image . name ) <EOL> def get_comments ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _comments = list ( self . comments . all ( ) ) <EOL> return self . _comments <EOL> def get_thumbnail_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return thumbnail ( self . image ) <EOL> def thumb ( self ) : <EOL> """<STR_LIT>""" <EOL> url = self . get_thumbnail_url ( ) <EOL> return mark_safe ( '<STR_LIT>' % <EOL> ( url , thumbnail ( self . image , '<STR_LIT>' ) , <EOL> escape ( self . caption ) ) ) <EOL> thumb . allow_tags = True <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . caption , self . image ) <EOL> def get_review_request ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . _review_request <EOL> try : <EOL> return self . review_request . all ( ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> try : <EOL> return self . inactive_review_request . all ( ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> try : <EOL> draft = self . drafts . get ( ) <EOL> except ObjectDoesNotExist : <EOL> draft = self . inactive_drafts . get ( ) <EOL> return draft . review_request <EOL> def get_absolute_url ( self ) : <EOL> review_request = self . get_review_request ( ) <EOL> if review_request . local_site : <EOL> local_site_name = review_request . local_site . name <EOL> else : <EOL> local_site_name = None <EOL> return local_site_reverse ( <EOL> '<STR_LIT>' , <EOL> local_site_name = local_site_name , <EOL> kwargs = { <EOL> '<STR_LIT>' : review_request . display_id , <EOL> '<STR_LIT>' : self . pk , <EOL> } ) <EOL> def save ( self , ** kwargs ) : <EOL> super ( Screenshot , self ) . save ( ) <EOL> try : <EOL> draft = self . drafts . get ( ) <EOL> draft . timestamp = timezone . now ( ) <EOL> draft . save ( ) <EOL> except ObjectDoesNotExist : <EOL> pass <EOL> class Meta : <EOL> app_label = '<STR_LIT>' </s>
