<s> import os <EOL> import random <EOL> from datetime import datetime <EOL> from django . core . exceptions import ValidationError <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils import timezone <EOL> from opps . core . models import Publishable , Slugged <EOL> from opps . core . tags . models import Tagged <EOL> def get_file_path ( instance , filename ) : <EOL> ext = filename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> filename = u"<STR_LIT>" . format ( random . getrandbits ( <NUM_LIT:32> ) , <EOL> instance . slug [ : <NUM_LIT:100> ] , ext ) <EOL> d = datetime . now ( ) <EOL> folder = u"<STR_LIT>" . format ( d . strftime ( "<STR_LIT>" ) ) <EOL> return os . path . join ( folder , filename ) <EOL> class Archive ( Publishable , Slugged ) : <EOL> title = models . CharField ( _ ( u"<STR_LIT>" ) , max_length = <NUM_LIT> , db_index = True ) <EOL> archive = models . FileField ( upload_to = get_file_path , <EOL> max_length = <NUM_LIT:255> , <EOL> verbose_name = _ ( u'<STR_LIT>' ) , <EOL> null = True , <EOL> blank = True ) <EOL> archive_link = models . URLField ( _ ( u"<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:255> , <EOL> null = True , <EOL> blank = True ) <EOL> description = models . TextField ( _ ( u"<STR_LIT>" ) , null = True , blank = True ) <EOL> source = models . CharField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> null = True , blank = True , <EOL> max_length = <NUM_LIT:255> <EOL> ) <EOL> def clean ( self ) : <EOL> items = [ self . archive , self . archive_link ] <EOL> if not any ( items ) : <EOL> raise ValidationError ( _ ( u"<STR_LIT>" ) ) <EOL> if all ( items ) : <EOL> raise ValidationError ( _ ( u"<STR_LIT>" ) ) <EOL> class Meta : <EOL> verbose_name = _ ( u'<STR_LIT>' ) <EOL> verbose_name_plural = _ ( u'<STR_LIT>' ) <EOL> unique_together = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> abstract = True <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" . format ( self . site , self . slug ) <EOL> def get_absolute_url ( self ) : <EOL> if self . date_available <= timezone . now ( ) and self . published : <EOL> return self . archive_link or self . archive . url <EOL> return u"<STR_LIT>" <EOL> class File ( Archive , Tagged ) : <EOL> class Meta : <EOL> verbose_name = _ ( u'<STR_LIT>' ) <EOL> verbose_name_plural = _ ( u'<STR_LIT>' ) </s>
