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

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

17 Mar 2025 02:22PM UTC coverage: 89.96% (+0.3%) from 89.7%
188

push

travis-pro

web-flow
Merge pull request #143 from gcivil-nyu-org/kumuda_develop

Bootstrap, main page and top bar

20 of 20 new or added lines in 3 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

224 of 249 relevant lines covered (89.96%)

0.9 hits per line

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

72.06
/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
from folium.plugins import MarkerCluster
1✔
9
import json
1✔
10

11
from .utilities import folium_cluster_styling
1✔
12

13

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

18

19
def home_view(request):
1✔
20
    return render(request, "parks/home.html")
1✔
21

22

23
def map(request):
1✔
24

25
    NYC_LAT_AND_LONG = (40.730610, -73.935242)
1✔
26
    # Create map centered on NYC
27
    m = folium.Map(location=NYC_LAT_AND_LONG, zoom_start=11)
1✔
28

29
    icon_create_function = folium_cluster_styling("rgb(0, 128, 0)")
1✔
30

31
    marker_cluster = MarkerCluster(icon_create_function=icon_create_function).add_to(m)
1✔
32

33
    # Currently, this data is not in DB.
34
    # just saved in file, so we hardcode to import it here
35
    coordinates = os.path.join(settings.BASE_DIR, "new_coordinates.json")
1✔
36
    with open(coordinates, "r") as file:
1✔
37
        coor_dict = json.load(file)
1✔
38

39
    # Fetch all dog runs from the database
40
    parks = DogRun.objects.all()
1✔
41

42
    # Mark every park on the map
43
    for park in parks:
1✔
44
        park_name = park.name
×
45

46
        # Some park names in the original dataset
47
        # does not refer to 1 park, but an area
48
        # of parks. For now just ignore them because there
49
        # is no google_name for them yet
50
        if park_name not in coor_dict:
×
51
            continue
×
52

53
        coordinates = coor_dict[park_name]
×
54

55
        folium.Marker(
×
56
            location=coordinates,
57
            icon=folium.Icon(icon="dog", prefix="fa", color="green"),
58
            popup=folium.Popup(park_name, max_width=200),
59
        ).add_to(marker_cluster)
60

61
    # represent map as html
62
    context = {"map": m._repr_html_()}
1✔
63
    return render(request, "parks/map.html", context)
1✔
64

65

66
def park_and_map(request):
1✔
67
    # Get filter values from GET request
68
    filter_value = request.GET.get("filter", "")
1✔
69
    accessible_value = request.GET.get("accessible", "")
1✔
70

71
    # Apply filters based on the selected values
72
    parks = DogRun.objects.all().order_by("id")
1✔
73
    if filter_value:
1✔
UNCOV
74
        parks = parks.filter(dogruns_type__icontains=filter_value)
×
75

76
    if accessible_value:
1✔
77
        parks = parks.filter(accessible=accessible_value)
×
78

79
    NYC_LAT_AND_LONG = (40.712775, -74.005973)
1✔
80

81
    # Create map centered on NYC
82
    # f = folium.Figure(height="100")
83
    m = folium.Map(location=NYC_LAT_AND_LONG, zoom_start=11)
1✔
84

85
    icon_create_function = folium_cluster_styling("rgb(0, 128, 0)")
1✔
86
    marker_cluster = MarkerCluster(icon_create_function=icon_create_function).add_to(m)
1✔
87

88
    coordinates = os.path.join(settings.BASE_DIR, "new_coordinates.json")
1✔
89
    with open(coordinates, "r") as file:
1✔
90
        coor_dict = json.load(file)
1✔
91

92
    # Mark every park on the map
93
    for park in parks:
1✔
94
        park_name = park.name
×
95
        if park_name not in coor_dict:
×
96
            continue
×
97

98
        if park_name in coor_dict:
×
99
            folium.Marker(
×
100
                location=coor_dict[park_name],
101
                icon=folium.Icon(icon="dog", prefix="fa", color="green"),
102
                popup=folium.Popup(park_name, max_width=200),
103
            ).add_to(marker_cluster)
104

105
    m = m._repr_html_()
1✔
106
    m = m.replace(
1✔
107
        '<div style="width:100%;">'
108
        + '<div style="position:relative;width:100%;height:0;padding-bottom:60%;">',
109
        '<div style="width:100%; height:100%;">'
110
        + '<div style="position:relative;width:100%;height:100%;>',
111
        1,
112
    )
113

114
    # Render map as HTML
115
    return render(request, "parks/combined_view.html", {"parks": parks, "map": m})
1✔
116

117

118
def park_detail(request, id):
1✔
119
    park = get_object_or_404(DogRun, id=id)  # Get the park by id
1✔
120

121
    if request.method == "POST" and request.FILES.get("image"):
1✔
122

123
        if park.image:
×
124
            if os.path.exists(park.image.path):
×
125
                os.remove(park.image.path)  # Delete the existing image file
×
126
                print(f"Deleted old image: {park.image.name}")
×
127
        park.image = request.FILES["image"]
×
128
        park.save()
×
129
        return redirect("park_detail", id=park.id)
×
130

131
    return render(request, "parks/park_detail.html", {"park": park})
1✔
132

133

134
def contact_view(request):
1✔
135
    return render(request, "parks/contact.html")
1✔
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