Project

General

Profile

Revision e0657267

IDe06572672cc356170812f7d26e46a4653bd5916d
Parent 38df0012
Child 049ebb6e

Added by Thomas Mullins about 11 years ago

Added add_card_event view and made some minor changes to models

View differences:

crm/robocrm/views.py
1 1
# Create your views here.
2
from django.http import HttpResponse
2
from django.http import HttpResponse, Http404
3
from django.contrib.auth import authenticate, login
3 4
from robocrm.models import *
4 5

  
5 6
def index(request):
6 7
  return HttpResponse("Hello again, world!")
7 8

  
8 9
def roboauth(request, rfid_tag, mach_num):
9
#  return HttpResponse("Hello, world!")
10 10
  r = RoboUser.objects.filter(rfid=rfid_tag)
11 11
  if r.count() > 0:
12 12
    us = r[0]
......
18 18
  else :
19 19
    return HttpResponse("0")
20 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()

Also available in: Unified diff