コード例 #1
0
ファイル: views.py プロジェクト: McPolemic/Vremya
def add_event(request, year, month, day):
    (y, m, d) = (int(year), int(month), int(day))
    date_target = date(y,m,d)
    act_id = request.POST['activity']
    act = get_object_or_404(Activity, pk=act_id)
    minutes = 0
    hours = 0

    if request.POST['minutes']:
        minutes = int(request.POST['minutes'])
    
    if request.POST['hours']:
        hours = int(request.POST['hours'])

    if 'event_id' in request.POST.keys():
        #We're modifying an existing event
        event_id = int(request.POST['event_id'])
        e = Event.objects.get(id=event_id)
        e.activity = act
        e.total_minutes = minutes + (hours * 60)
        e.save()
    else:
        #We're creating a new event
        e = Event(user = request.user.username,
                  date = date_target, 
                  activity = act, 
                  total_minutes = minutes + (hours * 60))
        e.save()

    return HttpResponseRedirect(reverse('vremya.views.daily', args=(y,m,d)))
コード例 #2
0
ファイル: views.py プロジェクト: McPolemic/Vremya
def delete_event(request):
    if request.POST['event_id']:
        event_id = int(request.POST['event_id'])

        print 'Deleting event %s' % event_id

        e = Event.objects.get(id=event_id)
        
        #Generate new total time data again
        event_date = e.date
        e.delete()

        event_list = Event.objects.filter(date = event_date).filter(user = request.user.username)

        #Temp object to return total time.  Do not save.
        total = Event(total_minutes = sum([e.total_minutes for e in event_list]))
        remaining = 8 - total.frac_hours()

        response = {'response': 'ok',
                    'total_frac': total.frac_hours(),
                    'total_eng': total.english_time(),
                    'remaining': remaining}

        return HttpResponse(json.dumps(response))
    else:
        return HttpResponse(json.dumps({'response': 'error'}))
コード例 #3
0
ファイル: views.py プロジェクト: McPolemic/Vremya
def daily(request, year, month, day):
    (y, m, d) = (int(year), int(month), int(day))
    date_target = date(y,m,d)
    event_list = Event.objects.filter(date = date_target).filter(user = request.user.username)

    #Temp object to return total time.  Do not save.
    total = Event(total_minutes = sum([e.total_minutes for e in event_list]))
    remaining = 8 - total.frac_hours()
    
    date_url = '/'.join((year, month, day))

    activity_list = Activity.objects.filter(user = request.user.username)

    #Create previous and next day links
    one_day = timedelta(1)

    prev_date = date_target-one_day
    next_date = date_target+one_day

    (py, pm, pd) = (str(prev_date.year), str(prev_date.month), str(prev_date.day))
    day_prev = reverse('vremya.views.daily', args=(py,pm,pd))
    (ny, nm, nd) = (str(next_date.year), str(next_date.month), str(next_date.day))
    day_next = reverse('vremya.views.daily', args=(ny,nm,nd))

    return render_to_response('vremya/daily.html',
                              {'event_list': event_list,
                               'activity_list': activity_list,
			                         'remaining': remaining,
                               'total': total,
                               'user': request.user,
                               'day_prev': day_prev,
                               'day_next': day_next,
                               'day_curr': date_target,
                               'date_url': date_url,
                               'development': settings.DEVELOPMENT},
                              context_instance=RequestContext(request))