<s> from os . path import split as path_split <EOL> from collections import Iterable <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from mezzanine . core . models import ( Displayable , Ownable , Orderable , RichText , <EOL> CONTENT_STATUS_DRAFT , CONTENT_STATUS_PUBLISHED ) <EOL> from mezzanine . core . fields import RichTextField <EOL> from mezzanine . utils . models import AdminThumbMixin <EOL> from mezzanine . utils . timezone import now <EOL> from mezzanine . blog . models import BlogCategory <EOL> from mezzanine . core . templatetags . mezzanine_tags import thumbnail <EOL> from raspberryio . project . utils import get_youtube_video_id <EOL> class Project ( Displayable , Ownable , AdminThumbMixin ) : <EOL> """<STR_LIT>""" <EOL> featured_photo = models . ImageField ( '<STR_LIT>' , <EOL> upload_to = '<STR_LIT>' , blank = True , null = True , <EOL> help_text = '<STR_LIT>' '<STR_LIT>' <EOL> ) <EOL> featured_video = models . URLField ( blank = True , default = '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' ) <EOL> featured_video_thumbnail = models . ImageField ( <EOL> upload_to = '<STR_LIT>' , <EOL> blank = True , null = True , editable = False <EOL> ) <EOL> tldr = RichTextField ( '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' <EOL> ) <EOL> categories = models . ManyToManyField ( BlogCategory , related_name = '<STR_LIT>' ) <EOL> score = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> created_datetime = models . DateTimeField ( '<STR_LIT>' ) <EOL> modified_datetime = models . DateTimeField ( '<STR_LIT>' ) <EOL> admin_thumb_field = '<STR_LIT>' <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . id : <EOL> self . status = CONTENT_STATUS_DRAFT <EOL> if not self . id : <EOL> self . created_datetime = now ( ) <EOL> self . modified_datetime = now ( ) <EOL> super ( Project , self ) . save ( * args , ** kwargs ) <EOL> def is_published ( self , request = None ) : <EOL> """<STR_LIT>""" <EOL> if request is not None : <EOL> if request . user . is_staff or request . user == self . user : <EOL> return True <EOL> return ( self . publish_date <= now ( ) and <EOL> self . status == CONTENT_STATUS_PUBLISHED ) <EOL> @ property <EOL> def video_id ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . featured_video : <EOL> return get_youtube_video_id ( self . featured_video ) <EOL> @ property <EOL> def embed_url ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . video_id : <EOL> return '<STR_LIT>' % self . video_id <EOL> return None <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , [ self . slug ] ) <EOL> def __unicode__ ( self ) : <EOL> return unicode ( self . title ) <EOL> class ProjectStep ( Orderable , RichText ) : <EOL> """<STR_LIT>""" <EOL> project = models . ForeignKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> title = models . CharField ( max_length = <NUM_LIT> ) <EOL> gallery = models . ManyToManyField ( '<STR_LIT>' , blank = True , null = True ) <EOL> video = models . URLField ( blank = True , default = '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' ) <EOL> search_classname = '<STR_LIT>' <EOL> class Meta ( object ) : <EOL> order_with_respect_to = '<STR_LIT>' <EOL> def is_editable ( self , request ) : <EOL> """<STR_LIT>""" <EOL> user = request . user <EOL> return user . is_superuser or user . id == self . project . user_id <EOL> @ property <EOL> def get_steps_count ( self ) : <EOL> return self . project . steps . count ( ) <EOL> @ property <EOL> def get_order_display ( self ) : <EOL> return self . _order + <NUM_LIT:1> <EOL> @ property <EOL> def order ( self ) : <EOL> return self . _order <EOL> @ models . permalink <EOL> def get_absolute_url ( self ) : <EOL> return ( '<STR_LIT>' , [ self . project . slug ] ) <EOL> @ property <EOL> def video_id ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . video : <EOL> return get_youtube_video_id ( self . video ) <EOL> @ property <EOL> def embed_url ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . video_id : <EOL> return '<STR_LIT>' % self . video_id <EOL> return None <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' . format ( <EOL> self . _order , self . project . title <EOL> ) <EOL> class ProjectCategory ( BlogCategory ) : <EOL> class Meta ( object ) : <EOL> proxy = True <EOL> class ProjectImage ( models . Model ) : <EOL> file = models . ImageField ( <EOL> upload_to = '<STR_LIT>' , editable = False <EOL> ) <EOL> def get_filename ( self ) : <EOL> """<STR_LIT>""" <EOL> return path_split ( self . file . name ) [ - <NUM_LIT:1> ] if self . file . name else '<STR_LIT>' <EOL> def get_delete_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return reverse ( '<STR_LIT>' , args = ( self . id , ) ) <EOL> def get_absolute_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return settings . MEDIA_URL + self . file . name . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> def get_thumbnail_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return settings . MEDIA_URL + thumbnail ( <EOL> self . get_absolute_url ( ) , <NUM_LIT> , <NUM_LIT:200> <EOL> ) <EOL> def get_image_data ( self ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT:id>' : self . id , <EOL> '<STR_LIT:name>' : self . get_filename ( ) , <EOL> '<STR_LIT:size>' : self . file . size , <EOL> '<STR_LIT:url>' : self . get_absolute_url ( ) , <EOL> '<STR_LIT>' : self . get_thumbnail_url ( ) , <EOL> '<STR_LIT>' : self . get_delete_url ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> @ classmethod <EOL> def serialize ( kls , images ) : <EOL> """<STR_LIT>""" <EOL> files_data = [ image . get_image_data ( ) for image in images ] if isinstance ( images , Iterable ) else [ images . get_image_data ( ) ] <EOL> return { '<STR_LIT>' : files_data } <EOL> class FeaturedProject ( models . Model ) : <EOL> "<STR_LIT>" <EOL> project = models . OneToOneField ( "<STR_LIT>" ) <EOL> byline = models . CharField ( max_length = <NUM_LIT:50> , <EOL> help_text = '<STR_LIT>' <EOL> ) <EOL> photo = models . ImageField ( upload_to = '<STR_LIT>' , <EOL> help_text = '<STR_LIT>' '<STR_LIT>' ) <EOL> featured_start_date = models . DateTimeField ( default = now ( ) , <EOL> help_text = '<STR_LIT>' '<STR_LIT>' ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] </s>
