Ejemplo n.º 1
0
	def handle(self, *args, **options):
		if len(args) > 0:
			raise CommandError('need exactly zero arguments')

		f = open('{0}/cleaned_list'.format(os.getcwd()), "r")
		lines = f.readlines()
		f.close()
		length = len(lines)
		print "Generating 10 States"
		for i in range(10):
			s = State()
			s.name = lines[randrange(1, length)-1]
			s.temporary = choice([True, False])
			s.save()
		print "Generating 10 Categories"
		for i in range(10):
			c = Category()
			c.name = lines[randrange(1, length)-1]
			c.save()
		print "Generating 10 Conditions"
		for i in range(10):
			c = Condition()
			c.name = lines[randrange(1, length)-1]
			c.save()

		print "Generating 4000 Hardwares"
		for i in range(4000):
			h = Hardware()
			h.name = lines[randrange(1, length)-1]
			h.state = choice(State.objects.all())
			h.condition = choice(Condition.objects.all())
			h.category = choice(Category.objects.all())
			h.description = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nibh justo, ornare semper pharetra id, laoreet quis ligula. Mauris non sem elit, nec ornare lectus. Duis sit amet dolor eleifend tellus congue auctor eget a augue. Fusce aliquam, ipsum sit amet imperdiet viverra, neque nisl aliquet arcu, quis tristique libero diam a sem. Curabitur quis elementum enim. Cras id nulla a arcu sollicitudin condimentum vestibulum ac risus. In tincidunt hendrerit mollis. Nunc sed nulla nibh, aliquam aliquam neque. Aenean eget cursus dui. Ut a purus neque. Proin eu eros elit. Suspendisse nisl enim, sagittis vel vulputate eu, pretium vitae ligula. Morbi posuere luctus dolor, sit amet tempus dolor vestibulum id. In ornare, risus eget mattis varius, dui tellus dapibus ligula, vel adipiscing risus elit non risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. """
			h.owner = choice(User.objects.all())
			if choice([True, False]):
				h.location = h.owner.get_profile().location
			else:
				l = Location()
				l.latitude = uniform(7.5 ,13.6)
				l.longitude = uniform(47.5, 53.8)
				l.save()
				h.location = l
			h.save()
Ejemplo 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"]
                            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({})))
Ejemplo 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']
							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))
Ejemplo n.º 4
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))