Ejemplo n.º 1
0
def mountains_view(request, mountain_abbr=None, date=None)  :
    context = {'active':'mountains'}
    if not date:
	date=datetime.strftime(datetime.now().date(),'%Y-%m-%d')
        return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)

    mountain = get_object_or_404(Mountain, abbr=mountain_abbr)
    context['mountain'] = mountain
    date = datetime.strptime(date, '%Y-%m-%d').date()
    context['date'] = date

    all_checkins = MountainCheckin.objects.filter(mountain=mountain)
    # still need to filter for the selected day
    # (Django doesn't let you use model methods in querysets, but list comprehensions do ;)
    checkins = [checkin for checkin in all_checkins if checkin.is_on_day(date) ]
    context['checkins'] = checkins

    # hidden list of active members that user can search on to enroll
    actives = Pass.objects.filter(season=get_current_season()).order_by('active_id')
    context['actives'] = actives
    inactives = Member.objects.filter(~Q(pass__season=get_current_season())).order_by('last_name')
    context['inactives'] = inactives

	# render alert if there is one
    #if alert: context['alert'] = alert

    return render(request, 'mountains/mountains_view.html', context)
Ejemplo n.º 2
0
def mountains_view(request, mountain_abbr=None, date=None):
    context = {'active': 'mountains'}
    if not date:
        date = datetime.strftime(datetime.now().date(), '%Y-%m-%d')
        return redirect('mountains_view',
                        mountain_abbr=mountain_abbr,
                        date=date)

    mountain = get_object_or_404(Mountain, abbr=mountain_abbr)
    context['mountain'] = mountain
    date = datetime.strptime(date, '%Y-%m-%d').date()
    context['date'] = date

    all_checkins = MountainCheckin.objects.filter(mountain=mountain)
    # still need to filter for the selected day
    # (Django doesn't let you use model methods in querysets, but list comprehensions do ;)
    checkins = [checkin for checkin in all_checkins if checkin.is_on_day(date)]
    context['checkins'] = checkins

    # hidden list of active members that user can search on to enroll
    actives = Pass.objects.filter(
        season=get_current_season()).order_by('active_id')
    context['actives'] = actives
    inactives = Member.objects.filter(~Q(
        pass__season=get_current_season())).order_by('last_name')
    context['inactives'] = inactives

    # render alert if there is one
    #if alert: context['alert'] = alert

    return render(request, 'mountains/mountains_view.html', context)
Ejemplo n.º 3
0
def busing_home(request, date=datetime.strftime(date.today(), '%Y-%m-%d')):
    context= {'active':'busing'}
    actives = Pass.objects.filter(season=get_current_season()).order_by('active_id')
    context['actives'] = actives
    inactives = Member.objects.filter(~Q(pass__season=get_current_season())).order_by('last_name')
    context['inactives'] = inactives
    date = datetime.strptime(date, '%Y-%m-%d').date()  # format input date as date object
    context['date'] = date
    context['today_list'] = Bus.objects.filter( ~Q(number=WAIT_LIST_NUM), date=date) #exclude wait list
    context['bus_list'] = Bus.objects.filter(~Q(number=WAIT_LIST_NUM))
    context['days_list'] = { bus.date for bus in context['bus_list'] } # set of unique dates
    print context['days_list'] 
    #get waiting list bus or create it
    try:
      wait = Bus.objects.get(number=WAIT_LIST_NUM, date=date)
    except ObjectDoesNotExist:
      wait = Bus(number=WAIT_LIST_NUM, capacity=WAIT_LIST_CAP, date=date)
      wait.save()
    context['waiting_list'] = wait
    #print 'Wat:',wait 
   
    # check to see if a bus reservation has been posted
    if request.method == 'POST':
        form = BusCheckinForm(request.POST)
        if form.is_valid():
            #print form.cleaned_data
            member_pass = get_object_or_404(Pass, active_id=form.cleaned_data['pass_num'], season=get_current_season())
            bus = form.cleaned_data['bus']
            # don't want to overcrowd buses
               
            if bus.is_open():
              # if they are on the waiting list, switch them to this bus
              wait_list = [bc.member for bc in wait.res_list()]
              if member_pass in wait_list:
                checkin = BusCheckin.objects.get(bus=wait, member=member_pass)
                checkin.pickup=form.cleaned_data['pickup']
                checkin.save()
                return redirect('buscheckin_switch', res_id=checkin.id, bus_id=bus.id)

              # check to see if they are on any bus already
              res_list = []
              for other_bus in context['today_list']:
                m_list = [ bc.member for bc in other_bus.res_list()]
                for mem in m_list:res_list.append(mem)   
              print 'reservation list:', res_list
              if member_pass not in res_list:
                pickup = form.cleaned_data['pickup']
                checkin = BusCheckin(member=member_pass, bus=bus, pickup=pickup)
                #print 'Checkin:', checkin
                checkin.save()
            
            
    else:
        context['checkin_form'] = BusCheckinForm()
 
    return render(request, "busing/busing_home.html", context)
Ejemplo n.º 4
0
def trips_view(request, trip_id=None):
  context = {'active':'trips'}
  trip = get_object_or_404(Trip, pk=int(trip_id))
  context['trip'] = trip

  #get current members
  actives = Pass.objects.filter(season=get_current_season()).order_by('active_id')
  context['actives'] = actives
  inactives = Member.objects.filter(~Q(pass__season=get_current_season())).order_by('last_name')
  context['inactives'] = inactives

  return render(request, 'trips/trips_view.html', context)
Ejemplo n.º 5
0
def mountains_checkin_add(request,
                          mountain_abbr=None,
                          date=None,
                          active_id=None):
    context = {'active': 'mountains'}
    mountain = get_object_or_404(Mountain, abbr=mountain_abbr)
    # make sure mountain is open
    """
    if not mountain.is_open():
        return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)
    """
    member_pass = get_object_or_404(Pass,
                                    active_id=int(active_id),
                                    season=get_current_season())

    checkin = MountainCheckin(member_pass=member_pass, mountain=mountain)
    checkin.save()
    # make sure checkin isn't duplicate
    checkins = mountain.todays_checkins()
    passes = [checkin.member_pass for checkin in checkins]
    if member_pass in passes:
        return redirect('mountains_view',
                        mountain_abbr=mountain_abbr,
                        date=date)

    return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)
Ejemplo n.º 6
0
def export_member_emails(request):
    # set up csv file response
    response = HttpResponse(content_type='text/csv')
    date_str = date.today().isoformat()
    response[
        'Content-Disposition'] = 'attachment; filename="member_info_' + date_str + '.csv"'

    # get active members
    actives = Pass.objects.filter(
        season=get_current_season()).order_by('active_id')
    # write out csv
    writer = csv.writer(response)
    writer.writerow(
        ["First Name", "Last Name", "Active ID", "Membership Type", "Email"])
    for m_pass in actives:
        member = m_pass.member
        first_name = member.first_name
        last_name = member.last_name
        pass_num = m_pass.active_id
        m_type = m_pass.member_type
        date_signup = m_pass.created
        price_paid = m_pass.price_paid
        email = m_pass.member.email
        writer.writerow([
            first_name, last_name, pass_num, m_type, date_signup, price_paid,
            email
        ])

    return response
Ejemplo n.º 7
0
def trips_add(request):
  context = {'active':'trips'}
  if request.method == 'POST':
    trip_form = TripForm(request.POST)
    if trip_form.is_valid():
      season = get_current_season()
      trip = Trip(season=season, **trip_form.cleaned_data)
      trip.save()
      return redirect('trips_view', trip_id = trip.id)
    else:
        context['add_trip_form'] = trip_form
  else:
    context['add_trip_form'] = TripForm()

  return render(request, 'trips/trips_add.html', context)
Ejemplo n.º 8
0
 def current_pass_list(self):
     from members.views import get_current_season  # import this way to avoid cyclical imports
     #print get_current_season()
     #get current passes (deals with lost stolen)
     passes = self.pass_set.filter(season=get_current_season())
     #if no current passes get all passes
     if not passes:
         passes = self.pass_set.all()
         #if that worked, get just the most recent inactive pass
         if passes:
             #print passes
             passes = [passes[0]]
         #else they are a trip-only member and have no pass whatsoever
         else:
             pseudo_pass = Pass(member_type='TRIP')
             #print 'Fake Pass', pseudo_pass
             passes = [pseudo_pass]
     return passes
Ejemplo n.º 9
0
 def current_pass_list(self):
     from members.views import get_current_season # import this way to avoid cyclical imports
     #print get_current_season()
     #get current passes (deals with lost stolen)
     passes = self.pass_set.filter(season=get_current_season())
     #if no current passes get all passes
     if not passes:
       passes = self.pass_set.all()
       #if that worked, get just the most recent inactive pass
       if passes:
         #print passes
         passes = [passes[0]]
       #else they are a trip-only member and have no pass whatsoever
       else: 
         pseudo_pass = Pass(member_type='TRIP')
         #print 'Fake Pass', pseudo_pass
         passes = [pseudo_pass]
     return passes
Ejemplo n.º 10
0
def mountains_checkin_add(request, mountain_abbr=None, date=None, active_id=None):
    context = {'active':'mountains'}
    mountain = get_object_or_404(Mountain, abbr=mountain_abbr)
    # make sure mountain is open
    """
    if not mountain.is_open():
        return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)
    """
    member_pass = get_object_or_404(Pass, active_id=int(active_id), season=get_current_season())

    checkin = MountainCheckin(member_pass=member_pass, mountain=mountain)
    checkin.save()
    # make sure checkin isn't duplicate
    checkins = mountain.todays_checkins()
    passes = [checkin.member_pass for checkin in checkins]
    if member_pass in passes:
        return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)
    
    return redirect('mountains_view', mountain_abbr=mountain_abbr, date=date)