Пример #1
0
    def handle(self, *args, **options):
        demo_user = User.objects.get(id=settings.DEMO_USER_ID)

        Flight.objects.filter(user=demo_user).delete()
        Plane.objects.filter(user=demo_user).delete()

        plane1 = Plane.objects.create(user=demo_user,
                                      tailnumber="N1234",
                                      type='C-172')
        plane2 = Plane.objects.create(user=demo_user,
                                      tailnumber="N5555",
                                      type='B-737')

        form = PopupFlightForm(
            dict(user=demo_user,
                 plane=plane2,
                 date=datetime.datetime.now(),
                 route_string='KLGA-KBOS',
                 total=3.2,
                 pic=3.2,
                 remarks="picked up dave"))

        form.save()

        edit_logbook.send(sender=demo_user)
Пример #2
0
def edit_flight(request, page):

    url = logbook_url(request.display_user, page)

    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")

    profile, c = Profile.objects.get_or_create(user=request.display_user)
    plane_widget = proper_plane_widget(profile)

    flight_id = request.POST['id']
    flight = Flight(pk=flight_id, user=request.display_user)

    form = forms.PopupFlightForm(request.POST,
                                 plane_widget=plane_widget,
                                 user=request.display_user,
                                 instance=flight,
                                 prefix="new")

    if form.is_valid() and request.display_user.username != 'ALL':
        form.save()

        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)

        return HttpResponseRedirect(url)

    return logbook(request, form=form, fail="edit")
Пример #3
0
def edit_flight(request, page):
    
    url = logbook_url(request.display_user, page)
        
    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")
    
    profile,c = Profile.objects.get_or_create(user=request.display_user)
    plane_widget = proper_plane_widget(profile)
    
    flight_id = request.POST['id']
    flight = Flight(pk=flight_id, user=request.display_user)

    form = forms.PopupFlightForm(request.POST,
                           plane_widget=plane_widget,
                           user=request.display_user,
                           instance=flight,
                           prefix="new")

    if form.is_valid() and request.display_user.username != 'ALL':
        form.save()
        
        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)
        
        return HttpResponseRedirect(url)
        
    return logbook(request, form=form, fail="edit")
Пример #4
0
def locations(request):
    customs = Location.objects.user_own(request.display_user)
    changed = False
    
    if "New" in request.POST.get('submit', "DERP"):
        form = CustomForm(request.POST)
        edit_or_new = 'new'
        
        if form.is_valid():
            point = get_point(form.cleaned_data['coordinates'])
            custom = form.save(commit=False)
            custom.loc_class = 3
            custom.location = point
            custom.user = request.display_user
            
            custom.save()
            changed = True
            
        else:
            ERROR = 'true'
            
    elif "Submit" in request.POST.get('submit', "DERP"):
        custom = Location.objects.get(loc_class=3,
                                      user=request.display_user,
                                      pk=request.POST.get('id', None) )
        form = CustomForm(request.POST, instance=custom)
        edit_or_new = 'edit'
        
        if form.is_valid():
            point = get_point(form.cleaned_data['coordinates'])
            custom = form.save(commit=False)
            custom.location = point
            custom.loc_class = 3
            
            custom.save()
            changed = True
            
        else:
            ERROR = 'true'
            
    elif "Delete" in request.POST.get('submit', "DERP"):
        custom = Location.objects.get(loc_class=3,
                                      user=request.display_user,
                                      pk=request.POST.get('id', None)
                                     )
        custom.delete()
        changed = True
        form = CustomForm()
        
    else:
        form = CustomForm()
        
    if changed:
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user)
        
    return locals()
Пример #5
0
def locations(request):
    customs = Location.objects.user_own(request.display_user)
    changed = False

    if "New" in request.POST.get('submit', "DERP"):
        form = CustomForm(request.POST)
        edit_or_new = 'new'

        if form.is_valid():
            point = get_point(form.cleaned_data['coordinates'])
            custom = form.save(commit=False)
            custom.loc_class = 3
            custom.location = point
            custom.user = request.display_user

            custom.save()
            changed = True

        else:
            ERROR = 'true'

    elif "Submit" in request.POST.get('submit', "DERP"):
        custom = Location.objects.get(loc_class=3,
                                      user=request.display_user,
                                      pk=request.POST.get('id', None))
        form = CustomForm(request.POST, instance=custom)
        edit_or_new = 'edit'

        if form.is_valid():
            point = get_point(form.cleaned_data['coordinates'])
            custom = form.save(commit=False)
            custom.location = point
            custom.loc_class = 3

            custom.save()
            changed = True

        else:
            ERROR = 'true'

    elif "Delete" in request.POST.get('submit', "DERP"):
        custom = Location.objects.get(loc_class=3,
                                      user=request.display_user,
                                      pk=request.POST.get('id', None))
        custom.delete()
        changed = True
        form = CustomForm()

    else:
        form = CustomForm()

    if changed:
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user)

    return locals()
Пример #6
0
def mass_entry(request):
    
    profile,c = Profile.objects.get_or_create(user=request.display_user)
    
    NewFlightFormset = modelformset_factory(
        Flight,
        form=forms.FormsetFlightForm,
        extra=profile.per_page,
        formset=forms.MassEntryFormset
    )
    NewFlightFormset.form = staticmethod(curry(forms.FormsetFlightForm, user=request.display_user))
        
    if request.POST.get('submit'):
        post = request.POST.copy()
        for pk in range(0, profile.per_page):
            # if this line has no date...
            if post["form-%s-date" % pk]:
                # add the user 
                post.update({"form-%s-user" % pk: str(request.user.pk)})
            else:
                # blank the user and plane fields
                post.update({"form-%s-user" % pk: u'',
                             "form-%s-plane" % pk: u''})
            
        formset = NewFlightFormset(
            post,
            queryset=Flight.objects.none(),
            user=request.display_user
        )
        
        if formset.is_valid():
            for form in formset.forms:
                instance = form.save(commit=False)
                instance.user = request.display_user
                if instance.date:
                    instance.save()
                    
            # send signal
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user)
            
            from django.core.urlresolvers import reverse
            return HttpResponseRedirect(
                reverse('logbook', kwargs={"username": request.display_user.username})
            )
        
    else:
        qs = Flight.objects.get_empty_query_set()
        formset = NewFlightFormset(queryset=qs,
                                   user=request.display_user)

    return locals()
Пример #7
0
def delete_flight(request, page):
    url = logbook_url(request.display_user, page)
    
    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")
        
    if request.display_user.username != 'ALL':
        flight_id = request.POST['id']
        Flight(pk=flight_id, user=request.display_user).delete()
        
        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)
    
    return HttpResponseRedirect(url)
Пример #8
0
def mass_entry(request):

    profile, c = Profile.objects.get_or_create(user=request.display_user)

    NewFlightFormset = modelformset_factory(Flight,
                                            form=forms.FormsetFlightForm,
                                            extra=profile.per_page,
                                            formset=forms.MassEntryFormset)
    NewFlightFormset.form = staticmethod(
        curry(forms.FormsetFlightForm, user=request.display_user))

    if request.POST.get('submit'):
        post = request.POST.copy()
        for pk in range(0, profile.per_page):
            # if this line has no date...
            if post["form-%s-date" % pk]:
                # add the user
                post.update({"form-%s-user" % pk: str(request.user.pk)})
            else:
                # blank the user and plane fields
                post.update({
                    "form-%s-user" % pk: u'',
                    "form-%s-plane" % pk: u''
                })

        formset = NewFlightFormset(post,
                                   queryset=Flight.objects.none(),
                                   user=request.display_user)

        if formset.is_valid():
            for form in formset.forms:
                instance = form.save(commit=False)
                instance.user = request.display_user
                if instance.date:
                    instance.save()

            # send signal
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user)

            from django.core.urlresolvers import reverse
            return HttpResponseRedirect(
                reverse('logbook',
                        kwargs={"username": request.display_user.username}))

    else:
        qs = Flight.objects.get_empty_query_set()
        formset = NewFlightFormset(queryset=qs, user=request.display_user)

    return locals()
Пример #9
0
def delete_flight(request, page):
    url = logbook_url(request.display_user, page)

    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")

    if request.display_user.username != 'ALL':
        flight_id = request.POST['id']
        Flight(pk=flight_id, user=request.display_user).delete()

        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)

    return HttpResponseRedirect(url)
Пример #10
0
def records(request):

    if request.POST:
        text = request.POST.get('records', None)
        records = Records(user=request.display_user, text=text)
        records.save()
        saved = True

        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)

    else:
        records, c = Records.objects.get_or_create(user=request.display_user)

    return locals()
Пример #11
0
def records(request):
      
    if request.POST:
        text = request.POST.get('records', None)
        records = Records(user=request.display_user, text=text)
        records.save()
        saved=True
        
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)
    
    else:
        records,c = Records.objects.get_or_create(user=request.display_user)
            
    return locals()
Пример #12
0
def mass_edit(request, page=0):

    flights = Flight.objects.filter(user=request.display_user)
    profile, c = Profile.objects.get_or_create(user=request.display_user)

    start = (int(page) - 1) * int(profile.per_page)
    duration = int(profile.per_page)
    qs = Flight.objects.filter(user=request.display_user)\
                       .order_by('date')[start:start+duration]

    NewFlightFormset = modelformset_factory(Flight,
                                            form=forms.FormsetFlightForm,
                                            formset=forms.MassEntryFormset,
                                            extra=0,
                                            can_delete=True)
    NewFlightFormset.form = staticmethod(
        curry(forms.FormsetFlightForm, user=request.display_user))

    if request.POST.get('submit'):
        pqs = Plane.objects.user_common(request.display_user)

        formset = NewFlightFormset(request.POST,
                                   queryset=qs,
                                   user=request.display_user)

        if formset.is_valid():
            formset.save()

            ## send signal to mark this user as having
            ## edited their logbook for today
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user, page=page)

            return HttpResponseRedirect(
                reverse('logbook-page',
                        kwargs={
                            "username": request.display_user.username,
                            "page": page
                        }))
    else:
        pqs = Plane.objects.user_common(request.display_user)
        formset = NewFlightFormset(queryset=qs, user=request.display_user)

    edit = True  # for rendering some text in the template
    return locals()
Пример #13
0
def mass_edit(request, page=0):

    flights = Flight.objects.filter(user=request.display_user)
    profile,c = Profile.objects.get_or_create(user=request.display_user)
    
    start = (int(page)-1) * int(profile.per_page)
    duration = int(profile.per_page)
    qs = Flight.objects.filter(user=request.display_user)\
                       .order_by('date')[start:start+duration]
    
    NewFlightFormset = modelformset_factory(
        Flight,
        form=forms.FormsetFlightForm,
        formset=forms.MassEntryFormset,
        extra=0,
        can_delete=True
    )
    NewFlightFormset.form = staticmethod(curry(forms.FormsetFlightForm, user=request.display_user))
        
    if request.POST.get('submit'):
        pqs = Plane.objects.user_common(request.display_user)
        
        formset = NewFlightFormset(request.POST,
                                   queryset=qs,
                                   user=request.display_user)
        
        if formset.is_valid():
            formset.save()
            
            ## send signal to mark this user as having
            ## edited their logbook for today
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user, page=page)
            
            return HttpResponseRedirect(
                reverse('logbook-page',
                        kwargs={"username": request.display_user.username,
                                "page": page})
            )
    else:
        pqs = Plane.objects.user_common(request.display_user)
        formset = NewFlightFormset(queryset=qs, user=request.display_user)

    edit = True     # for rendering some text in the template
    return locals()
Пример #14
0
def events(request):
    profile = request.display_user.get_profile()

    if profile.date_format:
        date_format = profile.date_format
    else:
        date_format = "Y-m-d"

    ##################################################

    nonflights = NonFlight.objects.filter(
        user=request.display_user).order_by('date')
    changed = False

    if request.POST:

        if request.POST.get("submit") == "Submit Changes":
            nf = NonFlight(pk=request.POST['id'])
            form = NonFlightForm(request.POST, instance=nf)
            if form.is_valid():
                form.save()
                changed = True

        elif request.POST.get("submit") == "Create New Event":
            form = NonFlightForm(request.POST)
            if form.is_valid():
                form.save()
                changed = True

        elif request.POST.get("submit") == "Delete Event":
            nf = NonFlight(pk=request.POST.get('id'))
            nf.delete()
            changed = True

            form = NonFlightForm()

    else:
        form = NonFlightForm(initial={'user': request.user})

    if changed:
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)

    return locals()
Пример #15
0
def events(request):
    profile = request.display_user.get_profile()
        
    if profile.date_format:
        date_format = profile.date_format
    else:
        date_format = "Y-m-d"
    
    ##################################################
    
    nonflights = NonFlight.objects.filter(user=request.display_user).order_by('date')
    changed = False
    
    if request.POST:
        
        if request.POST.get("submit") == "Submit Changes":
            nf = NonFlight(pk=request.POST['id'])
            form = NonFlightForm(request.POST, instance=nf)
            if form.is_valid():
                form.save()
                changed = True
                
        elif request.POST.get("submit") == "Create New Event":
            form = NonFlightForm(request.POST)
            if form.is_valid():
                form.save()
                changed = True
                
        elif request.POST.get("submit") == "Delete Event":
            nf = NonFlight(pk=request.POST.get('id'))
            nf.delete()
            changed = True
            
            form = NonFlightForm()
                
    else:
        form = NonFlightForm(initial={'user': request.user})
        
    if changed:
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)
    
    return locals()
Пример #16
0
def planes(request):
    planes = Plane.objects.filter(user=request.display_user)
    form = PopupPlaneForm()
    changed = False

    if request.POST.get('submit') == "Create New Plane":
        plane = Plane(user=request.display_user)
        form = PopupPlaneForm(request.POST, instance=plane)
        edit_or_new = "new"

        if form.is_valid():
            plane = form.save(commit=False)
            plane.user = request.display_user
            plane.save()
            changed = True

    elif request.POST.get('submit') == "Submit Changes":
        plane = Plane.objects.get(pk=request.POST.get("id"))
        form = PopupPlaneForm(request.POST, instance=plane)
        edit_or_new = "edit"

        if form.is_valid():
            plane = form.save(commit=False)
            plane.user = request.display_user
            plane.save()
            changed = True

    elif request.POST.get('submit') == "Delete Plane":
        plane = Plane.objects.get(pk=request.POST.get("id"))

        if not plane.flight_set.all().count() > 0:
            plane.delete()
            changed = True

    if changed:
        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user)

    return locals()
Пример #17
0
def planes(request):
    planes = Plane.objects.filter(user=request.display_user)
    form = PopupPlaneForm()
    changed = False
    
    if request.POST.get('submit') == "Create New Plane":
        plane = Plane(user=request.display_user)
        form = PopupPlaneForm(request.POST, instance=plane)      
        edit_or_new = "new"
        
        if form.is_valid():
            plane=form.save(commit=False)
            plane.user=request.display_user
            plane.save()
            changed = True
    
    elif request.POST.get('submit') == "Submit Changes":
        plane = Plane.objects.get(pk=request.POST.get("id"))
        form = PopupPlaneForm(request.POST, instance=plane)
        edit_or_new = "edit"
        
        if form.is_valid():
            plane=form.save(commit=False)
            plane.user=request.display_user
            plane.save()
            changed = True
            
    elif request.POST.get('submit') == "Delete Plane":
        plane = Plane.objects.get(pk=request.POST.get("id"))
        
        if not plane.flight_set.all().count() > 0:
            plane.delete()
            changed = True
            
    if changed:
        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user)
    
    return locals()
Пример #18
0
def mass_planes(request, page=0):
    from forms import PlaneFormset
    
    qs = Plane.objects.filter(user=request.display_user)
        
    if request.POST.get('submit'):
        formset = PlaneFormset(request.POST, queryset=qs)
        
        if formset.is_valid():
            formset.save()
            url = reverse('planes', kwargs={"username": request.display_user.username})
            return HttpResponseRedirect(url)
            
            ## send signal so this user is marked as having edited
            ## their logbook for today
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user)
    
    else:
        formset = PlaneFormset(queryset=qs)
    
    return locals()
Пример #19
0
    def handle(self, *args, **options):
    	demo_user = User.objects.get(id=settings.DEMO_USER_ID)
        
        Flight.objects.filter(user=demo_user).delete()
        Plane.objects.filter(user=demo_user).delete()

        plane1 = Plane.objects.create(user=demo_user, tailnumber="N1234", type='C-172')
        plane2 = Plane.objects.create(user=demo_user, tailnumber="N5555", type='B-737')

        form = PopupFlightForm(dict(
        	user=demo_user,
        	plane=plane2,
        	date=datetime.datetime.now(),
        	route_string='KLGA-KBOS',
        	total=3.2,
        	pic=3.2,
        	remarks="picked up dave"
        ))

        form.save()

        edit_logbook.send(sender=demo_user)
Пример #20
0
def mass_planes(request, page=0):
    from forms import PlaneFormset

    qs = Plane.objects.filter(user=request.display_user)

    if request.POST.get('submit'):
        formset = PlaneFormset(request.POST, queryset=qs)

        if formset.is_valid():
            formset.save()
            url = reverse('planes',
                          kwargs={"username": request.display_user.username})
            return HttpResponseRedirect(url)

            ## send signal so this user is marked as having edited
            ## their logbook for today
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user)

    else:
        formset = PlaneFormset(queryset=qs)

    return locals()
Пример #21
0
def import_v(request):

    fileform = ImportForm()
    
    ## get the previous uploaded file
    ## p=file, previous=dict with some metadata
    p, previous = get_last(request.display_user.id)
    
    if not request.method == 'POST':
        return locals()
    
    # whether or not we just display the cotents, or actually commit the
    # changes depending on which submit button was clicked
    preview = request.POST.get('preview_p') or\
              request.POST.get('preview_u') or\
              request.POST.get('preview_f')
    
    if request.POST.get('import_f') or request.POST.get('preview_f'):
        #the file form was used
        f = request.FILES.get('file')
        url = None
        force_tsv = False
        
    elif request.POST.get('import_u') or request.POST.get('preview_u'):
        # the PHP backup thing was used, may throw errors
        url = request.POST.get('url')
        ba = PHPBackup(url)
        f = None
        force_tsv = True
        
    else:
        url = None
        f = None
        force_tsv = False
    
    locs = {}
    try:
        if f:
            save_upload(f, request.display_user)
        elif url:
            f = ba.get_file()
            save_php(f, request.display_user)
        
        #now it's go time   
        locs = do_import(preview, request.display_user, force_tsv)
        
    except BaseImport.InvalidCSVError:
        Error = "Not a valid CSV file"
        
    except BaseImport.NoFileError:
        Error = "Could not find File"
        
    except InvalidToken:
        Error = "Invalid Token"
        
    except InvalidURL:
        Error = "Invalid URL"
    
    else:
        # the import finished and there are no errors
        if not preview:
            from backup.models import edit_logbook
            edit_logbook.send(sender=request.display_user)
         
    locs2 = locals()
    locs2.update(locs)
    return locs2
Пример #22
0
def profile(request):

    profile = Profile.objects.get_or_create(user=request.display_user)[0]
    column =  Columns.objects.get_or_create(user=request.display_user)[0]
    auto =    AutoButton.objects.get_or_create(user=request.display_user)[0]
    
    if request.POST:
        profile_form = ProfileForm(request.POST, instance=profile)
        user_form = UserForm(request.POST, instance=request.display_user)
        column_form = ColumnsForm(request.POST, prefix="column", instance=column)
        auto_form = AutoForm(request.POST, prefix="auto", instance=auto)
        password_form = ChangePasswordForm(request.POST, prefix='pass', user=request.user)

        if request.POST.get("submit") == "Delete All Flights":
            Flight.objects.filter(user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)
        
        elif request.POST.get("submit") == "Delete All Events":
            NonFlight.objects.filter(user=request.display_user).delete()
        
        elif request.POST.get("submit") == "Delete Unused Planes":
            Plane.objects.filter(flight__isnull=True, user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)
            
        elif request.POST.get("submit") == "Completely Reset All Data":
            NonFlight.objects.filter(user=request.display_user).delete()
            Flight.objects.filter(user=request.display_user).delete()
            Records.objects.filter(user=request.display_user).delete()
            Location.objects.filter(loc_class=3, user=request.display_user).delete()
            Plane.objects.filter(user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)
            
        else:
            
            if auto_form.is_valid():
                auto_form.save()
                
            if profile_form.is_valid():
                profile_form.save()
                
            if column_form.is_valid():
                column_form.save()
             
            if user_form.is_valid():
                ## remove illegal characters and spaces
                user = user_form.save(commit=False)
                user.username = \
                    re.sub(r'\W', '', user.username)\
                    .replace(" ",'')
                 
                if request.display_user.id == settings.DEMO_USER_ID:
                    ## don't let anyone change the demo's username or email
                    ## it will break stuff
                    user_form.cleaned_data['username'] = '******'
                    user_form.cleaned_data['email'] = '*****@*****.**'
                
                user.save()

            if password_form.is_valid():
                password_form.save()
    else:
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=request.display_user)
        column_form = ColumnsForm(prefix="column", instance=column)
        auto_form = AutoForm(prefix="auto", instance=auto)
        password_form = ChangePasswordForm(prefix='pass')
    
    f1 = '<td class="{cls}">{checkbox}</td>'
    f2 = '<td class="title">{title}</td><td class="description">{desc}</td>\n'
    
    
    bool_fields = []
    ## mix the auto button and the columns fields into the same html table
    ## FIXME: this should all be in a template tag
    for field in OPTION_FIELDS:
        row = []
        
        row.append("<tr>\n")
        
        if auto_form.fields.get(field):
            checkbox = str(auto_form[field])
        else:
            checkbox = "<input type='checkbox' style='visibility: hidden'>"
        
        row.append(f1.format(checkbox=checkbox, cls="aauto"))
            
        if column_form.fields.get(field):
            formatted = f1.format(checkbox=str(column_form[field]), cls="column")
            row.append(formatted)
        else:
            row.append('<td class="column"></td>')
        
        formatted = f2.format(title=FIELD_TITLES[field], desc=column_form[field].help_text)
        
        row.append(formatted)
                            
        row.append("</tr>\n")
        bool_fields.append("".join(row))

    return locals()
Пример #23
0
def profile(request):

    profile = Profile.objects.get_or_create(user=request.display_user)[0]
    column = Columns.objects.get_or_create(user=request.display_user)[0]
    auto = AutoButton.objects.get_or_create(user=request.display_user)[0]

    if request.POST:
        profile_form = ProfileForm(request.POST, instance=profile)
        user_form = UserForm(request.POST, instance=request.display_user)
        column_form = ColumnsForm(request.POST,
                                  prefix="column",
                                  instance=column)
        auto_form = AutoForm(request.POST, prefix="auto", instance=auto)
        password_form = ChangePasswordForm(request.POST,
                                           prefix='pass',
                                           user=request.user)

        if request.POST.get("submit") == "Delete All Flights":
            Flight.objects.filter(user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)

        elif request.POST.get("submit") == "Delete All Events":
            NonFlight.objects.filter(user=request.display_user).delete()

        elif request.POST.get("submit") == "Delete Unused Planes":
            Plane.objects.filter(flight__isnull=True,
                                 user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)

        elif request.POST.get("submit") == "Completely Reset All Data":
            NonFlight.objects.filter(user=request.display_user).delete()
            Flight.objects.filter(user=request.display_user).delete()
            Records.objects.filter(user=request.display_user).delete()
            Location.objects.filter(loc_class=3,
                                    user=request.display_user).delete()
            Plane.objects.filter(user=request.display_user).delete()
            edit_logbook.send(sender=request.display_user)

        else:

            if auto_form.is_valid():
                auto_form.save()

            if profile_form.is_valid():
                profile_form.save()

            if column_form.is_valid():
                column_form.save()

            if user_form.is_valid():
                ## remove illegal characters and spaces
                user = user_form.save(commit=False)
                user.username = \
                    re.sub(r'\W', '', user.username)\
                    .replace(" ",'')

                if request.display_user.id == settings.DEMO_USER_ID:
                    ## don't let anyone change the demo's username or email
                    ## it will break stuff
                    user_form.cleaned_data['username'] = '******'
                    user_form.cleaned_data['email'] = '*****@*****.**'

                user.save()

            if password_form.is_valid():
                password_form.save()
    else:
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=request.display_user)
        column_form = ColumnsForm(prefix="column", instance=column)
        auto_form = AutoForm(prefix="auto", instance=auto)
        password_form = ChangePasswordForm(prefix='pass')

    f1 = '<td class="{cls}">{checkbox}</td>'
    f2 = '<td class="title">{title}</td><td class="description">{desc}</td>\n'

    bool_fields = []
    ## mix the auto button and the columns fields into the same html table
    ## FIXME: this should all be in a template tag
    for field in OPTION_FIELDS:
        row = []

        row.append("<tr>\n")

        if auto_form.fields.get(field):
            checkbox = str(auto_form[field])
        else:
            checkbox = "<input type='checkbox' style='visibility: hidden'>"

        row.append(f1.format(checkbox=checkbox, cls="aauto"))

        if column_form.fields.get(field):
            formatted = f1.format(checkbox=str(column_form[field]),
                                  cls="column")
            row.append(formatted)
        else:
            row.append('<td class="column"></td>')

        formatted = f2.format(title=FIELD_TITLES[field],
                              desc=column_form[field].help_text)

        row.append(formatted)

        row.append("</tr>\n")
        bool_fields.append("".join(row))

    return locals()