• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / team4-wed-spring25 / 159

12 Mar 2025 03:05PM UTC coverage: 88.835%. Remained the same
159

cron

travis-pro

web-flow
Merge pull request #129 from gcivil-nyu-org/develop

Develop

71 of 75 new or added lines in 10 files covered. (94.67%)

10 existing lines in 2 files now uncovered.

183 of 206 relevant lines covered (88.83%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.38
/parks/views.py
1
from django.shortcuts import render, get_object_or_404, redirect
1✔
2
from django.http import HttpResponse  # noqa: F401  # Ignore "imported but unused"
1✔
3
from .models import DogRun
1✔
4
import os
1✔
5
from django.conf import settings
1✔
6

7
import folium
1✔
8
import json
1✔
9

10

11
def park_list(request):
1✔
12
    parks = DogRun.objects.all()  # Fetch all dog runs from the database
1✔
13
    return render(request, "parks/park_list.html", {"parks": parks})
1✔
14

15

16
def map(request):
1✔
17

18
    NYC_LAT_AND_LONG = (40.730610, -73.935242)
1✔
19
    # Create map centered on NYC
20
    m = folium.Map(location=NYC_LAT_AND_LONG, zoom_start=11)
1✔
21

22
    # Currently, this data is not in DB.
23
    # just saved in file, so we hardcode to import it here
24
    coordinates = os.path.join(settings.BASE_DIR, "coordinates.json")
1✔
25
    with open(coordinates, "r") as file:
1✔
26
        coor_dict = json.load(file)
1✔
27

28
    # Fetch all dog runs from the database
29
    parks = DogRun.objects.all()
1✔
30

31
    # Mark every park on the map
32
    for park in parks:
1✔
33
        park_name = park.name
×
34
        coordinates = coor_dict[park_name]
×
35

36
        folium.Marker(
×
37
            location=coordinates,
38
            popup=park_name,
39
        ).add_to(m)
40

41
    # represent map as html
42
    context = {"map": m._repr_html_()}
1✔
43
    return render(request, "parks/map.html", context)
1✔
44

45

46
def park_and_map(request):
1✔
47
    # Get filter values from GET request
48
    filter_value = request.GET.get("filter", "")
1✔
49
    accessible_value = request.GET.get("accessible", "")
1✔
50

51
    # Apply filters based on the selected values
52
    parks = DogRun.objects.all().order_by("id")
1✔
53

54
    if filter_value:
1✔
UNCOV
55
        parks = parks.filter(dogruns_type__icontains=filter_value)
×
56

57
    if accessible_value:
1✔
UNCOV
58
        parks = parks.filter(accessible=accessible_value)
×
59

60
    NYC_LAT_AND_LONG = (40.730610, -73.935242)
1✔
61

62
    # Create map centered on NYC
63
    m = folium.Map(location=NYC_LAT_AND_LONG, zoom_start=11)
1✔
64

65
    coordinates = os.path.join(settings.BASE_DIR, "coordinates.json")
1✔
66
    with open(coordinates, "r") as file:
1✔
67
        coor_dict = json.load(file)
1✔
68

69
    # Mark every park on the map
70
    for park in parks:
1✔
UNCOV
71
        park_name = park.name
×
UNCOV
72
        if park_name in coor_dict:
×
UNCOV
73
            folium.Marker(
×
74
                location=coor_dict[park_name],
75
                popup=park_name,
76
            ).add_to(m)
77

78
    # Render map as HTML
79
    return render(
1✔
80
        request, "parks/combined_view.html", {"parks": parks, "map": m._repr_html_()}
81
    )
82

83

84
def park_detail(request, id):
1✔
85
    park = get_object_or_404(DogRun, id=id)  # Get the park by id
×
86

NEW
87
    if request.method == "POST" and request.FILES.get("image"):
×
88

89
        if park.image:
×
UNCOV
90
            if os.path.exists(park.image.path):
×
91
                os.remove(park.image.path)  # Delete the existing image file
×
UNCOV
92
                print(f"Deleted old image: {park.image.name}")
×
NEW
93
        park.image = request.FILES["image"]
×
UNCOV
94
        park.save()
×
NEW
95
        return redirect("park_detail", id=park.id)
×
96

NEW
97
    return render(request, "parks/park_detail.html", {"park": park})
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc