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

gcivil-nyu-org / wed-fall24-team1 / #58

13 Nov 2024 05:50AM UTC coverage: 90.895% (+42.9%) from 47.955%
#58

push

coveralls-python

web-flow
#148 service provider's home is their list of services (#156)

2 of 3 new or added lines in 1 file covered. (66.67%)

28 existing lines in 6 files now uncovered.

2845 of 3130 relevant lines covered (90.89%)

0.91 hits per line

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

90.91
/src/services/forms.py
1
# services/forms.py
2
from decimal import Decimal
1✔
3

4
from django import forms
1✔
5
from django.forms import formset_factory
1✔
6
from geopy import Nominatim
1✔
7
from geopy.exc import GeocoderTimedOut, GeocoderServiceError
1✔
8

9

10
class ServiceForm(forms.Form):
1✔
11
    CATEGORY_CHOICES = [
1✔
12
        ("Mental Health Center", "Mental Health Center"),
13
        ("Homeless Shelter", "Homeless Shelter"),
14
        ("Food Pantry", "Food Pantry"),
15
        ("Restroom", "Restroom"),
16
    ]
17

18
    name = forms.CharField(max_length=255)
1✔
19
    address = forms.CharField(widget=forms.Textarea)
1✔
20
    category = forms.ChoiceField(choices=CATEGORY_CHOICES)
1✔
21
    is_active = forms.BooleanField(
1✔
22
        required=False, initial=True, label="Is the service currently available?"
23
    )
24

25
    def clean(self):
1✔
26
        cleaned_data = super().clean()
1✔
27
        address = cleaned_data.get("address")
1✔
28

29
        if address:
1✔
30
            geolocator = Nominatim(user_agent="public_service_finder")
1✔
31
            try:
1✔
32
                location = geolocator.geocode(address)
1✔
33
                if location:
1✔
34
                    cleaned_data["latitude"] = Decimal(str(location.latitude))
1✔
35
                    cleaned_data["longitude"] = Decimal(str(location.longitude))
1✔
36
                else:
37
                    self.add_error(
×
38
                        "address",
39
                        "Unable to geocode the given address. Please check if the address is correct.",
40
                    )
41
            except (GeocoderTimedOut, GeocoderServiceError):
×
UNCOV
42
                self.add_error(
×
43
                    "address",
44
                    "Error occurred while geocoding the address. Please try again later.",
45
                )
46

47
        # Translate category to backend value
48
        category_translation = {
1✔
49
            "Mental Health Center": "MENTAL",
50
            "Homeless Shelter": "SHELTER",
51
            "Food Pantry": "FOOD",
52
            "Restroom": "RESTROOM",
53
        }
54
        cleaned_data["category"] = category_translation[cleaned_data["category"]]
1✔
55

56
        return cleaned_data
1✔
57

58

59
class DescriptionItemForm(forms.Form):
1✔
60
    key = forms.CharField(max_length=100)
1✔
61
    value = forms.CharField(widget=forms.Textarea(attrs={"rows": 3}))
1✔
62

63

64
DescriptionFormSet = formset_factory(DescriptionItemForm, extra=1, can_delete=True)
1✔
65

66

67
class ReviewResponseForm(forms.Form):
1✔
68
    responseText = forms.CharField(  # Changed from 'response' to 'responseText'
1✔
69
        widget=forms.Textarea(
70
            attrs={
71
                "class": "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",
72
                "rows": "4",
73
                "placeholder": "Enter your response to this review...",
74
            }
75
        ),
76
        required=True,
77
    )
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