Пример #1
0
def new(request, default_template="project/new.html"):
    
    # grab the current event and check to see if it's actually open.
    eq = EventQuery()
    event = eq.current()
    
    if not event or not event.is_open() :
        messages = { 'warning' : 'There is currently no event open for submission.' }
        return redirect(reverse('victr.views.home'), locals())
    
    current_user = UserProfile.objects.get(user=request.user).pk
    
    if request.method == 'GET':
      project_form = ProjectForm(initial = {'event' : event, 'users' : [current_user] }) # the current event is preselected.
    
    elif request.method == 'POST':
        project_form = ProjectForm(request.POST, current_user=current_user)
        if project_form.is_valid() :
            try :
                proj = project_form.save()
            except :
                messages = { 'error' : 'Invalid form submission. Please contact your site administrator.' }
                return render_to_response(default_template, locals(), context_instance=RequestContext(request))
            return redirect('project', proj.slug)
        messages = { 'error': 'Invalid form submission. Please correct the indicated fields below before proceeding.' }

    else:
        return HttpResponseNotAllowed(['GET', 'POST'])
    
    forms = [project_form]
    return render_to_response(default_template, locals(), context_instance=RequestContext(request))
Пример #2
0
def present(request, slug="", default_template="impress/present.html"):
    if(slug is "") :
        eq = EventQuery()
        event = eq.current()
    else :
        event = get_object_or_404(Event, slug=slug)
    projects = Project.objects.filter(event=event)
    return render_to_response(default_template, context_instance=RequestContext(request, { 'event' : event, 'projects' : projects }))
Пример #3
0
def present(request, slug="", default_template="impress/present.html"):
    if (slug is ""):
        eq = EventQuery()
        event = eq.current()
    else:
        event = get_object_or_404(Event, slug=slug)
    projects = Project.objects.filter(event=event)
    return render_to_response(default_template,
                              context_instance=RequestContext(
                                  request, {
                                      'event': event,
                                      'projects': projects
                                  }))
Пример #4
0
def archive(request, default_template="archive.html"):
    eq = EventQuery()
    events = eq.visible()
    grouped_events = {}
    
    for event in events:
        date = event.open.date()
        year = date.year
        month = date.month
        if year not in grouped_events:
            grouped_events[year] = {}
        if month not in grouped_events[year]:
            grouped_events[year][month] = { 'month': calendar.month_name[month], 'events': [] }
        grouped_events[year][month]['events'].append(event)
        
    return render_to_response(default_template, locals(), context_instance=RequestContext(request))
Пример #5
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')
Пример #6
0
def view(request, slug="", default_template="event/view.html"):
    eq = EventQuery()
    visible_events = eq.visible()
    if(slug is "") :
        event = eq.current()
    else :
        event = get_object_or_404(Event, slug=slug)
    if not event.is_visible :
        raise Http404
    if event.show_results :
        try: 
            top_projects = Project.objects.filter(event=event, rank__isnull=False).order_by('rank')[:3]
        except IndexError :
            top_projects = False
        try:
            winner = Project.objects.filter(event=event, rank__isnull=False).order_by('rank')[0]
        except IndexError:
            winner = False
        awards = Project.objects.filter(award__isnull=False).exclude(award='')
    return render_to_response(default_template, locals(), context_instance=RequestContext(request))
Пример #7
0
def archive(request, default_template="archive.html"):
    eq = EventQuery()
    events = eq.visible()
    grouped_events = {}

    for event in events:
        date = event.open.date()
        year = date.year
        month = date.month
        if year not in grouped_events:
            grouped_events[year] = {}
        if month not in grouped_events[year]:
            grouped_events[year][month] = {
                'month': calendar.month_name[month],
                'events': []
            }
        grouped_events[year][month]['events'].append(event)

    return render_to_response(default_template,
                              locals(),
                              context_instance=RequestContext(request))