Beispiel #1
0
def location(request):
    """
    Location selection of the user profile
    """
    if (request.user.password == "!"):
        return HttpResponseRedirect('/accounts/social')
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit_location_done"))
    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = {
        'section': 'location',
        'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
        'form': form,
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Beispiel #2
0
 def post(self, request, *args, **kwargs):
     parking_lot_instance = get_object_or_404(ParkingLot, id=kwargs['pk'])
     location = LocationForm(request.POST,
                             instance=parking_lot_instance.location)
     if location.is_valid():
         location.save()
         messages.add_message(request, messages.SUCCESS,
                              'Informações atualizadas com sucesso.')
         return redirect('estacionamento-detalhe', kwargs['pk'])
     messages.add_message(request, messages.ERROR,
                          'Erro ao atualizar informações.')
     return render(request, 'website/system/parking_lot/location-form.html',
                   {'form': location})
Beispiel #3
0
def register_user(request):

    context = setup_view(request, 'Register')

    if request.method == 'POST': # If the form has been submitted...
        citizen_form = CitizenForm(request.POST, request.FILES) # A form bound to the POST data
        location_form = LocationForm(request.POST)

        if citizen_form.is_valid() and location_form.is_valid(): # All validation rules pass

            #Save the valid data
            home_location = location_form.save(commit=True)
            user = citizen_form.save(commit=False)

            email = citizen_form.cleaned_data.get('email')
            avatar = citizen_form.cleaned_data.get('avatar')
            first_name = citizen_form.cleaned_data.get('first_name')
            last_name = citizen_form.cleaned_data.get('last_name')

            citizen = Citizen.objects.create(email=email, first_name=first_name, last_name=last_name, avatar=avatar,
                                             user=user, home_location=home_location)
            citizen.save()

            context['citizen'] = citizen

            return redirect(home)

    else:
        citizen_form = CitizenForm() # An unbound form
        location_form = LocationForm()

    context['citizen_form'] = citizen_form
    context['location_form'] = location_form
    return render_to_response('registration/create_user.html', context, context_instance=RequestContext(request))
def location_new(request):
    from forms import LocationForm
    initial = {}
    if request.method == 'POST':
        form = LocationForm(request.POST, initial=initial)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/systems/locations/')
    else:
        form = LocationForm(initial=initial)

    return render_to_response(
        'generic_form.html',
        {
            'form': form,
        },
        RequestContext(request))
Beispiel #5
0
def location(request):
    """
    Location selection of the user profile
    """
    profile, created = Profile.objects.get_or_create(user=request.user)

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit_location_done"))
    else:
        form = LocationForm(instance=profile)

    template = "userprofile/profile/location.html"
    data = { 'section': 'location', 'GOOGLE_MAPS_API_KEY': GOOGLE_MAPS_API_KEY,
             'form': form, }
    return render_to_response(template, data, context_instance=RequestContext(request))
def location_edit(request, object_id):
    location = get_object_or_404(models.Location, pk=object_id)
    from forms import LocationForm
    initial = {}
    if request.method == 'POST':
        form = LocationForm(request.POST, instance=location)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/systems/locations/')
    else:
        form = LocationForm(instance=location)

    return render_to_response(
        'generic_form.html',
        {
            'form': form,
        },
        RequestContext(request))
Beispiel #7
0
def editlocation(request, location_id):
    location = get_object_or_404(Location, pk=location_id)

    if request.POST:
        form = LocationForm(request.POST, instance=location)
        if form.is_valid():
            form.save()

            return HttpResponseRedirect('/')

    else:
        form = LocationForm(instance=location)

    return render_to_response("editlocation.html", {
        'form': form,
        'location': location,
    },
                              context_instance=RequestContext(request))
Beispiel #8
0
def loc_create(request):
    '''Model form for creating a new location.'''
    if request.POST:
        form = LocationForm(request.POST, auto_id=True)
        if form.is_valid():
            form.save()
            # The problem w/ duplicate POST submissions is only a problem with traditional requests. With AJAX request can simply render the success page instead of redirecting to it.
            if request.is_ajax():
                return render(request, 'loc_list.html')
            else:
                return redirect('/loc_list/')
    else:
        form = LocationForm(auto_id=True)

    context = {}
    context.update(csrf(request))
    
    context['form'] = form

    return render_to_response('loc_create.html', context)
Beispiel #9
0
def all_locations(request):
    locations = Location.objects.all().order_by('type')

    for i in locations:
        lat, long = i.latlng.split(",")

    if request.POST:
        form = LocationForm(request.POST)
        if form.is_valid():
            form.save()

            return HttpResponseRedirect('/')
    else:
        form = LocationForm()

    location = Location.objects.all()
    title = "Location"
    url = "location"

    return render(request, "locations.html", locals())
Beispiel #10
0
def loc_edit(request, pk):
    '''Model form for editing a location. This location is acquired with a pk.'''
    location= Location.objects.get(pk = pk)
    if request.POST:
        form = LocationForm(request.POST, instance = location)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return render(request, 'loc_list.html')
            else:
                return redirect('/loc_list/')
    else:
        form = LocationForm(instance = location)

    context = {}
    context.update(csrf(request))
    context['form'] = form
    context['location'] = location
    context['pk'] = pk
    
    return render_to_response('loc_edit.html', context)
Beispiel #11
0
def register(request):
    if request.method == 'POST':
        userForm = UserForm(data=request.POST)
        profileForm = UserProfileForm(data=request.POST)
        locationForm = LocationForm(data=request.POST)

        if userForm.is_valid() and profileForm.is_valid() and \
           locationForm.is_valid():
            userObj = userForm.save()
            userObj.set_password(userObj.password)
            userObj.save()

            location = locationForm.save(commit=False)
            location.name = 'Home'
            location.save()

            profileObj = profileForm.save(commit=False)
            profileObj.user = userObj
            profileObj.address = location
            profileObj.save()
            profileObj.locations.add(location)
            profileObj.save()

            userObj = authenticate(username=userObj.username,
                                   password=userObj.password)
            login(request, userObj)

            return render(request, 'socketbox/index.html', {})
        else:
            if not locationForm.is_valid():
                print("Location is bad!")
                print locationForm.errors
            if not userForm.is_valid():
                print("user is bad!")
                print userForm.errors
                print request.POST
            if not profileForm.is_valid():
                print("profile is bad!")
                print profileForm.errors
            return index(request)
    else:
        profileForm = UserProfile()
        locationForm = Location()
        userForm = User()

    contextDict = {'profileForm': profileForm, 'locationForm': locationForm,
                   'userForm': userForm}

    return render(request, "registration/registration_form.html", contextDict)
Beispiel #12
0
def location_add(request):
	"""
	FIXME
	@param request:
	@type request:
	"""
	if request.method == "POST":
		form = LocationForm(request.POST)
		if form.is_valid():
			larp=form.save()
			return HttpResponseRedirect(location.get_absolute_url())
	else:
		form = LocationForm()
	
	return render_to_response('eventCRUD/location_add.html', {
		'form':form, 
		},
		context_instance=RequestContext(request)
	)
Beispiel #13
0
    def post(self, request, *args, **kwargs):
        location = LocationForm(request.POST)
        parking_lot = ParkingLotForm(request.POST)
        if location.is_valid() and parking_lot.is_valid():
            location_instance = location.save()
            parking_lot_instance = parking_lot.save(commit=False)
            parking_lot_instance.location = location_instance
            parking_lot_instance.owner = get_object_or_404(
                Person, user__id=request.user.id)
            parking_lot_instance.save()
            return redirect('estacionamentos')

        forms = {
            u'Localização': location,
            u'Estacionamento': parking_lot,
        }
        messages.add_message(request, messages.ERROR,
                             'Erro ao atualizar informações.')
        return render(request,
                      'website/system/parking_lot/new-parking-lot.html',
                      {'forms': forms})
Beispiel #14
0
def add_edit_item(request, model_name, add_edit, edit_id):
    """Add/Edit page for the inventory"""
    if add_edit == "add":
        edit_id = None
    if _checkModel(model_name):
        directory = "asset_inventory/add_edit_Pages/"
        # Adding or Editing a Job
        if model_name == "Job":
            templateFile = directory + "Job.html"
            post_data = request.POST or None

            try:
                Job_Instance = Job.objects.get(pk=edit_id)
            except Job.DoesNotExist:
                Job_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Job", "add", "new"]))

            Job_Form = JobForm(post_data, instance=Job_Instance)

            if Job_Form.is_valid():
                Job_Occurance = Job_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Job"]))
            return render_to_response(templateFile, {"form": Job_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Location
        elif model_name == "Location":
            templateFile = directory + "Location.html"
            post_data = request.POST or None

            try:
                Location_Instance = Location.objects.get(pk=edit_id)
            except Location.DoesNotExist:
                Location_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(
                        reverse("asset_inventory_add_edit_item", args=["Location", "add", "new"])
                    )

            Location_Form = LocationForm(post_data, instance=Location_Instance)

            if Location_Form.is_valid():
                Location_Occurance = Location_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Location"]))

            return render_to_response(templateFile, {"form": Location_Form}, context_instance=RequestContext(request))

        # Adding or Editing a Person
        elif model_name == "Person":
            templateFile = directory + "Person.html"
            post_data = request.POST or None

            try:
                Person_Instance = Person.objects.get(pk=edit_id)
            except Person.DoesNotExist:
                Person_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Person", "add", "new"]))

            Person_Form = PersonForm(post_data, instance=Person_Instance)

            if Person_Form.is_valid():
                Person_Occurance = Person_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Person"]))

            return render_to_response(templateFile, {"form": Person_Form}, context_instance=RequestContext(request))

        # Adding or Editing a Purchase
        elif model_name == "Purchase":
            templateFile = directory + "Purchase.html"
            post_data = request.POST or None

            try:
                Purchase_Instance = Purchase.objects.get(pk=edit_id)
            except Purchase.DoesNotExist:
                Purchase_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(
                        reverse("asset_inventory_add_edit_item", args=["Purchase", "add", "new"])
                    )

            Purchase_Form = PurchaseForm(post_data, instance=Purchase_Instance)

            if Purchase_Form.is_valid():
                Purchase_Occurance = Purchase_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Purchase"]))

            return render_to_response(templateFile, {"form": Purchase_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Status
        elif model_name == "Status":
            templateFile = directory + "Status.html"
            post_data = request.POST or None

            try:
                Status_Instance = Status.objects.get(pk=edit_id)
            except Status.DoesNotExist:
                Status_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Status", "add", "new"]))

            Status_Form = StatusForm(post_data, instance=Status_Instance)

            if Status_Form.is_valid():
                Status_Occurance = Status_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Status"]))

            return render_to_response(templateFile, {"form": Status_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Esign
        elif model_name == "Esign":
            templateFile = directory + "Esign.html"
            post_data = request.POST or None

            try:
                Esign_Instance = Esign.objects.get(pk=edit_id)
            except Esign.DoesNotExist:
                Esign_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Esign", "add", "new"]))

            Esign_Form = EsignForm(post_data, instance=Esign_Instance)

            if Esign_Form.is_valid():
                Esign_Occurance = Esign_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Esign"]))

            return render_to_response(templateFile, {"form": Esign_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Device
        elif model_name == "Device":
            templateFile = directory + "Device.html"
            post_data = request.POST or None

            try:
                Device_Instance = Device.objects.get(pk=edit_id)
            except Device.DoesNotExist:
                Device_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Device", "add", "new"]))

            Device_Form = DeviceForm(post_data, instance=Device_Instance)

            if Device_Form.is_valid():
                Device_Occurance = Device_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Device"]))

            return render_to_response(templateFile, {"form": Device_Form}, context_instance=RequestContext(request))
    # This is a catch all response, if some unforseen error manages
    # to occur with the calling of add/edit pages
    else:
        render_to_response(reverse("homepage"))
Beispiel #15
0
def create_Activity(request):
	if request.is_ajax():
		search_term = request.POST['yelp_term']
		# lat = request.session['cur_lat']
		# lng = request.session['cur_lng']
		lat = '42.056459'
		lng = '-87.675267'
		search_result = yelp_api.search_location(lat,lng,search_term)
		request.session['search_result'] = search_result
		return HttpResponse(json.dumps(search_result), content_type="application/json")

	elif request.method == 'POST':
		actForm = ActivityForm(request.POST)
		locForm = LocationForm(request.POST)

		# check for valid location
		if locForm.is_valid():
			street = request.POST.get('address')
			city = request.POST.get('city')
			state = request.POST.get('state')

			# get lat and long
			addr_str = street + ", " + city + ", " + state
			r = geocode(addr_str)
			lat = r['lat']
			lng = r['lng']

			m = locForm.save(commit=False)
			m.longitude = lng
			m.latitude = lat
			loc_name = m.location_name
			
			# get yelp rating and image
			rating,img_url = yelp_api.get_yelp_data(loc_name,lng,lat)
			print rating
			if rating == -1:
				m.location_rate = 0.0
			else:
				m.location_rate = rating
			if img_url == -1:
				m.location_img_url = "http://www.mountainmansocialmedia.com/_site/wp-content/themes/juiced/img/thumbnail-default.jpg"
			else:
				m.location_img_url = img_url
			
			location_obj = locForm.save()
			
			date = request.POST.get('date')
			start_time = request.POST.get('start_time')
			end_time = request.POST.get('end_time')
			name = request.POST.get('activity_name')
			max_num = request.POST.get('max_num_attendees')
			min_num = request.POST.get('min_num_attendees')
			skill = request.POST.get('skill_level')

			dt = datetime.strptime(date, "%m/%d/%Y")
			st = datetime.strptime(convert_Time(start_time), "%H:%M:%S")
			et = datetime.strptime(convert_Time(end_time), "%H:%M:%S")
			owner = request.user.onthemoveuser

			request.GET = request.GET.copy()
			request.GET['date'] = dt
			request.GET['start_time'] = st 
			request.GET['end_time'] = et 
			request.GET['activity_name'] = name
			request.GET['max_num_attendees'] = max_num
			request.GET['min_num_attendees'] = min_num
			request.GET['skill_level'] = skill
			request.GET['location_id'] = location_obj
			request.GET['owner_id'] = owner

			actForm1 = ActivityForm(request.GET)

			if actForm1.is_valid():
				x=actForm1.save(commit=False)
				x.location_id = location_obj
				x.owner_id = owner
				y = actForm1.save()
				print "here"
				return HttpResponseRedirect(reverse("Activities:details",args=(y.pk,)))
	else:
		actForm = ActivityForm()
		locForm = LocationForm()
	context = {}
	context.update(csrf(request))
	context['act_form'] = actForm
	context['loc_form'] = locForm
	context['path'] = request.path

	return render(request,"Activities/createActivity.html", context)