Ejemplo n.º 1
0
def new_location(request, provider_id):
    provider = get_object_or_404(Provider, id=provider_id)
    admin_user = provider.admin
    if request.user == admin_user: # only the provider's registered user
        if request.method == "POST":
            location_form = LocationForm(request.POST)
            if location_form.is_valid():
                location = location_form.save(commit=False)
                location.provider = provider
                location.save()
                data = {
                    'location_id': location.id,
                }
                return HttpResponse(simplejson.dumps(data), content_type="application/json")
            else:
                errors_dict = {}
                if location_form.errors:
                    for error in location_form.errors:
                        e = location_form.errors[error]
                        errors_dict[error] = unicode(e)

                return HttpResponseBadRequest(simplejson.dumps(errors_dict))

        else:
            template = 'location/new.html'
            data = {
                'location_form': LocationForm(),
                'provider_id': provider.id,

            }
            return render(request, template, data)
    else:
        return HttpResponseRedirect(reverse('provider_detail', kwargs={'provider_id': provider.id}))
Ejemplo n.º 2
0
def edit_location(request, location_id):
    location = get_object_or_404(Location, id=location_id)
    provider = location.provider
    admin_user = provider.admin
    if request.user == admin_user: # only the provider's registered user
        if request.method == "POST":
            location_form = LocationForm(request.POST,instance=location)
            if location_form.is_valid():
                location = location_form.save()
                template = 'location/profile.html'
                return HttpResponse('OK')
            else:
                errors_dict = {}
                if location_form.errors:
                    for error in location_form.errors:
                        e = location_form.errors[error]
                        errors_dict[error] = unicode(e)

                return HttpResponseBadRequest(simplejson.dumps(errors_dict))
        else:
            template = 'location/edit.html'
            data = {
                        'location_form': LocationForm(instance=location),
                        'location_id': location.id,
                    }
            return render(request, template, data)
    else:
        return HttpResponseRedirect(reverse('provider_detail', kwargs={'provider_id': provider.id}))
Ejemplo n.º 3
0
def edit_provider(request, provider_id):

	provider = get_object_or_404(Provider, id=provider_id)
	admin_user = provider.admin

	#TEMPORARY
	location = Location.objects.filter(provider__pk = provider_id)[0]

	if request.user == admin_user: # only the provider's registered user can edit page

		if request.method == 'POST':
			provider_form = ProviderForm(request.POST,instance=provider)
			location_form = LocationForm(request.POST,instance=location)

			if provider_form.is_valid() and location_form.is_valid():
				provider = provider_form.save(commit=False)
				provider.admin = admin_user
				provider.save()
				location = location_form.save(commit=False)
				location.provider = provider
				location.save()
				location_form.save_m2m()
				return HttpResponseRedirect(reverse('provider_detail', kwargs={'provider_id': provider.id}))

		else:
			provider_form = ProviderForm(instance=provider)
			location_form = LocationForm(instance=location) #todo: turn into formsets--right now this is creating a new loca

		return render(request, "provider/edit.html", { 
												'provider_form': provider_form, 
												'location_form': location_form
												 })

	else:
		return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 4
0
def add_provider(request):
	if request.method == "POST":
		admin_form = UserCreationForm(request.POST)
		provider_form = ProviderForm(request.POST)
		location_form = LocationForm(request.POST)

		if admin_form.is_valid() and provider_form.is_valid() and location_form.is_valid():
			admin = admin_form.save()
			provider = provider_form.save(commit=False)
			provider.admin = admin
			provider.save()
			location = location_form.save(commit=False)
			location.provider = provider
			location.save()
			location_form.save_m2m()
			return HttpResponseRedirect(reverse('provider_detail', kwargs={'provider_id': provider.id}))

	else:
		admin_form = UserCreationForm()
		provider_form = ProviderForm()
		location_form = LocationForm()

	return render(request, "provider/new.html", { 
												'provider_form': provider_form, 
												'location_form': location_form,
												'admin_form': admin_form,
												 })
Ejemplo n.º 5
0
def home(request):
    """Renders the home page."""
    assert isinstance(request, HttpRequest)
    form = LocationForm(request.POST or None)
    userInfo = getUserInfo(user=request.user)
    newsfeed = Newsfeed(userInfo)
    if (request.method == 'POST' and form.is_valid()):
        location = getLocationFromString(form.cleaned_data['location'])
        try:
            form.fields['location'].initial = '{0}, {1}, {2}'.format(
                location['city'], location['state'], location['country'])
            request.session['location'] = location
            newsfeed.nextPage()
        except KeyError:
            form.fields['location'].initial = ''
    elif ('location' in request.session):
        try:
            location = request.session['location']
            form.fields['location'].initial = '{0}, {1}, {2}'.format(
                location['city'], location['state'], location['country'])
            newsfeed.nextPage()
        except KeyError:
            form.fields['location'].initial = ''
    return render(
        request, 'app/index.html', {
            'title': 'Go Out',
            'year': datetime.now().year,
            'form': form,
            'newsfeed': newsfeed.articles
        })
Ejemplo n.º 6
0
def location(request):
    """Handles location update"""
    assert isinstance(request, HttpRequest)
    form = LocationForm(request.POST or None)
    if (request.method == 'POST' and form.is_valid()):
        location = getLocationFromString(form.cleaned_data['location'])
        request.session['location'] = location
    next = request.POST.get('next', '/')
    return HttpResponseRedirect(next)
Ejemplo n.º 7
0
def delete_location(request):
    response = reply_object()
    form = LocationForm(request.POST)
    if form.is_valid():
        response = form.delete_campaign_location()
    else:
        response["code"] = settings.APP_CODE["FORM ERROR"]
        response["errors"] = form.errors
    return HttpResponse(simplejson.dumps(response))