We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add field for tribe locality on Tribal Goverment Question Page 
### Story

As a Registrant Applicant I want a way to specify the locality of my tribe so that I can give analysts more specific information to complete their review of my request

![tribalgovernment](https://github.com/cisagov/getgov/assets/107440934/48d1a8a2-e074-4ad2-9440-838eaa3e382a)


### Acceptance Criteria

- [x] Content is drafted for the question
- [x] Content is approved
- [x] Design prototype demonstrates the look and feel for approval
- [x] Implement the field in the registrar

A new field is added to the page that allows the user to specify the locality of their tribe

### Additional Context

_No response_

### Issue Links

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/registrar/templatetags/custom_filters.py`
Content:
```
1 from django import template
2 import re
3 
4 register = template.Library()
5 
6 
7 @register.filter(name="extract_value")
8 def extract_value(html_input):
9     match = re.search(r'value="([^"]*)"', html_input)
10     if match:
11         return match.group(1)
12     return ""
13 
14 
15 @register.filter
16 def extract_a_text(value):
17     # Use regex to extract the text within the <a> tag
18     pattern = r"<a\b[^>]*>(.*?)</a>"
19     match = re.search(pattern, value)
20     if match:
21         extracted_text = match.group(1)
22     else:
23         extracted_text = ""
24 
25     return extracted_text
26
```

Path: `src/registrar/views/utility/mixins.py`
Content:
```
1 """Permissions-related mixin classes."""
2 
3 from django.contrib.auth.mixins import PermissionRequiredMixin
4 
5 from registrar.models import UserDomainRole, DomainApplication, DomainInvitation
6 
7 
8 class PermissionsLoginMixin(PermissionRequiredMixin):
9 
10     """Mixin that redirects to login page if not logged in, otherwise 403."""
11 
12     def handle_no_permission(self):
13         self.raise_exception = self.request.user.is_authenticated
14         return super().handle_no_permission()
15 
16 
17 class DomainPermission(PermissionsLoginMixin):
18 
19     """Does the logged-in user have access to this domain?"""
20 
21     def has_permission(self):
22         """Check if this user has access to this domain.
23 
24         The user is in self.request.user and the domain needs to be looked
25         up from the domain's primary key in self.kwargs["pk"]
26         """
27         if not self.request.user.is_authenticated:
28             return False
29 
30         # user needs to have a role on the domain
31         if not UserDomainRole.objects.filter(
32             user=self.request.user, domain__id=self.kwargs["pk"]
33         ).exists():
34             return False
35 
36         # if we need to check more about the nature of role, do it here.
37         return True
38 
39 
40 class DomainApplicationPermission(PermissionsLoginMixin):
41 
42     """Does the logged-in user have access to this domain application?"""
43 
44     def has_permission(self):
45         """Check if this user has access to this domain application.
46 
47         The user is in self.request.user and the domain needs to be looked
48         up from the domain's primary key in self.kwargs["pk"]
49         """
50         if not self.request.user.is_authenticated:
51             return False
52 
53         # user needs to be the creator of the application
54         # this query is empty if there isn't a domain application with this
55         # id and this user as creator
56         if not DomainApplication.objects.filter(
57             creator=self.request.user, id=self.kwargs["pk"]
58         ).exists():
59             return False
60 
61         return True
62 
63 
64 class DomainInvitationPermission(PermissionsLoginMixin):
65 
66     """Does the logged-in user have access to this domain invitation?
67 
68     A user has access to a domain invitation if they have a role on the
69     associated domain.
70     """
71 
72     def has_permission(self):
73         """Check if this user has a role on the domain of this invitation."""
74         if not self.request.user.is_authenticated:
75             return False
76 
77         if not DomainInvitation.objects.filter(
78             id=self.kwargs["pk"], domain__permissions__user=self.request.user
79         ).exists():
80             return False
81 
82         return True
83
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py
--- a/src/registrar/templatetags/custom_filters.py
+++ b/src/registrar/templatetags/custom_filters.py
@@ -23,3 +23,20 @@
         extracted_text = ""
 
     return extracted_text
+
+
+@register.filter
+def find_index(haystack, needle):
+    try:
+        return haystack.index(needle)
+    except ValueError:
+        return -1
+
+
+@register.filter
+def slice_after(value, substring):
+    index = value.find(substring)
+    if index != -1:
+        result = value[index + len(substring) :]
+        return result
+    return value
diff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py
--- a/src/registrar/views/utility/mixins.py
+++ b/src/registrar/views/utility/mixins.py
@@ -24,6 +24,12 @@
         The user is in self.request.user and the domain needs to be looked
         up from the domain's primary key in self.kwargs["pk"]
         """
+
+        # ticket 806
+        # if self.request.user is staff or admin and
+        # domain.application__status = 'approved' or 'rejected' or 'action needed'
+        #     return True
+
         if not self.request.user.is_authenticated:
             return False
 
@@ -33,6 +39,10 @@
         ).exists():
             return False
 
+        # ticket 796
+        # if domain.application__status != 'approved'
+        #     return false
+
         # if we need to check more about the nature of role, do it here.
         return True

{"golden_diff": "diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py\n--- a/src/registrar/templatetags/custom_filters.py\n+++ b/src/registrar/templatetags/custom_filters.py\n@@ -23,3 +23,20 @@\n         extracted_text = \"\"\n \n     return extracted_text\n+\n+\n+@register.filter\n+def find_index(haystack, needle):\n+    try:\n+        return haystack.index(needle)\n+    except ValueError:\n+        return -1\n+\n+\n+@register.filter\n+def slice_after(value, substring):\n+    index = value.find(substring)\n+    if index != -1:\n+        result = value[index + len(substring) :]\n+        return result\n+    return value\ndiff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py\n--- a/src/registrar/views/utility/mixins.py\n+++ b/src/registrar/views/utility/mixins.py\n@@ -24,6 +24,12 @@\n         The user is in self.request.user and the domain needs to be looked\n         up from the domain's primary key in self.kwargs[\"pk\"]\n         \"\"\"\n+\n+        # ticket 806\n+        # if self.request.user is staff or admin and\n+        # domain.application__status = 'approved' or 'rejected' or 'action needed'\n+        #     return True\n+\n         if not self.request.user.is_authenticated:\n             return False\n \n@@ -33,6 +39,10 @@\n         ).exists():\n             return False\n \n+        # ticket 796\n+        # if domain.application__status != 'approved'\n+        #     return false\n+\n         # if we need to check more about the nature of role, do it here.\n         return True\n", "issue": "Add field for tribe locality on Tribal Goverment Question Page \n### Story\r\n\r\nAs a Registrant Applicant I want a way to specify the locality of my tribe so that I can give analysts more specific information to complete their review of my request\r\n\r\n![tribalgovernment](https://github.com/cisagov/getgov/assets/107440934/48d1a8a2-e074-4ad2-9440-838eaa3e382a)\r\n\r\n\r\n### Acceptance Criteria\r\n\r\n- [x] Content is drafted for the question\r\n- [x] Content is approved\r\n- [x] Design prototype demonstrates the look and feel for approval\r\n- [x] Implement the field in the registrar\r\n\r\nA new field is added to the page that allows the user to specify the locality of their tribe\r\n\r\n### Additional Context\r\n\r\n_No response_\r\n\r\n### Issue Links\r\n\r\n_No response_\n", "before_files": [{"content": "from django import template\nimport re\n\nregister = template.Library()\n\n\n@register.filter(name=\"extract_value\")\ndef extract_value(html_input):\n    match = re.search(r'value=\"([^\"]*)\"', html_input)\n    if match:\n        return match.group(1)\n    return \"\"\n\n\n@register.filter\ndef extract_a_text(value):\n    # Use regex to extract the text within the <a> tag\n    pattern = r\"<a\\b[^>]*>(.*?)</a>\"\n    match = re.search(pattern, value)\n    if match:\n        extracted_text = match.group(1)\n    else:\n        extracted_text = \"\"\n\n    return extracted_text\n", "path": "src/registrar/templatetags/custom_filters.py"}, {"content": "\"\"\"Permissions-related mixin classes.\"\"\"\n\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\n\nfrom registrar.models import UserDomainRole, DomainApplication, DomainInvitation\n\n\nclass PermissionsLoginMixin(PermissionRequiredMixin):\n\n    \"\"\"Mixin that redirects to login page if not logged in, otherwise 403.\"\"\"\n\n    def handle_no_permission(self):\n        self.raise_exception = self.request.user.is_authenticated\n        return super().handle_no_permission()\n\n\nclass DomainPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain?\"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has access to this domain.\n\n        The user is in self.request.user and the domain needs to be looked\n        up from the domain's primary key in self.kwargs[\"pk\"]\n        \"\"\"\n        if not self.request.user.is_authenticated:\n            return False\n\n        # user needs to have a role on the domain\n        if not UserDomainRole.objects.filter(\n            user=self.request.user, domain__id=self.kwargs[\"pk\"]\n        ).exists():\n            return False\n\n        # if we need to check more about the nature of role, do it here.\n        return True\n\n\nclass DomainApplicationPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain application?\"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has access to this domain application.\n\n        The user is in self.request.user and the domain needs to be looked\n        up from the domain's primary key in self.kwargs[\"pk\"]\n        \"\"\"\n        if not self.request.user.is_authenticated:\n            return False\n\n        # user needs to be the creator of the application\n        # this query is empty if there isn't a domain application with this\n        # id and this user as creator\n        if not DomainApplication.objects.filter(\n            creator=self.request.user, id=self.kwargs[\"pk\"]\n        ).exists():\n            return False\n\n        return True\n\n\nclass DomainInvitationPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain invitation?\n\n    A user has access to a domain invitation if they have a role on the\n    associated domain.\n    \"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has a role on the domain of this invitation.\"\"\"\n        if not self.request.user.is_authenticated:\n            return False\n\n        if not DomainInvitation.objects.filter(\n            id=self.kwargs[\"pk\"], domain__permissions__user=self.request.user\n        ).exists():\n            return False\n\n        return True\n", "path": "src/registrar/views/utility/mixins.py"}], "after_files": [{"content": "from django import template\nimport re\n\nregister = template.Library()\n\n\n@register.filter(name=\"extract_value\")\ndef extract_value(html_input):\n    match = re.search(r'value=\"([^\"]*)\"', html_input)\n    if match:\n        return match.group(1)\n    return \"\"\n\n\n@register.filter\ndef extract_a_text(value):\n    # Use regex to extract the text within the <a> tag\n    pattern = r\"<a\\b[^>]*>(.*?)</a>\"\n    match = re.search(pattern, value)\n    if match:\n        extracted_text = match.group(1)\n    else:\n        extracted_text = \"\"\n\n    return extracted_text\n\n\n@register.filter\ndef find_index(haystack, needle):\n    try:\n        return haystack.index(needle)\n    except ValueError:\n        return -1\n\n\n@register.filter\ndef slice_after(value, substring):\n    index = value.find(substring)\n    if index != -1:\n        result = value[index + len(substring) :]\n        return result\n    return value\n", "path": "src/registrar/templatetags/custom_filters.py"}, {"content": "\"\"\"Permissions-related mixin classes.\"\"\"\n\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\n\nfrom registrar.models import UserDomainRole, DomainApplication, DomainInvitation\n\n\nclass PermissionsLoginMixin(PermissionRequiredMixin):\n\n    \"\"\"Mixin that redirects to login page if not logged in, otherwise 403.\"\"\"\n\n    def handle_no_permission(self):\n        self.raise_exception = self.request.user.is_authenticated\n        return super().handle_no_permission()\n\n\nclass DomainPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain?\"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has access to this domain.\n\n        The user is in self.request.user and the domain needs to be looked\n        up from the domain's primary key in self.kwargs[\"pk\"]\n        \"\"\"\n\n        # ticket 806\n        # if self.request.user is staff or admin and\n        # domain.application__status = 'approved' or 'rejected' or 'action needed'\n        #     return True\n\n        if not self.request.user.is_authenticated:\n            return False\n\n        # user needs to have a role on the domain\n        if not UserDomainRole.objects.filter(\n            user=self.request.user, domain__id=self.kwargs[\"pk\"]\n        ).exists():\n            return False\n\n        # ticket 796\n        # if domain.application__status != 'approved'\n        #     return false\n\n        # if we need to check more about the nature of role, do it here.\n        return True\n\n\nclass DomainApplicationPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain application?\"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has access to this domain application.\n\n        The user is in self.request.user and the domain needs to be looked\n        up from the domain's primary key in self.kwargs[\"pk\"]\n        \"\"\"\n        if not self.request.user.is_authenticated:\n            return False\n\n        # user needs to be the creator of the application\n        # this query is empty if there isn't a domain application with this\n        # id and this user as creator\n        if not DomainApplication.objects.filter(\n            creator=self.request.user, id=self.kwargs[\"pk\"]\n        ).exists():\n            return False\n\n        return True\n\n\nclass DomainInvitationPermission(PermissionsLoginMixin):\n\n    \"\"\"Does the logged-in user have access to this domain invitation?\n\n    A user has access to a domain invitation if they have a role on the\n    associated domain.\n    \"\"\"\n\n    def has_permission(self):\n        \"\"\"Check if this user has a role on the domain of this invitation.\"\"\"\n        if not self.request.user.is_authenticated:\n            return False\n\n        if not DomainInvitation.objects.filter(\n            id=self.kwargs[\"pk\"], domain__permissions__user=self.request.user\n        ).exists():\n            return False\n\n        return True\n", "path": "src/registrar/views/utility/mixins.py"}]}