@login_required
def period_form(request, period_id=None):
    # e.g. /period_form/?timestamp=2015-08-19T08:31:24-07:00
    user_timezone = pytz.timezone(request.user.timezone.zone)
    try:
        flow_event = period_models.FlowEvent.objects.get(pk=int(period_id))
        flow_event.timestamp = flow_event.timestamp.astimezone(user_timezone)
    except (TypeError, period_models.FlowEvent.DoesNotExist):
        timestamp = request.GET.get('timestamp')
        try:
            timestamp = dateutil_parser.parse(timestamp)
        except AttributeError:
            timestamp = period_models.today().astimezone(user_timezone)
        flow_event = period_models.FlowEvent(timestamp=timestamp)
        if timestamp:
            yesterday = datetime.timedelta(days=1) - timestamp
            yesterday_start = yesterday.replace(hour=0, minute=0, second=0)
            yesterday_events = period_models.FlowEvent.objects.filter(
                timestamp__gte=yesterday_start, timestamp__lte=timestamp)
            if not yesterday_events.count():
                flow_event.first_day = True
    flow_event.timestamp = flow_event.timestamp.replace(tzinfo=pytz.utc)
    form = period_forms.PeriodForm(instance=flow_event)
    data = {
        'form': form,
    }
    return render_to_response('periods/period_form.html', data,
                              context_instance=RequestContext(request))
dataset/ETHPy150Open jessamynsmith/eggtimer-server/periods/views.py/period_form/swapped operands of `-`