Esempio n. 1
0
 def test_complaint_contains_without_image(self):
     form = Complaint(
         subject="hi all,",
         message="yippie",
         uploaded_at=timezone.now(),
     )
     self.assertFalse(form.save())
Esempio n. 2
0
 def test_complaint_contains_wrong_subject_data(self):
     form = Complaint(
         subject="",
         message="yippie",
         uploaded_at=timezone.now(),
         image=None,
     )
     self.assertFalse(form.save())
Esempio n. 3
0
    def test_complaint_contains_correct_info(self):
        test_complaint_1 = Complaint(
            subject="I hate math",
            message="I hate math",
            uploaded_at=timezone.now(),
            image=None,
        )
        test_complaint_1.save()

        response = self.client.get(reverse("issue-complaint"))
        self.assertEqual(response.status_code, 200)
Esempio n. 4
0
def post(request):
    if not request.user.is_authenticated:
        return redirect('/users_student/login/')

    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        print(user.username)
        title = request.POST.get('title')
        des = request.POST.get('description')
        tags = request.POST.get('tags')
        image = request.FILES['image']
        fs = FileSystemStorage()
        filename = fs.save(image.name, image)
        url = fs.url(filename)
        print(user.username)
        print(url)
        student_img = student.objects.filter(user=request.user)
        complain = Complaint(user=user,
                             title=title,
                             description=des,
                             tags=tags,
                             image=url,
                             url=student_img[0].profile_picture)
        complain.save()
        student_obj = student.objects.get(user=user)
        ids = student_obj.post_ids
        ids = ids.split(",")
        ids.append(str(complain.id))
        if "" in ids:
            ids.remove("")
        student_obj.post_ids = ",".join(ids)
        student_obj.save()
        return redirect("/users_student/profile/")
    else:
        level = request.GET.get('level')
        student_img = student.objects.filter(user=request.user)
        # print(student_img)
        print(
            "---------------------------------------------------------------------"
        )
        print(student_img[0].profile_picture)
        for i in student_img:
            print(i.profile_picture)
        if level is None or level == "":
            level = "department"
        userdata = student.objects.get(user=request.user)
        print(userdata)
        return render(request, 'complaint/add_complaint.html', {
            'level': level,
            'userdata': userdata
        })
Esempio n. 5
0
    def test_complaint_contains_correct_info(self):
        reservation_post = create_reservation_post()
        issuer = reservation_post.helpseeker
        receiver = reservation_post.donor
        test_complaint_1 = Complaint(
            subject="I hate math",
            message="I hate math",
            uploaded_at=timezone.now(),
            image=None,
            issuer=issuer,
            receiver=receiver,
            reservation_post=reservation_post,
        )
        test_complaint_1.save()

        self.assertEquals(
            str(test_complaint_1.issuer.username) + " to " +
            str(test_complaint_1.receiver.username) + " about " +
            str(test_complaint_1.reservation_post.__str__()),
            test_complaint_1.__str__(),
        )
Esempio n. 6
0
    def getComplaintStats(self, complaints):
        stats_complaint = {}
        status_parser = dict(Complaint().COMPLAINT_STATUS)

        for key, value in status_parser.items():
            stats_complaint[value] = 0

        for complaint in list(complaints):
            temp_status = status_parser.get(complaint.status)
            stats_complaint[temp_status] += 1

        return stats_complaint
Esempio n. 7
0
def create():
    #instancia formulario
    form = BasicComplaintForm()
    error = None
    #validar formulario y post request
    if request.method == 'POST' and form.validate():
        error = form.errors
        print(error)
        if not error:
            #si el usuario tiene sesion activa
            user = User.objects.filter(email=session.get('email')).first()
            #almacenar en bd
            complaint = Complaint(name=form.name.data,
                                  place=form.place.data,
                                  location=[form.lng.data, form.lat.data],
                                  description=form.description.data,
                                  complainer=user.id,
                                  follow=[user])
            complaint.save()
            return redirect(url_for('complaint_page.edit', id=complaint.id))
    return render_template('complaint/create.html', form=form)
Esempio n. 8
0
 def test_complaint_contains_without_subject_message_data(self):
     form = Complaint(
         uploaded_at=timezone.now(),
         image=None,
     )
     form.reservation_post = create_reservation_post()
     form.issuer = form.reservation_post.helpseeker
     form.receiver = form.reservation_post.donor
     self.assertFalse(form.save())
Esempio n. 9
0
 def test_complaint_contains_without_image(self):
     form = Complaint(
         subject="hi all,",
         message="yippie",
         uploaded_at=timezone.now(),
     )
     form.reservation_post = create_reservation_post()
     form.issuer = form.reservation_post.helpseeker
     form.receiver = form.reservation_post.donor
     self.assertFalse(form.save())
Esempio n. 10
0
def explore(complaint_page_number=1):
    place = request.args.get('place')
    try:
        lng = float(request.args.get('lng'))
        lat = float(request.args.get('lat'))
        complaints = Complaint.objects(location__near=[lng, lat],
                                       location__max_distance=100000,
                                       cancel=False).paginate(
                                           page=complaint_page_number,
                                           per_page=4)
        return render_template('complaint/explore.html',
                               complaints=complaints,
                               place=place,
                               lng=lng,
                               lat=lat)
    except:
        return render_template('complaint/explore.html', place=place)
Esempio n. 11
0
def new_complaint(request):
    geolocator = GoogleV3()
    fellows = []
    time = datetime.time(datetime.now())
    date = datetime.date(datetime.now())
    if request.method == 'POST' and request.is_ajax:
    	complaint = ComplaintForm(request.POST)
    	if complaint.is_valid():
    	    situation = complaint.cleaned_data['situation']
    	    neighborhood = complaint.cleaned_data['neighborhood']
    	    apt_number = complaint.cleaned_data['apt_number']
    	    street_address = complaint.cleaned_data['street_address']
    	    new_complaint = Complaint(situation=situation, neighborhood=neighborhood, street_address=street_address, date=date, time=time)
    	    if request.user.is_authenticated:
                new_complaint.owner = request.user
            if apt_number:
            	new_complaint.apt_number = apt_number
            	apts = Complaint.objects.filter(street_address=street_address).filter(apt_number=apt_number)
    	        numbers = [apt.apt_number for apt in apts]
    	        if apt_number in numbers:
    	        	new_complaint.others = True
    	    	if new_complaint.others:
    	    		for a in apts:
    	    			if a.owner not in fellows:
    	        			fellows.append(a.owner)	
    	    for fellow in fellows:
    	    	new_msg = Message(sent_from=request.user, send_to=fellow, subject="another complaint about %s" % new_complaint.street_address, message="you are not alone! Others have also complained about %s. Reply to this message so you guys can figure out what to do about it." % new_complaint.street_address)
    	    new_complaint.save()
    	    new_msg.complaint = new_complaint
    	    new_msg.save()
    	    data = json.dumps({"situation": situation, "neighborhood": neighborhood, "time": str(new_complaint.time)})
    	    if new_complaint.street_address:
    	    	nycaddress = new_complaint.street_address + " NYC"
    	    	geoAddress = nycaddress, (latitude, longitude) = geolocator.geocode(nycaddress)
                way = WayPoint(complaint=new_complaint)
                way.geometry = 'POINT(%s %s)' % (latitude, longitude)
                way.save()
                return HttpResponse(data, content_type='application/json')  
	return HttpResponse("...")
Esempio n. 12
0
 def test_complaint_contains_without_subject_message_data(self):
     form = Complaint(
         uploaded_at=timezone.now(),
         image=None,
     )
     self.assertFalse(form.save())
Esempio n. 13
0
 def test_complaint_contains_no_data(self):
     form = Complaint()
     self.assertFalse(form.save())
Esempio n. 14
0
def create_complaint(title, description, phone, email, category, locality, photo, username):
    try:
        c = Complaint.objects.get(title__exact=title)
    except Complaint.DoesNotExist:        
        try:
            location = Location.objects.get(name__exact=locality)
            category = Category.objects.get(name__exact=category)
            u = User.objects.get(username__exact=username)        
            
            c = Complaint(user=u)
            c.title = title
            c.information = description
            c.category = category
            c.locality = location
            c.address = ""
            c.date_entered = timezone.now()
            c.photo = photo
            c.email = email        
            
            c.save()
            
        except Location.DoesNotExist:
            print "error"
Esempio n. 15
0
 def test_complaint_contains_no_data(self):
     form = Complaint()
     form.reservation_post = create_reservation_post()
     form.issuer = form.reservation_post.helpseeker
     form.receiver = form.reservation_post.donor
     self.assertFalse(form.save())
def post(request):
    if not request.user.is_authenticated:
        return redirect('/users_student/login/')

    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        # print(user.username)
        level = request.POST.get('level')
        cats = request.POST.get('category')
        print("-----------imp--------------------")
        print(level)
        print(cats)
        print("-----------imp--------------------")
        title = request.POST.get('title')
        des = request.POST.get('description')
        tags = request.POST.get('all_emails')
        print(tags)
        list_tags = tags.split(",")
        if not student.objects.filter(user=request.user):
            return redirect('/login')
        student_img = student.objects.get(user=request.user)
        complain = Complaint(student=student_img, title=title, description=des, tags=tags,  # image=url,
                             url=student_img.profile_picture, level=level, sub_cat=cats)
        complain.save()
        list_tags = tags.split(",")
        if "" in list_tags:
            list_tags.remove("")
        for tag in list_tags:
            if User.objects.filter(email=tag).exists():
                temp_user =  User.objects.get(email=tag)
                if student.objects.filter(user=temp_user).exists():
                    temp_obj = student.objects.get(user=temp_user)
                    all_user_tags =  temp_obj.requested_tag
                    all_user_tags = all_user_tags.split(",")
                    all_user_tags.append(str(complain.id))
                    temp_obj.requested_tag = ",".join(all_user_tags)
                    temp_obj.save()
        student_obj = student.objects.get(user=user)
        ids = student_obj.post_ids
        ids = ids.split(",")
        ids.append(str(complain.id))
        if "" in ids:
            ids.remove("")
        student_obj.post_ids = ",".join(ids)
        student_obj.save()
        return redirect("/users_student/profile/")
    else:
        level = request.GET.get('level')
        student_img = student.objects.filter(user=request.user)
        # print(student_img)
        print("---------------------------------------------------------------------")
        # print(student_img.profile_picture)
        for i in student_img:
            print(i.profile_picture)
        if level is None or level == "":
            level = "department"
        category = cat.objects.all()
        if not student.objects.filter(user=request.user):
            return redirect('/login')
        userdata = student.objects.get(user=request.user)
        print(userdata)
        return render(request, 'complaint/add_complaint.html', {'level': level, 'userdata': userdata, 'cats': category})
Esempio n. 17
0
			noise = True
		elif situation == 'Loud Music/Party':
			noise = True
		elif situation == 'Loud Talking':
			noise = True
		elif situation == 'Loud Television':
			noise = True
		else:
			noise = False
		os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'effyouneighbor.settings')
		from complaint.models import Complaint, WayPoint
		from django.contrib.auth.models import User
		user = User.objects.get(username="******")
		#put these complaints under the admin account
		#create new complaint in database
		new_complaint = Complaint(name="Christina", owner=user, noise=noise, time=time, date=date, situation=situation, street_address=geoAddress, location_type=location_type, from_311=True)
		new_complaint.save()
		#create new waypoint for map
		point = WayPoint(complaint=new_complaint, geometry=geometry).save()