def profile(request, userid): """displays a user profile""" user = get_object_or_404(User, id=userid) available_hardware = Hardware.objects.filter(owner=user, availability=True) accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account) if user.get_profile().displayLocation: map, showmap = create_map(user.get_profile().location) else: map = None context = { 'userprofile': user, 'available_hardware': available_hardware, 'map': map, 'accountlist': accountlist } if request.user == user: unavailable_hardware = Hardware.objects.filter(owner=user, availability=False) context['unavailable_hardware'] = unavailable_hardware return render_to_response('users/userprofile.html', context, RequestContext(request))
def displayHardware(request, id, name): """Display a hardware""" hardware = get_object_or_404(Hardware, id=id) context = {'hardware': hardware} if request.user.is_authenticated(): if hardware.owner != request.user and hardware.location != None and request.user.get_profile( ).location != None: hardwarelocation = hardware.location userlocation = request.user.get_profile().location context["distance"] = util.get_distance_string( hardwarelocation, userlocation) if hardware.owner.get_profile().displayLocation or request.user.is_staff: map, showmap = util.create_map(hardware.location, (500, 300)) context["map"] = map context["showmap"] = showmap images = MultiuploaderImage.objects.filter(hardware=hardware.id) context["images"] = images if hardware.lendlengthtype != None: lendlengthtypes = { '1': 'Tag(e)', '7': 'Woche(n)', '30': 'Monat(e)', '356': 'Jahr(e)' } context["lendlengthtype"] = lendlengthtypes[str( hardware.lendlengthtype)] return render_to_response('hardware/hardwareview.html', context, RequestContext(request))
def profile(request, userid): """displays a user profile""" user = get_object_or_404(User, id = userid) hardware =Hardware.objects.filter(owner=user) accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account) if user.get_profile().displayLocation: map, showmap = create_map(user.get_profile().location) else: map = None context = {'userprofile':user, 'hardware':hardware, 'map':map, 'accountlist':accountlist} return render_to_response('users/userprofile.html', context, RequestContext(request))
def displayHardware(request, id, name): """Display a hardware""" hardware = get_object_or_404(Hardware, id=id) context = {'hardware':hardware} if request.user.is_authenticated(): if hardware.owner != request.user and hardware.location != None and request.user.get_profile().location != None: hardwarelocation = hardware.location userlocation = request.user.get_profile().location context["distance"] = util.get_distance_string(hardwarelocation, userlocation) if hardware.owner.get_profile().displayLocation or request.user.is_staff: map, showmap = util.create_map(hardware.location, (500, 300)) context["map"] = map context["showmap"] = showmap images = MultiuploaderImage.objects.filter(hardware=hardware.id) context["images"] = images return render_to_response('hardware/hardwareview.html', context, RequestContext(request))
def profile(request, userid): """displays a user profile""" user = get_object_or_404(User, id=userid) available_hardware = Hardware.objects.filter(owner=user, availability=True) accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account) if user.get_profile().displayLocation: map, showmap = create_map(user.get_profile().location) else: map = None context = {"userprofile": user, "available_hardware": available_hardware, "map": map, "accountlist": accountlist} if request.user == user: unavailable_hardware = Hardware.objects.filter(owner=user, availability=False) context["unavailable_hardware"] = unavailable_hardware return render_to_response("users/userprofile.html", context, RequestContext(request))
def displayHardware(request, id, name): """Display a hardware""" hardware = get_object_or_404(Hardware, id=id) context = {"hardware": hardware} if request.user.is_authenticated(): if hardware.owner != request.user and hardware.location != None and request.user.get_profile().location != None: hardwarelocation = hardware.location userlocation = request.user.get_profile().location context["distance"] = util.get_distance_string(hardwarelocation, userlocation) if hardware.owner.get_profile().displayLocation or request.user.is_staff: map, showmap = util.create_map(hardware.location, (500, 300)) context["map"] = map context["showmap"] = showmap images = MultiuploaderImage.objects.filter(hardware=hardware.id) context["images"] = images if hardware.lendlengthtype != None: lendlengthtypes = {"1": "Tag(e)", "7": "Woche(n)", "30": "Monat(e)", "356": "Jahr(e)"} context["lendlengthtype"] = lendlengthtypes[str(hardware.lendlengthtype)] return render_to_response("hardware/hardwareview.html", context, RequestContext(request))
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() else: lform = LocationForm() mform = UserSettingsForm() 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)) @login_required def confirmEmail(request, confirmation_key): profile = request.user.get_profile() if profile.confirmation_key==confirmation_key: #if profile.key_expires < datetime.datetime.today(): # return render_to_response('users/confirm.html', {'expired': True}, RequestContext(request)) profile.mail_confirmed = True profile.save() return render_to_response('users/confirm.html', {'success': True}, RequestContext(request)) else: return render_to_response('users/confirm.html', {'invalid': True}, RequestContext(request))
else: lform = LocationForm() mform = UserSettingsForm() if user.password != "": passform = ChangePasswordForm() else: passform = SetPasswordForm() context.update({ "apps": apps, "accountlist": accountlist, 'profile': profile, 'lform': lform, 'mform': mform, 'passform': passform }) map, showmap = create_map(profile.location) context["map"] = map context["showmap"] = showmap return render_to_response('users/usersettings.html', context, RequestContext(request)) @login_required def confirmEmail(request, confirmation_key): profile = request.user.get_profile() if profile.confirmation_key == confirmation_key: #if profile.key_expires < datetime.datetime.today(): # return render_to_response('users/confirm.html', {'expired': True}, RequestContext(request)) profile.mail_confirmed = True profile.save() return render_to_response('users/confirm.html', {'success': True},
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))