def submit_announcement(request, template="listings/announcements/submit.html"): if request.method == 'POST': form = SubmitAnnouncementForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse(announcement_success)) else: form = SubmitAnnouncementForm() return render_to_response(template, context_instance=RequestContext( request, { 'form': form, 'poster': Poster.published.get_running(), }))
def around_swarthmore(request, template="listings/around/index.html"): today = datetime.date.today() year = today.year month = today.month day = today.day date = datetime.date(int(year), int(month), int(day)) current = Announcement.community.filter(date_start__lte=date, date_end__gte=date) regular = current.filter(is_lost_and_found=False, event_date=None) events = current.exclude(event_date=None) lost_and_found = current.filter(is_lost_and_found=True) one_week = datetime.timedelta(days=7) if date == datetime.date.today(): jobs = JobListing.unfilled.get_for_show(num=5, cutoff=one_week) else: jobs = JobListing.published.get_for_show(num=5, base_date=date, cutoff=one_week) if not current.count() and not jobs.count(): raise Http404 tomorrow = date + datetime.timedelta(days=1) comments = PublicComment.visible.filter( time__lt=tomorrow).order_by('-time') t, m, l = Article.published.get_stories(num_top=0, num_mid=4, num_low=0) if request.method == 'POST': announcement_form = SubmitAnnouncementForm() job_form = SubmitJobForm() if announcement_form.is_valid(): announcement_form.save_m2m() return HttpResponseRedirect(reverse(around_swarthmore)) if job_form.is_valid(): job_form.save_m2m() return HttpResponseRedirect(reverse(around_swarthmore)) else: announcement_form = SubmitAnnouncementForm() job_form = SubmitJobForm() if datetime.datetime.now().hour < 21: menu = Menu.objects.for_today() else: menu = Menu.objects.for_tomorrow() data = { 'year': year, 'month': month, 'day': day, 'date': date, 'announcements': regular.order_by('-date_start', 'pk'), 'events': events.order_by('event_date', 'event_time', 'pk'), 'lost_and_found': lost_and_found.order_by('-date_start', 'pk'), 'jobs': jobs, 'comments': comments[:10], 'stories': m, 'announcement_form': announcement_form, 'job_form': job_form, 'menu': menu, 'bico_news': get_bico_news(), 'poster': Poster.published.get_running(), } rc = RequestContext(request) return render_to_response(template, data, context_instance=rc)