<commit_before>import datetime as dt

from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, Http404
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.template import RequestContext

from etcetera.service import models as service
from etcetera.service import forms as woforms
from etcetera.equipment import models as equipment
from etcetera.service.mailer import *
from etcetera.extras.search import get_query

def service_form(request):
	# If data is being sent in POST, then get that data, clean it, and assign
	# it to a new WorkOrder instance.
	if request.method == 'POST':
		form = woforms.ServiceForm(request.POST)
		if form.is_valid():
			cd = form.cleaned_data
			wo = service.WorkOrder()
			name = cd['name'].split(' ')
			wo.first_name = name[0]
			wo.last_name = name[-1]
			wo.department_text = cd['department']
			wo.phone = cd['phone']
			wo.email = cd['email']
			wo.building = cd['building']
			wo.room = cd['room']
			wo.equipment_text = cd['equipment_text']
			if cd['barcode']:
				wo.equipment = wo.barcode_lookup(cd['barcode'])
			wo.description = cd['description']
			wo.work_type = cd['work_type']
			wo.save()
			created_mail(wo, cd['coordinator_check'])
			return HttpResponseRedirect('/thanks.html')
	# If data is not being sent in POST, our form is an empty one.
	else:
		form = woforms.ServiceForm()
	# Bundle our form in the context and send it out.
	context = {'form':form,}
	return render_to_response(
		"service/service_form.html",
		context, context_instance=RequestContext(request)
	)

@login_required
def index(request, view_type=None):
	paged_objects = None
	q = None
	form = woforms.SearchForm()
	if request.GET and request.GET.get('q'):
		form = woforms.SearchForm(request.GET)<commit_msg>Fixed nasty bug on barcode lookup in public service form.<commit_after>import datetime as dt

from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, Http404
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.template import RequestContext

from etcetera.service import models as service
from etcetera.service import forms as woforms
from etcetera.equipment import models as equipment
from etcetera.service.mailer import *
from etcetera.extras.search import get_query

def service_form(request):
	# If data is being sent in POST, then get that data, clean it, and assign
	# it to a new WorkOrder instance.
	if request.method == 'POST':
		form = woforms.ServiceForm(request.POST)
		if form.is_valid():
			cd = form.cleaned_data
			wo = service.WorkOrder()
			name = cd['name'].split(' ')
			wo.first_name = name[0]
			wo.last_name = name[-1]
			wo.department_text = cd['department']
			wo.phone = cd['phone']
			wo.email = cd['email']
			wo.building = cd['building']
			wo.room = cd['room']
			wo.equipment_text = cd['equipment_text']
			if cd['barcode']:
				try:
					cd['equipment'] = equipment.Equipment.objects.get(
						barcode=cd['barcode']
					)
				except equipment.Equipment.DoesNotExist:
					cd['equipment'] = None
			else:
				cd['equipment'] = None
			wo.description = cd['description']
			wo.work_type = cd['work_type']
			wo.save()
			created_mail(wo, cd['coordinator_check'])
			return HttpResponseRedirect('/thanks.html')
	# If data is not being sent in POST, our form is an empty one.
	else:
		form = woforms.ServiceForm()
	# Bundle our form in the context and send it out.
	context = {'form':form,}
	return render_to_response(
		"service/service_form.html",
		context, context_instance=RequestContext(request)
	)

@login_required
def index(request, view_type=None):
	paged_objects = None
	q = None
	form = woforms.SearchForm()
	if request.GET and request.GET.get('q'):
		form = woforms.SearchForm(request.GET)
{'fraction_non_alphanumeric': 0.10701015605647758, 'fraction_numerical': 0.003963339113202873, 'mean_word_length': 4.531506849315068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1254550', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1263, 'n_words': 361}