Revision e0657267
Added add_card_event view and made some minor changes to models
crm/crm/settings.py | ||
---|---|---|
92 | 92 |
MIDDLEWARE_CLASSES = ( |
93 | 93 |
'django.middleware.common.CommonMiddleware', |
94 | 94 |
'django.contrib.sessions.middleware.SessionMiddleware', |
95 |
'django.middleware.csrf.CsrfViewMiddleware', |
|
95 |
#'django.middleware.csrf.CsrfViewMiddleware',
|
|
96 | 96 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
97 | 97 |
'django.contrib.messages.middleware.MessageMiddleware', |
98 | 98 |
# Uncomment the next line for simple clickjacking protection: |
crm/crm/urls.py | ||
---|---|---|
10 | 10 |
# url(r'^$', 'crm.views.home', name='home'), |
11 | 11 |
# url(r'^crm/', include('crm.foo.urls')), |
12 | 12 |
url(r'^roboauth/(?P<rfid_tag>[0-9A-Fa-f]+)/(?P<mach_num>\d+)/', 'robocrm.views.roboauth'), |
13 |
url(r'^add_card_event/', 'robocrm.views.add_card_event'), |
|
13 | 14 |
|
14 | 15 |
# Uncomment the admin/doc line below to enable admin documentation: |
15 | 16 |
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')), |
crm/robocrm/models.py | ||
---|---|---|
88 | 88 |
choices=STATUS_CHOICES, |
89 | 89 |
default=GOOD) |
90 | 90 |
def __unicode__(self): |
91 |
return self.user.username;
|
|
91 |
return self.user.username |
|
92 | 92 |
|
93 | 93 |
# needed for Django Auth model |
94 | 94 |
def create_roboclub_user(sender, instance, created, **kwargs): |
... | ... | |
106 | 106 |
succ = models.BooleanField(default=False) |
107 | 107 |
imgurl = models.URLField() |
108 | 108 |
machine = models.ForeignKey('Machine') |
109 |
project = models.ForeignKey('Project') |
|
109 |
project = models.ForeignKey('Project', null=True)
|
|
110 | 110 |
matuse = models.TextField() |
111 | 111 |
|
112 | 112 |
def __unicode__(self): |
113 |
return u'%s %s %s' (self.type, self.user.username, self.succ)
|
|
113 |
return u'%s %s %s'%(self.type, self.user.user.username, self.succ)
|
|
114 | 114 |
|
115 | 115 |
# Project Model |
116 | 116 |
class Project(models.Model): |
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