예제 #1
0
def get_point(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = PointForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            return HttpResponseRedirect('/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = PointForm()

    return render(request, 'point_form.html', {'form': form})
예제 #2
0
def add_point(request):
    """
            Get the form to add a point 
    """
    data = {'success': False}
    rendered = None
    form = PointForm(request.POST or None,
                     request.FILES if request.POST else None)
    if request.method == 'POST':
        point = form.save(commit=False)
        point.user = request.user
        point.save()
        photoForm = PhotoForm(request.POST,  request.FILES) 
        photo = photoForm.save(commit=False)
        photo.point = point
        photo.save()
    else:
        rendered = render_to_string('points/add_point_form.html', {'form': form},RequestContext(request))
    data = { 'success': True, 'html': rendered }

    return HttpResponse(simplejson.dumps(data))
예제 #3
0
def add_point(request):
    """
            Get the form to add a point 
    """
    data = {'success': False}
    rendered = None
    form = PointForm(request.POST or None,
                     request.FILES if request.POST else None)
    if request.method == 'POST':
        point = form.save(commit=False)
        point.user = request.user
        point.save()
        photoForm = PhotoForm(request.POST, request.FILES)
        photo = photoForm.save(commit=False)
        photo.point = point
        photo.save()
    else:
        rendered = render_to_string('points/add_point_form.html',
                                    {'form': form}, RequestContext(request))
    data = {'success': True, 'html': rendered}

    return HttpResponse(simplejson.dumps(data))
예제 #4
0
def createPoint(request):

	mapId = settings.MAP_ID
	apiKey = settings.API_KEY
	mapNearZoom = settings.MAP_NEAR_ZOOM

	#logger.info("Pepeando")

	try:
		extra = UserExtra.objects.get(user=request.user)
	except:
		extra = None

	# If the form has been submitted...

	if request.method == 'POST':

		# A form bound to the POST data

		form = PointForm(request.POST, request.FILES,user=request.user)

		# All validation rules pass

		if form.is_valid():
			valores = {}
			valores['lat'] = form.cleaned_data['lat']
			valores['long'] = form.cleaned_data['long']
			valores['texto'] = form.cleaned_data['texto']
			valores['signal'] = form.cleaned_data['signal']

			# Aqui inserto

			newPoint = DataPoint()

			newPoint.lat = form.cleaned_data['lat']
			newPoint.long = form.cleaned_data['long']
			newPoint.auxText = form.cleaned_data['texto']
			newPoint.user = request.user
			newPoint.signal = form.cleaned_data['signal']
			newPoint.pointTags = form.cleaned_data['pointTags']

			#if request.FILES.get('fileUrl',default=None) is not None:
			if 'imageUrl' in request.FILES:
				newPoint.imageUrl = request.FILES['imageUrl']

			# Actualizo los contadores y karma de usuario y señal

			# Karma del usuario

			if extra != None:
				extra.karmaCounter += KARMA_PER_INPUT

				# Karma de la señal, de momento lo incremento con el TOTAL del karmaCounter del usuario

				newPoint.signal.karmaCounter += signalKarmaFromUser(extra.karmaCounter)

				extra.save()

			# numero de puntos de la señal

			newPoint.signal.numPoints += 1
			newPoint.signal.numPointsNow += 1

			# Guardo la señal y el punto...

			newPoint.signal.save()

			newPoint.save()

			# inserto el punto en el solr

			solrutils.index_point(newPoint.id,newPoint.signal.id,newPoint.signal.name,newPoint.user.username,newPoint.auxText,datetime.datetime.now(),newPoint.lat,newPoint.long,newPoint.pointTags)

		return render_to_response("thanksPoint.html",locals(),context_instance=RequestContext(request))
	else:
		form = PointForm(user=request.user) # An unbound form

	return render_to_response("createPoint.html", locals(),context_instance=RequestContext(request))
예제 #5
0
def point_edit(request, point_id=None):
    #start_acl = None
    if point_id is not None:
        point = get_object_or_404(Point, id=point_id)
        title = u'Редактирование точки'
        #start_acl = point.state
    else:
        point = None
        title = u'Новая точка'
    if point is not None and not point.location.admins.filter(id=request.user.id).count():
        return HttpResponseNotFound()

    messages = []
    #trans_forms = []
    if request.method == "POST":
        form = PointForm(request.POST, request.FILES,  instance=point)
        #for lang_code, lang_name in settings.LANGUAGES:
        #    if lang_code != settings.LANGUAGE_CODE:
        #        if point is not None:
        #            trans, c = Translation.objects.get_or_create(point=point, language=lang_code)
        #        else:
        #            trans = None
        #        trans_forms.append(TransForm(request.POST, instance=trans, prefix=lang_code))
        if form.is_valid(): # and all([i.is_valid() for i in trans_forms]):
            _point =  form.save()
            #for i in trans_forms:
            #    t = i.save()
            #    if not t.language:
            #        t.language = i.prefix
            #    if t.point is None:
            #        t.point = _point
            #    t.save()
            for f in request.FILES.getlist('photos',[]):
                ph = Photo.objects.get_or_create(point=_point, image=f)
            messages.append(u"Изменения успешно сохранены.")
            if request.POST.get('submit', 'to_current_page') == 'to_section':
                return HttpResponseRedirect(reverse('manager_points'))
            if point is None:
                return HttpResponseRedirect(reverse('point-edit', 
                                                    args=[form.instance.id]))
    else:
        form = PointForm(instance=point)
        #for lang_code, lang_name in settings.LANGUAGES:
        #    if lang_code != settings.LANGUAGE_CODE:
        #        if point is not None:
        #            trans, c = Translation.objects.get_or_create(point=point, language=lang_code)
        #        else:
        #            trans = None
        #        trans_forms.append(TransForm(instance=trans, prefix=lang_code))
    mod_notifi = None
    if point is not None and point.message_set.filter(state='m').count():
        mod_notifi = point.message_set.filter(state='m')[0]
    
    return render_to_response('obj_edit.html',
                              {'form': form,
                               #'trans_forms': trans_forms,
                               'comments_instance': point,
                               'title': title,
                               'back_url': reverse('manager_points'),
                               'info': {'messages': messages},
                               #'mod_notifi': mod_notifi
                               },                              
                              RequestContext(request))