Changeset 9749 for src/django_gheat/wlheatmap/forms.py
- Timestamp:
- Dec 3, 2011, 12:17:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/wlheatmap/forms.py
r9746 r9749 1 1 from django import forms 2 from django.conf import settings 3 from django.contrib.auth import authenticate, login 4 from django.contrib.auth.decorators import login_required 2 5 from django.core.files.base import ContentFile 6 from django.db import IntegrityError 7 from django.http import HttpResponse,HttpResponseServerError 3 8 from django.shortcuts import render_to_response 4 from django.http import HttpResponse,HttpResponseServerError5 from django.conf import settings6 9 from gheat.models import * 7 from django.db import IntegrityError8 10 9 11 def get_apperatuur_choices(item): … … 11 13 12 14 class MeetBestandForm(forms.Form): 15 username = forms.CharField() 16 password = forms.CharField() 13 17 naam = forms.ChoiceField(choices=Gebruiker.objects.values_list('naam','naam')) 14 18 kaart = forms.ChoiceField(choices=get_apperatuur_choices('kaart')) … … 18 22 19 23 # 20 # curl -F naam=huub -F kaart=onbekend -F antenne=onbekend -F bestand=@manage.py -F surveyid=kerk http://localhost:8000/wlheatp/add/meetbestand/24 # curl -Fusername=huub -Fpassword=bert -F naam=huub -F kaart=onbekend -F antenne=onbekend -F bestand=@manage.py -F surveyid=kerk http://localhost:8000/wlheatmap/add/meetbestand/ 21 25 def add_meetbestand(request): 22 26 if request.method == 'POST': 23 27 form = MeetBestandForm(request.POST, request.FILES) 24 28 if form.is_valid(): 29 username = form.cleaned_data['username'] 30 password = form.cleaned_data['password'] 31 user = authenticate(username=username, password=password) 32 if user == None or not user.is_active: 33 return HttpResponseServerError('ERROR: Authentication Failed') 34 35 login(request, user) 36 25 37 gebruiker = Gebruiker.objects.get(naam=form.cleaned_data['naam']) 26 38 apparatuur, created = Apparatuur.objects.get_or_create(kaart=form.cleaned_data['kaart'], … … 37 49 return HttpResponse('OK: Attached to meetrondje %s' % meetrondje) 38 50 else: 39 return HttpResponseServerError('ERROR File does already exists')51 return HttpResponseServerError('ERROR: File does already exists') 40 52 else: 41 return HttpResponseServerError('ERROR No valid input')53 return HttpResponseServerError('ERROR: No valid input') 42 54 else: 43 55 form = MeetBestandForm()
Note:
See TracChangeset
for help on using the changeset viewer.