예제 #1
0
def new_log(request, fountain_name):
    """Checks form data and attempts to create new log."""
    fountain = Fountain.objects.get(url_name__iexact=fountain_name)
    form = NewLogForm(request.POST)
    if not form.is_valid():
        print 'Invalid form data'
        messages.error(request, 'Form data was not valid.')
    else:
        print 'Valid form data'
        last = Log.objects.filter(fountain=fountain).order_by('bottles').last()
        log = Log(fountain=fountain,
                  bottles=form.cleaned_data['bottles'],
                  date=form.cleaned_data['date'],
                  time=form.cleaned_data['time'])
        if last and (last.bottles > log.bottles or last.date > log.date):
            print 'Bottle/date out of range'
            messages.error(request, 'Bottles or date out of range.')
        else:
            print 'Valid log'
            log.full_clean()
            try:
                log.save()
            except ValidationError:
                messages.error(request, 'Failed to create log.')
            signals.new_log_signal.send(sender=log, bottles=log.bottles)
            messages.success(request, 'New log added.')
    template = loader.get_template('logger/_messages.html')
    context = RequestContext(request)
    return HttpResponse(template.render(context))
예제 #2
0
 def __call__(self, request):
     start = time.time()
     response = self.get_response(request)
     if not request.path.startswith('/admin'):
         diff = time.time() - start
         log = Log(path=request.path, method=request.method, execution_time_sec=diff)
         log.save()
     return response
예제 #3
0
    def read( self, request, expression ):
	acct, lg, agent = expression.split('&')
	a, a_id = acct.split('=')
	l, l_tx = lg.split('=')
	ag, ag_id = agent.split('=')
	l = Log( log_dt = datetime.now(),
		 account = a_id,
		 agent = ag_id,
		 text = l_tx
		)
	l.save()
 	return HttpResponseRedirect('/tools/account/%s/%s/' % (a_id, ag_id))
예제 #4
0
 def record_log(self, imei, raw, type, send_time=None, **kwargs):
     device, created = Device.objects.get_or_create(imei=imei)
     if type == 'ack':
         # Acknowledgement, so try and find the SMS which this refers to
         try:
             sms = SMS.objects.get(device=device, send_time=send_time)
             l = Log(device=device, received_date_time=datetime.now(), message=raw, cause=sms)
         except SMS.DoesNotExist:
             l = Log(device=device, received_date_time=datetime.now(), message=raw)
     else:
         l = Log(device=device, received_date_time=datetime.now(), message=raw)
     l.save()
     return l
예제 #5
0
파일: views.py 프로젝트: muki/outfit-logger
def addLog(request):
    user = request.user
    date = datetime.strptime(request.POST['date'], '%d.%m.%Y')
    theme = request.POST['theme']
    notes = request.POST['notes']

    if request.POST['is_implicit'] == 'true':
        is_implicit = True
        fallacies = {}
    else:
        is_implicit = False
        fallacies = json.loads(request.POST['fallacies'])

    newlog = Log(user=user, date=date, is_implicit=is_implicit, fallacies=fallacies, theme=theme, notes=notes)
    newlog.save()

    return HttpResponse(1)
예제 #6
0
def log_session_error(request, exception):
    # -- General info
    log = Log(exception_type=type(exception).__name__,
              message=exception.detail,
              stack_trace=traceback.format_exc())
    log.request_url = request.get_full_path()
    log.request_method = request.method
    log.get_data = json.dumps(request.GET)
    log.post_data = json.dumps(request.POST)
    log.request_body = '{}'
    log.cookies = json.dumps(request.COOKIES)

    # --- Request meta info
    log.meta = ','.join('"%s": "%s"' % (k, str(v))
                        for k, v in request.META.items())
    log.meta = '{%s}' % log.meta
    log.meta = log.meta.replace('\\', '|')

    # --- User info
    if request.user.is_authenticated():
        log.user_id = request.user.id
        log.user_name = request.user.email

    # --- User agent info
    user_agent = request.user_agent
    # Browser
    log.request_browser = user_agent.browser
    # OS
    log.request_os = user_agent.os
    # Device
    log.request_device = user_agent.device
    # Device type
    log.is_mobile = user_agent.is_mobile
    log.is_tablet = user_agent.is_tablet
    log.is_touch_capable = user_agent.is_touch_capable
    log.is_pc = user_agent.is_pc
    log.is_bot = user_agent.is_bot

    # --- Save
    log.save()
    return None
예제 #7
0
def uploader(request):
    if request.method == 'POST':
        #Si ya mandaron el formulario entonces necesitaremos un formulario
        #"atado" a POST y FILES
        form = UploaderForm(request.POST, request.FILES)
        if form.is_valid():
            file_data = form['logfile']
            for line in file_data.value().readlines():
                p = parsear(line)
                if len(p) == 3:
                    fecha, tipo, mensaje = p
                    fecha = datetime.strptime(fecha, '%a %b %d %H:%M:%S %Y')
                    l = Log(fecha = fecha, tipo = tipo, mensaje = mensaje)
                    l.save()
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        #Esto ocurre si acaban de visitar la pagina.
        form = UploaderForm() # Un formulario "desatado" o "unbound"

    #CSRF
    c = {'form': form}
    c.update(csrf(request))
    return render_to_response('uploader.html', RequestContext(request, c))
예제 #8
0
def log_mop(mop, action, data=''):
    cron = mop.player.cron
    log = Log(cron=cron, mop=mop, action=action, data=data)
    log.save()
예제 #9
0
def log_cron(cron, action, data=''):
    log = Log(cron=cron, action=action, data=data)
    log.save()