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

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

12 Mar 2025 11:16PM UTC coverage: 89.7% (+0.9%) from 88.835%
173

cron

travis-pro

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

Develop

27 of 31 new or added lines in 3 files covered. (87.1%)

1 existing line in 1 file now uncovered.

209 of 233 relevant lines covered (89.7%)

0.9 hits per line

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

70.31
/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 map(request):
1✔
20

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

25
    icon_create_function = folium_cluster_styling("rgb(0, 128, 0)")
1✔
26

27
    marker_cluster = MarkerCluster(icon_create_function=icon_create_function).add_to(m)
1✔
28

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

35
    # Fetch all dog runs from the database
36
    parks = DogRun.objects.all()
1✔
37

38
    # Mark every park on the map
39
    for park in parks:
1✔
40
        park_name = park.name
×
41

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

UNCOV
49
        coordinates = coor_dict[park_name]
×
50

51
        folium.Marker(
×
52
            location=coordinates,
53
            icon=folium.Icon(icon="dog", prefix="fa", color="green"),
54
            popup=folium.Popup(park_name, max_width=200),
55
        ).add_to(marker_cluster)
56

57
    # represent map as html
58
    context = {"map": m._repr_html_()}
1✔
59
    return render(request, "parks/map.html", context)
1✔
60

61

62
def park_and_map(request):
1✔
63
    # Get filter values from GET request
64
    filter_value = request.GET.get("filter", "")
1✔
65
    accessible_value = request.GET.get("accessible", "")
1✔
66

67
    # Apply filters based on the selected values
68
    parks = DogRun.objects.all().order_by("id")
1✔
69

70
    if filter_value:
1✔
71
        parks = parks.filter(dogruns_type__icontains=filter_value)
×
72

73
    if accessible_value:
1✔
74
        parks = parks.filter(accessible=accessible_value)
×
75

76
    NYC_LAT_AND_LONG = (40.712775, -74.005973)
1✔
77

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

82
    icon_create_function = folium_cluster_styling("rgb(0, 128, 0)")
1✔
83
    marker_cluster = MarkerCluster(icon_create_function=icon_create_function).add_to(m)
1✔
84

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

89
    # Mark every park on the map
90
    for park in parks:
1✔
91
        park_name = park.name
×
NEW
92
        if park_name not in coor_dict:
×
NEW
93
            continue
×
94

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

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

111
    # Render map as HTML
112
    return render(request, "parks/combined_view.html", {"parks": parks, "map": m})
1✔
113

114

115
def park_detail(request, id):
1✔
116
    park = get_object_or_404(DogRun, id=id)  # Get the park by id
1✔
117

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

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

128
    return render(request, "parks/park_detail.html", {"park": park})
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