Changeset 9746 for src


Ignore:
Timestamp:
Dec 3, 2011, 10:58:19 AM (13 years ago)
Author:
rick
Message:
  • Cannot be placed in init as this will causes the CHOICES to load _before_

the database is created, leading to unknown table errors.

  • Added surveyid to upload field to allow selecting which meetrondje to use.
Location:
src/django_gheat/wlheatmap
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/wlheatmap/__init__.py

    r9674 r9746  
    3535  response.write('</pre>')
    3636  return response
    37 
    38 from django import forms
    39 from django.core.files.base import ContentFile
    40 
    41 def get_apperatuur_choices(item):
    42   return sorted(set(Apparatuur.objects.values_list(item,item)))
    43 
    44 class MeetBestandForm(forms.Form):
    45     naam = forms.ChoiceField(choices=Gebruiker.objects.values_list('naam','naam'))
    46     kaart = forms.ChoiceField(choices=get_apperatuur_choices('kaart'))
    47     antenne = forms.ChoiceField(choices=get_apperatuur_choices('antenne'))
    48     bestand = forms.FileField()
    49 
    50 #
    51 # curl  -F naam=huub -F kaart=onbekend -F antenne=onbekend -F bestand=@manage.py http://localhost:8000/wlheatp/add/meetbestand/
    52 def add_meetbestand(request):
    53   if request.method == 'POST':
    54     form = MeetBestandForm(request.POST, request.FILES)
    55     if form.is_valid():
    56       gebruiker = Gebruiker.objects.get(naam=form.cleaned_data['naam'])
    57       apparatuur, created = Apparatuur.objects.get_or_create(kaart=form.cleaned_data['kaart'],
    58         antenne=form.cleaned_data['antenne'])
    59       meetrondje, created = MeetRondje.objects.get_or_create(gebruiker=gebruiker,
    60         datum=None,
    61         naam=(form.cleaned_data['bestand']),
    62         apparatuur=apparatuur)
    63 
    64       meetbestand, created = MeetBestand.objects.get_or_create(meetrondje=meetrondje,is_imported=False)
    65       if created:
    66         meetbestand.bestand.save(form.cleaned_data['bestand'].name,form.cleaned_data['bestand'])
    67         meetbestand.save()
    68         return HttpResponse('OK')
    69       else:
    70         return HttpResponseServerError('ERROR File does already exists')
    71     else:
    72       return HttpResponseServerError('ERROR No valid input')
    73   else:
    74     form = MeetBestandForm()
    75   return render_to_response('add_file.html', {'form': form})
  • src/django_gheat/wlheatmap/urls.py

    r9660 r9746  
    11from django.conf.urls.defaults import *
    22from django.views.generic.simple import direct_to_template
    3 #from django.views.generic.base import TemplateView
    43from django.conf import settings
    54
    6 #class HomeView(TemplateView):
    7 #    template_name = 'home.html'
    8 #
    9 #urlpatterns = patterns('',
    10 #    ('^$', HomeView.as_view())
    11 #)
    125
    136urlpatterns = patterns('wlheatmap',
     
    2013    url(r'^filters/$', 'filters.serve_filters'),
    2114    url(r'^process/$', 'process'),
    22     url(r'^add/meetbestand/$', 'add_meetbestand'),
     15    url(r'^add/meetbestand/$', 'forms.add_meetbestand'),
    2316)
Note: See TracChangeset for help on using the changeset viewer.