def edit_regulation(request, pk=None): '''A form to edit the titles of regulations. If no primary key is specified, this script will find the next regulation where the title is "[Not set]". If a primary key is specified, the corresponding regulation will be presented as a form or saved. ''' message = '' if pk is None: regulation = Regulation.objects.filter(title='[Not set]')[0] message = 'Edit the regulation below.' else: regulation = get_object_or_404(Regulation, pk=pk) if request.method == 'POST': form = RegulationForm(request.POST, instance=regulation) if form.is_valid(): form.save() message = 'Saved.' regulation = Regulation.objects.filter(title='[Not set]')[0] else: message = 'Your submission was invalid.' form = RegulationForm(instance=regulation) return render_to_response('parser_tools/edit_regulation.html', {'form': form, 'message': message, 'regulation': regulation, 'DATA_PATH': DATA_PATH}, context_instance=RequestContext(request))
def add_by_hand(request): '''A form to add regulations that can't be scraped. Currently, this is only used for HTML files. ''' # add HTML file to folder if request.method == 'POST': # validate and save form data form = RegulationForm(request.POST) if form.is_valid(): regulation = form.save() generate_regulation_pages(regulation) return redirect('parser_tools.views.add_by_hand') else: message = 'Your submission was invalid.' return render_to_response('parser_tools/add_by_hand.html', {'message': message}, context_instance=RequestContext(request)) else: form = RegulationForm() return render_to_response('parser_tools/add_by_hand.html', {'form': form}, context_instance=RequestContext(request))