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