Exemplo n.º 1
0
def hardwareEdit(request, id=None):
	user = request.user
	profile = user.get_profile()
	if user.email != "" and profile.mail_confirmed:
		if id==None:
			#Create new hardware
			if request.method == 'POST': # If the form has been submitted...
				form = HardwareForm(request.POST) # A form bound to the POST data
				if form.is_valid(): # All validation rules pass
					h = Hardware()
					h.name = form.cleaned_data['name']
					h.description = form.cleaned_data['description']
					h.condition = form.cleaned_data['condition']
					h.category = form.cleaned_data['category']
					h.state = get_object_or_404(State, id=form.cleaned_data['state'])
					h.owner = user
					if form.cleaned_data['ownlocation']:
						location = Location()
						location.city = form.cleaned_data['city']
						location.street = form.cleaned_data['street']
						location.postcode = form.cleaned_data['postcode']
						g = geocoders.Google()
						if location.city!= "" or location.street!="" or location.street!="":
							searchstring = location.street + ", " + location.postcode + " " + form.cleaned_data['city']
							try:
								places = g.geocode(urllib.quote(searchstring), exactly_one=False)
								location.latitude = places[0][1][0]
								location.longitude = places[0][1][1]
								location.save()
							except geocoders.google.GQueryError, e:
								messages.add_message(request, messages.ERROR, u"Es konnte kein Ort gefunden werden, der deiner Eingabe entspricht. Hast du dich vielleicht vertippt?")
								context = {'form':form, 'edit':False}
								return render_to_response('hardware/hardwareform.html', context, RequestContext(request))
							except:
								messages.add_message(request, messages.ERROR, u"Es gab einen Fehler beim überprüfen des Ortes. Hast du dich vielleicht vertippt?")
								context = {'form':form, 'edit':False}
								return render_to_response('hardware/hardwareform.html', context, RequestContext(request))
						else:
							location.latitude = None
							location.longitude = None
							location.save()
						h.location = location
					else:
						h.location = profile.location
					if h.state.temporary and form.cleaned_data['lendlength'] != None:
						h.lendlength = form.cleaned_data['lendlength']
						h.lendlengthtype = form.cleaned_data['lendlengthtype']

					h.save()
					messages.add_message(request, messages.SUCCESS, u"Deine Hardware wurde erfolgreich angelegt. Bitte füge noch ein paar Bilder hinzu.")
					context = {'form':form, 'hardware':h}
					return render_to_response('hardware/imageform.html', context, RequestContext(request))
Exemplo n.º 2
0
def hardwareEdit(request, id=None):
	user = request.user
	profile = user.get_profile()
	if user.email != "" and profile.mail_confirmed:
		if id==None:
			#Create new hardware
			if request.method == 'POST': # If the form has been submitted...
				form = HardwareForm(request.POST) # A form bound to the POST data
				if form.is_valid(): # All validation rules pass
					h = Hardware()
					h.name = form.cleaned_data['name']
					h.description = form.cleaned_data['description']
					h.condition = form.cleaned_data['condition']
					h.category = form.cleaned_data['category']
					h.state = get_object_or_404(State, id=form.cleaned_data['state'])
					h.owner = user
					if form.cleaned_data['ownlocation']:
						location = Location()
						location.city = form.cleaned_data['city']
						location.street = form.cleaned_data['street']
						location.postcode = form.cleaned_data['postcode']
						g = geocoders.Google()
						if location.city!= "" or location.street!="" or location.street!="":
							searchstring = location.street + ", " + location.postcode + " " + form.cleaned_data['city']
							places = g.geocode(urllib.quote(searchstring), exactly_one=False)
							location.latitude = places[0][1][0]
							location.longitude = places[0][1][1]
						else:
							location.latitude = None
							location.longitude = None
						location.save()
						h.location = location
					else:
						h.location = profile.location
					if h.state.temporary and form.cleaned_data['lendlength'] != None:
						h.lendlength = form.cleaned_data['lendlength'] * form.cleaned_data['lendlengthtype']

					h.save()
					messages.add_message(request, messages.SUCCESS, u"Deine Hardware wurde erfolgreich angelegt. Bitte füge noch ein paar Bilder hinzu.")
					context = {'form':form, 'hardware':h}
					return render_to_response('hardware/imageform.html', context, RequestContext(request))
			else:
				form = HardwareForm()

			context = {'form':form, 'edit':False}
			return render_to_response('hardware/hardwareform.html', context, RequestContext(request))
		else:
			#edit existing hardware
			hardware = get_object_or_404(Hardware, id=id)
			if user == hardware.owner:
				if request.method == 'POST':
					form = HardwareForm(request.POST) # A form bound to the POST data
					if form.is_valid():
						hardware.name = form.cleaned_data['name']
						hardware.description = form.cleaned_data['description']
						hardware.condition = form.cleaned_data['condition']
						hardware.category = form.cleaned_data['category']
						hardware.state = get_object_or_404(State, id=form.cleaned_data['state'])
						hardware.owner = user
						if form.cleaned_data['ownlocation']:
							location = Location()
							location.city = form.cleaned_data['city']
							location.street = form.cleaned_data['street']
							location.postcode = form.cleaned_data['postcode']
							g = geocoders.Google()
							if location.city!= "" or location.street!="" or location.street!="":
								searchstring = location.street + ", " + location.postcode + " " + form.cleaned_data['city']
								places = g.geocode(urllib.quote(searchstring), exactly_one=False)
								location.latitude = places[0][1][0]
								location.longitude = places[0][1][1]
							else:
								location.latitude = None
								location.longitude = None
							location.save()
							hardware.location = location
						else:
							hardware.location = profile.location
						hardware.save()
						print hardware.id
						messages.add_message(request, messages.SUCCESS, "Hardware wurde erfolgreich bearbeitet.")
						return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.name])) # Redirect after POST
				else:
					form = HardwareForm()

					form.initial["name"] = hardware.name
					form.initial["description"] = hardware.description
					form.initial["condition"] = hardware.condition
					form.initial["category"] = hardware.category
					form.initial["state"] = hardware.state.id
					images = MultiuploaderImage.objects.filter(hardware=hardware.id)
					context = {'form':form, 'hardware':hardware, 'edit':True, 'images':images}
					return render_to_response('hardware/hardwareform.html', context, RequestContext(request))
			else:
				return HttpResponseForbidden(loader.get_template("403.html").render(RequestContext({})))
	else:
		return render_to_response('hardware/hardwareform.html', {"invalidmail":True} , RequestContext(request))
Exemplo n.º 3
0
def hardwareEdit(request, id=None):
    user = request.user
    profile = user.get_profile()
    if user.email != "" and profile.mail_confirmed:
        if id == None:
            # Create new hardware
            if request.method == "POST":  # If the form has been submitted...
                form = HardwareForm(request.POST)  # A form bound to the POST data
                if form.is_valid():  # All validation rules pass
                    h = Hardware()
                    h.name = form.cleaned_data["name"]
                    h.description = form.cleaned_data["description"]
                    h.condition = form.cleaned_data["condition"]
                    h.category = form.cleaned_data["category"]
                    h.state = get_object_or_404(State, id=form.cleaned_data["state"])
                    h.owner = user
                    if form.cleaned_data["ownlocation"]:
                        location = Location()
                        location.city = form.cleaned_data["city"]
                        location.street = form.cleaned_data["street"]
                        location.postcode = form.cleaned_data["postcode"]
                        g = geocoders.Google()
                        if location.city != "" or location.street != "" or location.street != "":
                            searchstring = location.street + ", " + location.postcode + " " + form.cleaned_data["city"]
                            try:
                                places = g.geocode(urllib.quote(searchstring), exactly_one=False)
                                location.latitude = places[0][1][0]
                                location.longitude = places[0][1][1]
                                location.save()
                            except geocoders.google.GQueryError, e:
                                messages.add_message(
                                    request,
                                    messages.ERROR,
                                    u"Es konnte kein Ort gefunden werden, der deiner Eingabe entspricht. Hast du dich vielleicht vertippt?",
                                )
                        else:
                            location.latitude = None
                            location.longitude = None
                            location.save()
                        h.location = location
                    else:
                        h.location = profile.location
                    if h.state.temporary and form.cleaned_data["lendlength"] != None:
                        h.lendlength = form.cleaned_data["lendlength"]
                        h.lendlengthtype = form.cleaned_data["lendlengthtype"]

                    h.save()
                    messages.add_message(
                        request,
                        messages.SUCCESS,
                        u"Deine Hardware wurde erfolgreich angelegt. Bitte füge noch ein paar Bilder hinzu.",
                    )
                    context = {"form": form, "hardware": h}
                    return render_to_response("hardware/imageform.html", context, RequestContext(request))
            else:
                form = HardwareForm()

            context = {"form": form, "edit": False}
            return render_to_response("hardware/hardwareform.html", context, RequestContext(request))
        else:
            # edit existing hardware
            hardware = get_object_or_404(Hardware, id=id)
            if user == hardware.owner:
                if request.method == "POST":
                    form = HardwareForm(request.POST)  # A form bound to the POST data
                    if form.is_valid():
                        hardware.name = form.cleaned_data["name"]
                        hardware.description = form.cleaned_data["description"]
                        hardware.condition = form.cleaned_data["condition"]
                        hardware.category = form.cleaned_data["category"]
                        hardware.state = get_object_or_404(State, id=form.cleaned_data["state"])
                        hardware.owner = user
                        if form.cleaned_data["ownlocation"]:
                            location = Location()
                            location.city = form.cleaned_data["city"]
                            location.street = form.cleaned_data["street"]
                            location.postcode = form.cleaned_data["postcode"]
                            g = geocoders.Google()
                            if location.city != "" or location.street != "" or location.street != "":
                                searchstring = (
                                    location.street + ", " + location.postcode + " " + form.cleaned_data["city"]
                                )
                                places = g.geocode(urllib.quote(searchstring), exactly_one=False)
                                location.latitude = places[0][1][0]
                                location.longitude = places[0][1][1]
                            else:
                                location.latitude = None
                                location.longitude = None
                            location.save()
                            hardware.location = location
                        else:
                            hardware.location = profile.location
                        if hardware.state.temporary and form.cleaned_data["lendlength"] != None:
                            hardware.lendlength = form.cleaned_data["lendlength"]
                            hardware.lendlengthtype = form.cleaned_data["lendlengthtype"]
                        hardware.save()
                        messages.add_message(request, messages.SUCCESS, "Hardware wurde erfolgreich bearbeitet.")
                        return HttpResponseRedirect(
                            reverse(displayHardware, args=[hardware.id, hardware.slug])
                        )  # Redirect after POST
                else:
                    form = HardwareForm()

                    form.initial["name"] = hardware.name
                    form.initial["description"] = hardware.description
                    form.initial["condition"] = hardware.condition
                    form.initial["category"] = hardware.category
                    form.initial["state"] = hardware.state.id
                    form.initial["lendlength"] = hardware.lendlength
                    form.initial["lendlengthtype"] = hardware.lendlengthtype
                    images = MultiuploaderImage.objects.filter(hardware=hardware.id)
                    context = {"form": form, "hardware": hardware, "edit": True, "images": images}
                    return render_to_response("hardware/hardwareform.html", context, RequestContext(request))
            else:
                return HttpResponseForbidden(loader.get_template("403.html").render(RequestContext({})))
Exemplo n.º 4
0
					h.save()
					messages.add_message(request, messages.SUCCESS, u"Deine Hardware wurde erfolgreich angelegt. Bitte füge noch ein paar Bilder hinzu.")
					context = {'form':form, 'hardware':h}
					return render_to_response('hardware/imageform.html', context, RequestContext(request))
			else:
				form = HardwareForm()

			context = {'form':form, 'edit':False}
			return render_to_response('hardware/hardwareform.html', context, RequestContext(request))
		else:
			#edit existing hardware
			hardware = get_object_or_404(Hardware, id=id)
			if user == hardware.owner:
				if request.method == 'POST':
					form = HardwareForm(request.POST) # A form bound to the POST data
					if form.is_valid():
						hardware.name = form.cleaned_data['name']
						hardware.description = form.cleaned_data['description']
						hardware.condition = form.cleaned_data['condition']
						hardware.category = form.cleaned_data['category']
						hardware.state = get_object_or_404(State, id=form.cleaned_data['state'])
						hardware.owner = user
						if form.cleaned_data['ownlocation']:
							location = Location()
							location.city = form.cleaned_data['city']
							location.street = form.cleaned_data['street']
							location.postcode = form.cleaned_data['postcode']
							g = geocoders.Google()
							if location.city!= "" or location.street!="" or location.street!="":
								searchstring = location.street + ", " + location.postcode + " " + form.cleaned_data['city']
								try: