def login(request): if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): try: if request.is_ajax(): user = form.authenticate(request) if not user is None: accesstype = request.session['access_type'] auth.login(request, user) if accesstype == DEFUSER_ACCESS_TYPES[0][0]: return json_result({'success': 1, 'accesstype': accesstype}) else: ts = get_template('theme_select.html') themeselect = ts.render(RequestContext(request)) return json_result({'success': 1, 'accesstype': accesstype, 'themeselect': themeselect}) else: return json_form_error(form) else: return HttpResponseRedirect('/') except Exception, e: return HttpResponse(e) else: return json_form_error(form)
def get(request): if not 'id' in request.GET: return json_error(1, arg1='id') try: result = Location.objects\ .values('id', 'longitude', 'latitude', 'last_update', 'date_created')\ .get(id=int(request.GET['id'])) except (ObjectDoesNotExist, ValueError, TypeError): return json_error(2, arg1='id') return json_result(result)
def logout(request): cleanup(request) auth.logout(request) #request.session.set_test_cookie() form = AuthForm() t = get_template('registration/login.html') ts = get_template('theme_select.html') loginform = t.render(RequestContext(request, {'form': form})) themeselect = ts.render(RequestContext(request)) return json_result({'success': 1, 'loginform': loginform, 'themeselect': themeselect})
def get(request): if (not 'id' in request.GET) and (not 'name' in request.GET): return json_error(1, arg1='id or name') try: res = Truck.objects.values('id', 'name', 'location_id', 'last_update', 'date_created') if 'id' in request.GET: result = res.get(id=request.GET['id']) else: result = res.get(name=request.GET['name']) except ObjectDoesNotExist: return json_error(2, arg1='id or name') return json_result(result)
def add(request): if not 'name' in request.GET: return json_error(1, arg1='name') if not 'location_id' in request.GET: return json_error(1, arg1='location_id') try: location = Location.objects.get(id=int(request.GET['location_id'])) except (ObjectDoesNotExist, ValueError, TypeError): return json_error(2, arg1='location') result = Truck.objects.create(name=request.GET['name'], location=location) return json_result(result.id)
def add(request): if not 'longitude' in request.GET: return json_error(1, arg1='longitude') if not 'latitude' in request.GET: return json_error(1, arg1='latitude') # # defaults = request.GET # if 'id' in defaults: # defaults.pop('id') # defaults.pop('longitude') # defaults.pop('latitude') result, created = Location.objects\ .get_or_create(longitude=request.GET['longitude'], latitude=request.GET['latitude']) return json_result(result.id)
def test(request): return json_result(True)