<s> from django . db import models <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> import os <EOL> import datetime <EOL> from datetime import datetime as dt <EOL> DATA_STATUS = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> class Contest ( models . Model ) : <EOL> title = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> start_date = models . DateTimeField ( ) <EOL> end_date = models . DateTimeField ( ) <EOL> vote_frequency = models . IntegerField ( ) <EOL> rules = models . TextField ( ) <EOL> def get_days_left ( self ) : <EOL> today = dt . today ( ) <EOL> left = self . end_date - today <EOL> if left . days < <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> return left . days <EOL> def get_days_till_start ( self ) : <EOL> till = self . start_date - dt . today ( ) <EOL> return till . days + <NUM_LIT:1> <EOL> def has_ended ( self ) : <EOL> return dt . today ( ) >= self . end_date <EOL> def has_started ( self ) : <EOL> return dt . today ( ) >= self . start_date <EOL> def get_next_vote_date ( self , user ) : <EOL> votes = user . vote_set . order_by ( '<STR_LIT>' ) <EOL> increment = datetime . timedelta ( days = self . vote_frequency ) <EOL> if len ( votes ) : <EOL> last_vote_date = votes [ <NUM_LIT:0> ] . timestamp <EOL> else : <EOL> last_vote_date = dt . today ( ) <EOL> next_vote_date = last_vote_date + increment <EOL> return next_vote_date <EOL> def user_can_vote ( self , user ) : <EOL> votes = user . vote_set . order_by ( '<STR_LIT>' ) <EOL> if votes . count ( ) > <NUM_LIT:0> : <EOL> next_date = self . get_next_vote_date ( user ) <EOL> if dt . today ( ) < next_date and dt . today ( ) < self . end_date : <EOL> return False <EOL> return True <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> class Entry ( models . Model ) : <EOL> def get_image_path ( instance , filename ) : <EOL> fsplit = filename . split ( '<STR_LIT:.>' ) <EOL> extra = <NUM_LIT:1> <EOL> test_path = os . path . join ( settings . MEDIA_ROOT , '<STR_LIT>' , str ( instance . id ) , fsplit [ <NUM_LIT:0> ] + '<STR_LIT:_>' + str ( extra ) + '<STR_LIT:.>' + fsplit [ <NUM_LIT:1> ] ) <EOL> while os . path . exists ( test_path ) : <EOL> extra += <NUM_LIT:1> <EOL> test_path = os . path . join ( settings . MEDIA_ROOT , '<STR_LIT>' , str ( instance . id ) , fsplit [ <NUM_LIT:0> ] + '<STR_LIT:_>' + str ( extra ) + '<STR_LIT:.>' + fsplit [ <NUM_LIT:1> ] ) <EOL> path = os . path . join ( '<STR_LIT>' , str ( instance . id ) , fsplit [ <NUM_LIT:0> ] + '<STR_LIT:_>' + str ( extra ) + '<STR_LIT:.>' + fsplit [ <NUM_LIT:1> ] ) <EOL> return path <EOL> title = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> description = models . TextField ( ) <EOL> short_description = models . CharField ( max_length = <NUM_LIT> ) <EOL> nominator = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> nominator_link = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> nominator_image = models . ImageField ( upload_to = get_image_path , null = True , blank = True , help_text = "<STR_LIT>" ) <EOL> status = models . CharField ( max_length = <NUM_LIT:255> , choices = DATA_STATUS , default = "<STR_LIT>" ) <EOL> links = models . CharField ( max_length = <NUM_LIT> , null = True , blank = True ) <EOL> is_visible = models . BooleanField ( default = True ) <EOL> data_owner = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> rejected_reason = models . CharField ( max_length = <NUM_LIT:255> , null = True , blank = True ) <EOL> comments = models . TextField ( null = True , blank = True ) <EOL> contest = models . ForeignKey ( Contest ) <EOL> vote_count = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> def get_place ( self ) : <EOL> entries = Entry . objects . filter ( contest = self . contest ) . order_by ( '<STR_LIT>' ) <EOL> for i , entry in enumerate ( entries ) : <EOL> if entry == self : return i + <NUM_LIT:1> <EOL> class Vote ( models . Model ) : <EOL> user = models . ForeignKey ( User ) <EOL> timestamp = models . DateTimeField ( auto_now = True ) <EOL> entry = models . ForeignKey ( Entry ) <EOL> from django import forms <EOL> class EntryForm ( forms . Form ) : <EOL> org_name = forms . CharField ( max_length = <NUM_LIT:255> , label = "<STR_LIT>" ) <EOL> org_url = forms . CharField ( max_length = <NUM_LIT:255> , label = "<STR_LIT>" ) <EOL> contact_person = forms . CharField ( max_length = <NUM_LIT> , label = "<STR_LIT>" ) <EOL> contact_phone = forms . CharField ( max_length = <NUM_LIT:15> , label = "<STR_LIT>" ) <EOL> contact_email = forms . EmailField ( max_length = <NUM_LIT> , label = "<STR_LIT>" ) <EOL> data_set = forms . CharField ( max_length = <NUM_LIT:255> , label = "<STR_LIT>" ) <EOL> data_use = forms . CharField ( max_length = <NUM_LIT:1000> , widget = forms . Textarea , label = "<STR_LIT>" ) <EOL> data_mission = forms . CharField ( max_length = <NUM_LIT:1000> , widget = forms . Textarea , label = "<STR_LIT>" ) </s>
