Пример #1
0
def location():
    form = LocationForm()
    location_data = db.session.query(Location)
    location_data = [str(row).split('|') for row in location_data]

    if form.validate_on_submit():
        location = Location(location_name=form.location_name.data,\
                            city=form.city.data,\
                            lat_long=form.lat_long.data,\
                            address=form.address.data)

        try:
            obj = db.session.query(Location).filter(
                Location.location_name == form.location_name.data).first()
            if obj == None:
                db.session.add(location)
                db.session.commit()
                flash('Your location data has been saved successfully!')
            else:
                obj.update({"city" : form.city.data,\
                                     "lat_long" : form.lat_long.data,\
                                     "address" : form.address.data})
                db.session.commit()

            return redirect(url_for('location'))
        except IntegrityError as e:
            flash('Integrity error')

    return render_template('location.html', form=form, location_data=location_data,\
                            is_authenticated=current_user.is_authenticated)
Пример #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}))
Пример #3
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
        })
Пример #4
0
def fill_db():
    form = LocationForm()
    print(form.user_id.data)

    if form.validate_on_submit():
        location = Location(lat=form.lat.data,
                            lan=form.lan.data,
                            timestamp=form.timestamp.data,
                            user_id=form.user_id.data)
        session.add(location)
        session.flush()
        return redirect("/")
    # if request.method == 'POST':
    #     lat = request.form['lat']
    #     lan = request.form['lan']
    #     timestamp = request.form['timestamp']
    #     user_id = request.form['user_id']
    #     print(timestamp)
    #     ts = datetime.strptime(timestamp, "%Y-%m-%d")
    #     location = Location(lat, lan, ts, user_id)
    #     session.add(location)
    #     session.flush()
    #     return redirect("/")
    else:
        users = session.query(User).all()
        return render_template('add_location.html', users=users, form=form)
Пример #5
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}))
def home():
    form = LocationForm(request.form)
    if request.method == 'POST' and form.validate():
        location = Location()
        form.populate_obj(location)
        db.session.add(location)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('welcome.html', form=form)
Пример #7
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)
Пример #8
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))
Пример #9
0
def index():

    form = LocationForm()
    data = []
    if form.validate_on_submit():
        print("success")
        url = "https://www.pythonprogramming.in/media/wysiwyg/matplotlib/mat-7.png"
        data.append(url)
        print(data)

    return render_template('index.html', title='Teacher Home', form=form)
Пример #10
0
def location_create():

    form = LocationForm()
    if form.validate_on_submit():
        db.session.add(Location(name=form.name.data, address=form.address.data))
        db.session.commit()
        flash("Successfully created Location: {}".format(form.name.data), 'info')
        app.logger.info('Location {} created by Admin ID {} at {}'.format(form.name.data, current_user.id, datetime.now()))
        return redirect(url_for('admin_panel.alldata_stype', sub_type='locations'))
    
    return render_template('/location_create.html', form=form) if validation(current_user)==True else redirect(url_for('main_panel.index'))
Пример #11
0
def fill_db():
    form = LocationForm()
    print(form.user_id.data)

    if form.validate_on_submit():
        location = Location(lat=form.lat.data, lan=form.lan.data, timestamp=form.timestamp.data, user_id=form.user_id.data)
        session.add(location)
        session.flush()
        return redirect("/")
    else:
        users = session.query(User).all()
        return render_template("add_location.html", users=users, form=form)
Пример #12
0
def location():
    form = LocationForm()
    if form.validate_on_submit():
        location = Location(id_location=form.id_location.data, continent=form.continent.data, country=form.country.data, province=form.province.data, city=form.city.data)
        
        #save the model to the database
        db.session.add(location)
        db.session.commit()
        
        flash('Congratulations, you are now a registered location!')
        return redirect(url_for('index'))
    return render_template('location.html', title='validate', form=form)
Пример #13
0
def create_location():
    """Creates a location for a drop list item"""
    form = LocationForm()

    if form.validate_on_submit():
        location = Location(name=form.name.data)
        db.session.add(location)
        db.session.commit()
        flash("Location has been successfully created", "success")
        return redirect(f"/locations/{location.id}")

    return render_template("locations_new.html", form=form)
Пример #14
0
def edit_location(location_id):
    """edit a location"""
    location = Location.query.get_or_404(location_id)

    form = LocationForm(obj=location)

    if form.validate_on_submit():
        location.name = form.name.data

        db.session.commit()

        flash("Location successfully updated", "success")
        return redirect(f"/locations/{location.id}")

    return render_template("/locations_edit.html", form=form)
Пример #15
0
def edit_provider(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 can edit page

        if request.method == 'POST':
            password_change_form = PasswordChangeForm(request.POST)
            provider_form = ProviderForm(request.POST, instance=provider)
            location_formset = LocationForm(request.POST, request.FILES)

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

        else:
            password_change_form = PasswordChangeForm(user=admin_user)
            provider_form = ProviderForm(instance=provider)
            location_formset = LocationFormset(
                queryset=Location.objects.filter(provider__pk=provider_id))

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

    else:
        return HttpResponseRedirect(reverse('index'))
Пример #16
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'))
Пример #17
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,
												 })
Пример #18
0
def edit(location_id=None):
    """FRONTEND, Create, view or edit a location."""
    if not ModuleAPI.can_write('location'):
        return abort(403)

    # Select location..
    if location_id:
        location = Location.query.get(location_id)
    else:
        location = Location()

    form = LocationForm(request.form, location)

    if form.validate_on_submit():
        form.populate_obj(location)
        db.session.add(location)
        db.session.commit()
        flash(_('Location saved.'), 'success')
        return redirect(url_for('location.edit', location_id=location.id))
    else:
        flash_form_errors(form)
    return render_template('location/edit.htm', location=location, form=form)
Пример #19
0
def edit_provider(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 can edit page

		if request.method == 'POST':
			password_change_form = PasswordChangeForm(request.POST)
			provider_form = ProviderForm(request.POST,instance=provider)
			location_formset = LocationForm(request.POST,request.FILES)

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

		else:
			password_change_form = PasswordChangeForm(user=admin_user)
			provider_form = ProviderForm(instance=provider)
			location_formset = LocationFormset(queryset=Location.objects.filter(provider__pk = provider_id))

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

	else:
		return HttpResponseRedirect(reverse('index'))
Пример #20
0
def location_field(request):
    locationForm = LocationForm()
    return {'FORM_LOCATION': locationForm}
Пример #21
0
def edit_provider(request, provider_id):

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

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

        if request.is_ajax():
            if request.method == 'POST': #and request.is_ajax():
                provider_form = ProviderForm(request.POST,instance=provider)
                if provider_form.is_valid():
                    provider = provider_form.save()
                    template = 'provider/provider_profile.html'
                    data = {
                        'provider_id': provider.id,
                    }
                    return HttpResponse(simplejson.dumps(data), content_type="application/json")
                else:
                    errors_dict = {}
                    if provider_form.errors:
                        for error in provider_form.errors:
                            e = provider_form.errors[error]
                            errors_dict[error] = unicode(e)

                    return HttpResponseBadRequest(simplejson.dumps(errors_dict))
            else:
                    template = 'provider/provider_edit.html'
                    data = {
                        'provider_form': ProviderForm(instance=provider),
                        'provider_id': provider.id,
                    }
            return render(request, template, data)

        else:
            if request.method == 'POST':
                provider_form = ProviderForm(request.POST,instance=provider)
                password_change_form = PasswordChangeForm(request.POST)
                location_formset = LocationForm(request.POST,request.FILES)

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

            else:
                password_change_form = PasswordChangeForm(user=admin_user)
                provider_form = ProviderForm(instance=provider)
                location_formset = LocationFormset(queryset=Location.objects.filter(provider__pk = provider_id))

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

    else:
        return HttpResponseRedirect(reverse('provider_detail', kwargs={'provider_id': provider.id}))
Пример #22
0
def index():
    """Main page"""
    form = LocationForm()
    return render_template('index.html', form=form)