Statistics
| Branch: | Revision:

root / crm / robocrm / views.py @ 06dedf83

History | View | Annotate | Download (1.57 KB)

1 988e217a Julian Binder
# Create your views here.
2 e0657267 Tom Mullins
from django.http import HttpResponse, Http404
3 06dedf83 Tom Mullins
from django.core.exceptions import PermissionDenied
4 e0657267 Tom Mullins
from django.contrib.auth import authenticate, login
5 66cc3ee3 Julian Binder
from robocrm.models import *
6 7cc67b05 Julian Binder
7
def index(request):
8
  return HttpResponse("Hello again, world!")
9 314bdec9 Julian Binder
10 66cc3ee3 Julian Binder
def roboauth(request, rfid_tag, mach_num):
11
  r = RoboUser.objects.filter(rfid=rfid_tag)
12
  if r.count() > 0:
13
    us = r[0]
14
  else:
15
    return HttpResponse("0")
16
  auth_machines = us.machines.filter(id=mach_num)
17
  if auth_machines.count() > 0 :
18
    return HttpResponse("1")
19
  else :
20
    return HttpResponse("0")
21 314bdec9 Julian Binder
22 e0657267 Tom Mullins
def add_card_event(request):
23
  if request.method != 'POST':
24
    raise Http404
25
  if 'username' in request.POST and 'password' in request.POST:
26
    user = authenticate(username=request.POST['username'],
27
        password=request.POST['password'])
28
    if user is not None and user.is_active:
29
      login(request, user)
30
31
  if not request.user.is_authenticated() \
32
      or not request.user.has_perm('robocrm.add_event'):
33
    raise PermissionDenied
34
35
  tstart = request.POST['tstart'] # TODO convert to date
36
  tend = request.POST['tend']
37
  user_id = request.POST['user_id']
38
  succ = request.POST['succ'] == '1'
39
  imgurl = '' # TODO find url based on tstart
40
  machine_id = int(request.POST['machine_id'])
41
42
  robouser = RoboUser.objects.get(rfid__iexact=user_id)
43
  machine = Machine.objects.get(id__exact=machine_id)
44
45
  ev = Event(type='card',
46
      tstart=tstart,
47
      tend=tend,
48
      user=robouser,
49
      succ=succ,
50
      imgurl=imgurl,
51
      machine=machine,
52
      project=None,
53
      matuse='')
54
55
  ev.save()
56
57
  return HttpResponse()