Beispiel #1
0
def settings(request):
    """displays the settings for an account"""
    user = request.user
    profile = user.get_profile()
    accounts = SocialAccount.objects.filter(user=user)
    accountlist = []
    for account in accounts:
        accountlist.append(account.provider)
    apps = SocialApp.objects.all()
    context = {}
    if request.method == 'POST':  # If the form has been submitted...
        if request.POST["type"] == "location":
            lform = LocationForm(request.POST)
            mform = UserSettingsForm()
            if lform.is_valid():  # All validation rules pass
                if profile.location == None:
                    location = Location()
                    location.save()
                    profile.location = location
                    profile.save()
                else:
                    location = profile.location
                location.city = lform.cleaned_data['city']
                location.street = lform.cleaned_data['street']
                location.postcode = lform.cleaned_data['postcode']
                profile.displayLocation = lform.cleaned_data['displayLocation']
                g = geocoders.Google()
                if location.city != "" or location.street != "" or location.street != "":
                    try:
                        places = g.geocode(location.street + ", " +
                                           location.postcode + " " +
                                           location.city,
                                           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()
                profile.save()
        else:
            lform = LocationForm()
            mform = UserSettingsForm(request.POST)
            mform.user = request.user
            if mform.is_valid():
                if mform.cleaned_data['email'] != user.email:
                    set_mail(user, mform.cleaned_data['email'])
                if mform.cleaned_data['displayname'] != profile.displayname:
                    profile.displayname = mform.cleaned_data['displayname']
                    profile.save()
                user.save()
Beispiel #2
0
def settings(request):
    """displays the settings for an account"""
    user = request.user
    profile = user.get_profile()
    accounts = SocialAccount.objects.filter(user=user)
    accountlist = []
    for account in accounts:
        accountlist.append(account.provider)
    apps = SocialApp.objects.all()
    context = {}
    if request.method == "POST":  # If the form has been submitted...
        if request.POST["type"] == "location":
            lform = LocationForm(request.POST)
            mform = UserSettingsForm()
            if lform.is_valid():  # All validation rules pass
                if profile.location == None:
                    location = Location()
                    location.save()
                    profile.location = location
                    profile.save()
                else:
                    location = profile.location
                location.city = lform.cleaned_data["city"]
                location.street = lform.cleaned_data["street"]
                location.postcode = lform.cleaned_data["postcode"]
                profile.displayLocation = lform.cleaned_data["displayLocation"]
                g = geocoders.Google()
                if location.city != "" or location.street != "" or location.street != "":
                    try:
                        places = g.geocode(
                            location.street + ", " + location.postcode + " " + location.city, 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()
                profile.save()
        else:
            lform = LocationForm()
            mform = UserSettingsForm(request.POST)
            mform.user = request.user
            if mform.is_valid():
                if mform.cleaned_data["email"] != user.email:
                    set_mail(user, mform.cleaned_data["email"])
                if mform.cleaned_data["displayname"] != profile.displayname:
                    profile.displayname = mform.cleaned_data["displayname"]
                    profile.save()
                user.save()
Beispiel #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?")
								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))
Beispiel #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']
							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))
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({})))
Beispiel #6
0
			#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:
									places = g.geocode(urllib.quote(searchstring), exactly_one=False)
									location.latitude = places[0][1][0]
									location.longitude = places[0][1][1]
								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, 'hardware':hardware, 'edit':True}
									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, 'hardware':hardware, 'edit':True}
Beispiel #7
0
def settings(request):
	"""displays the settings for an account"""
	user = request.user
	profile = user.get_profile()
	accounts = SocialAccount.objects.filter(user=user)
	accountlist = []
	for account in accounts:
		accountlist.append(account.provider)
	apps = SocialApp.objects.all()
	context = {}
	if request.method == 'POST': # If the form has been submitted...
		if request.POST["type"] == "location":
			lform = LocationForm(request.POST)
			mform = UserSettingsForm()
			if lform.is_valid(): # All validation rules pass
				if profile.location==None:
					location = Location()
					location.save()
					profile.location = location
					profile.save()
				else:
					location = profile.location
				location.city = lform.cleaned_data['city']
				location.street = lform.cleaned_data['street']
				location.postcode = lform.cleaned_data['postcode']
				profile.displayLocation = lform.cleaned_data['displayLocation']
				g = geocoders.Google()
				if location.city!= "" or location.street!="" or location.street!="":
					places = g.geocode(location.street + ", " + location.postcode + " " + location.city, exactly_one=False)
					location.latitude = places[0][1][0]
					location.longitude = places[0][1][1]
				else:
					location.latitude = None
					location.longitude = None
				location.save()
				profile.save()
				print profile.location.city
		else:
			lform = LocationForm()
			mform = UserSettingsForm(request.POST, request.FILES)
			if mform.is_valid():
				print "valid"
				if 'avatar' in request.FILES:
					profile.avatar = request.FILES["avatar"]
					profile.save()
					print "file saved"
				if mform.cleaned_data['email'] != user.email:
					set_mail(user, mform.cleaned_data['email'])
				if mform.cleaned_data['displayname'] != profile.displayname:
					profile.displayname = mform.cleaned_data['displayname'] 
					profile.save()
				user.save()
	else:
		lform = LocationForm()
		mform = UserSettingsForm()
	if not profile.mail_confirmed:
		context["mailconfirm"] = "We sent you a confirmation link. Please check your mail."
	context.update({"apps":apps, "accountlist":accountlist, 'profile':profile, 'lform':lform, 'mform':mform})
	map, showmap = create_map(profile.location)
	context["map"] = map
	context["showmap"] = showmap
	return render_to_response('users/usersettings.html', context, RequestContext(request))