Beispiel #1
0
class Project(models.Model):
    slug = models.SlugField()
    title = models.CharField(max_length=50,
                             verbose_name=string.capwords(
                                 config.keyword('Project.title')))
    description = models.TextField(blank=True,
                                   verbose_name=string.capwords(
                                       config.keyword('Project.description')))
    url = models.URLField(blank=True,
                          verbose_name=string.capwords(
                              config.keyword('Project.url')))
    event = models.ForeignKey(Event,
                              verbose_name=string.capwords(
                                  config.keyword('Event')))
    users = models.ManyToManyField(UserProfile)
    disciplines = models.ManyToManyField(Discipline, blank=True)
    rank = models.IntegerField(
        blank=True,
        null=True,
        help_text="What place the project came in in the contest.",
    )
    award = models.CharField(
        max_length=50,
        blank=True,
        help_text="e.g. \"Best UX\" or \"Honorable Mention\"",
    )

    # other_urls
    # tags = models.ManyToManyField(Discipline, blank=True)
    # collaborators = models.ManyToManyField(User, blank=True)
    # screenshot = models.ImageField(upload_to="images/screenshot")

    def __unicode__(self):
        return self.title

    def save(self):
        if not self.id:
            self.slug = SlugifyUniquely(self.title, self.__class__)
        super(self.__class__, self).save()

    def award_text(self):
        """ generate award text for display on various pages """
        if self.award and (self.rank is None or self.rank >= 4):
            a = self.award
        elif self.rank and self.rank < 4:
            ranks = ['First Place', 'Second Place', 'Third Place']
            if self.award:
                a = "%s - %s" % (ranks[self.rank - 1], self.award)
            else:
                a = ranks[self.rank - 1]
        return a

    def rank_class(self):
        """ pass a class for use in styling project/details.html """
        classes = [' first', ' second', ' third']
        if self.rank and self.rank > 0 and self.rank < 4:
            return classes[self.rank - 1]
        return ''
Beispiel #2
0
 def clean_users(self):
     """ makes sure currently logged in user is part of this list """
     data = self.cleaned_data["users"]
     if str(self.current_user) not in data:
         self._errors["users"] = self.error_class(
             ["Make sure to include yourself in the %s list!" % config.keyword("Users")]
         )
     return data
Beispiel #3
0
class ProjectForm(ModelForm):
    #event choices
    eq = EventQuery()
    event = eq.current()
    events = [(event.pk, event)]

    #user choices
    users = map(lambda userprofile: (userprofile.pk, userprofile), UserProfile.objects.filter())
    
    disciplines = map((lambda discipline:
                       (discipline.pk, discipline)),
                Discipline.objects.filter())
    
    title       = forms.fields.CharField(
                    label = string.capwords(config.keyword('Project.title')),
                    max_length = 100, 
                    widget = forms.TextInput(attrs={ 'placeholder': 'be creative..'}), )
    description = forms.fields.CharField(
                    label = string.capwords(config.keyword('Project.description')),
                    widget = forms.Textarea(attrs={ 'placeholder': 'details..'}), )
    url         = forms.fields.URLField(
                    label = string.capwords(config.keyword('Project.url')),
                    widget = forms.TextInput(attrs={ 'placeholder': 'http://hacks4you.com'}), )
    event       = forms.fields.ChoiceField(
                    label = string.capwords(config.keyword('Event')),
                    choices = events,
                    widget = SelectWithDisabled(), )
    users       = forms.fields.MultipleChoiceField(
                    label = string.capwords(config.keyword('Users')),
                    choices = users,
                    widget = forms.SelectMultiple(attrs={ 'data-placeholder': 'search for %s by name or email' % (config.keyword('Users'),) }), )
    disciplines = Tagger(
                    type = Discipline,
                    label = string.capwords(config.keyword('Disciplines')),
                    choices = disciplines,
                    widget = forms.SelectMultiple(attrs={ 'class': 'tagger',
                                                          'data-placeholder': 'search for %s' % (config.keyword('Disciplines'),) }), )
    
    def __init__(self, *args, **kwargs):
        # load current user
        self.current_user = kwargs.pop('current_user', None)
        super(ProjectForm, self).__init__(*args, **kwargs)
        
    def clean_event(self):
        """ turns int into Event entity for ze processing """
        return Event.objects.get(pk=int(self.cleaned_data['event']))
        
    def clean_users(self):
        """ makes sure currently logged in user is part of this list """
        data = self.cleaned_data['users']
        if str(self.current_user) not in data:
            self._errors["users"] = self.error_class(["Make sure to include yourself in the %s list!" % config.keyword('Users')])
        return data
    
    class Meta:
        model = Project
        title = "%s Information" % string.capwords(config.keyword('Project'))
        description = "Basic info about your %s, such as title, description, and the involved %s." % (config.keyword('Project'), config.keyword('Users'))
        exclude = ('slug', 'rank', 'award')
Beispiel #4
0
class Event(models.Model):
    slug = models.SlugField()
    name = models.CharField(max_length=50)
    description = models.TextField(blank=True)
    show_results = models.BooleanField()
    rsvp = models.URLField(
        blank=True,
        verbose_name=string.capwords(config.keyword('Event.RSVP')),
        help_text="A URL to the event RSVP (Eventbrite, etc.)",
    )
    scheduled = models.DateTimeField(
        blank=True,
        null=True,
        help_text="When your contest will appear publicly as a simple page \
						  with an RSVP link. Leaving this blank means that your event \
						  will appear as soon as it is saved.",
    )
    open = models.DateTimeField(
        help_text="When your participants can start submitting their projects.",
    )
    close = models.DateTimeField(help_text="When submissions will close.", )
    hidden = models.DateTimeField(
        blank=True,
        null=True,
        help_text="When the event, results, and hacks will go into hidden mode. \
						  Leaving this off will leave all portions of this event accessible on \
						  the \"Events\" section of the site.",
    )

    def __unicode__(self):
        return self.name

    def is_open(self):
        """ checks if current event is in the open scope """
        return self.open < now() and self.close > now()

    def is_visible(self):
        """ checks if current event is in the visible scope """
        return (self.scheduled is None
                or self.scheduled <= now()) and (self.hidden is None
                                                 or self.hidden >= now())

    def save(self):
        if not self.id:
            self.slug = SlugifyUniquely(self.name, self.__class__)
        super(self.__class__, self).save()
Beispiel #5
0
def victr_brand():
    return '<img src="'+config.brand()+'" />'
Beispiel #6
0
def victr_stylesheet():
    return ''.join([ '<link href="'+url+'" rel="stylesheet">\n' for url in config.stylesheet()])
Beispiel #7
0
def victr_keyword(key):
    """ returns language set in config.py """
    return config.keyword(key)
Beispiel #8
0
 class Meta:
     model = Project
     title = "%s Information" % string.capwords(config.keyword('Project'))
     description = "Basic info about your %s, such as title, description, and the involved %s." % (config.keyword('Project'), config.keyword('Users'))
     exclude = ('slug', 'rank', 'award')
Beispiel #9
0
 def clean_users(self):
     """ makes sure currently logged in user is part of this list """
     data = self.cleaned_data['users']
     if str(self.current_user) not in data:
         self._errors["users"] = self.error_class(["Make sure to include yourself in the %s list!" % config.keyword('Users')])
     return data