Skip to content

Commit

Permalink
Remove org column, fix user select
Browse files Browse the repository at this point in the history
  • Loading branch information
sravfeyn committed Aug 2, 2024
1 parent e85f605 commit e1c03fd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
6 changes: 0 additions & 6 deletions commcare_connect/events/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ class Migration(migrations.Migration):
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
(
"organization",
models.ForeignKey(
on_delete=models.CASCADE, related_name="events", related_query_name="event", to="organization.organization"
),
)
],
),
Expand Down
7 changes: 0 additions & 7 deletions commcare_connect/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.utils.translation import gettext as _

from commcare_connect.cache import quickcache
from commcare_connect.organization.models import Organization
from commcare_connect.users.models import User

from . import types
Expand All @@ -22,12 +21,6 @@ class Event(models.Model):
event_type = models.CharField(max_length=40, db_index=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
opportunity = models.ForeignKey(Opportunity, on_delete=models.PROTECT, null=True)
organization = models.ForeignKey(
Organization,
on_delete=models.CASCADE,
related_name="events",
related_query_name="event",
)

@classmethod
@quickcache([], timeout=60 * 60)
Expand Down
3 changes: 2 additions & 1 deletion commcare_connect/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.response import Response

from commcare_connect.opportunity.forms import DateRanges
from commcare_connect.opportunity.models import Opportunity
from commcare_connect.users.models import User

from .models import Event
Expand Down Expand Up @@ -95,4 +96,4 @@ def get_template_names(self):
return template_name

def get_queryset(self):
return Event.objects.filter(organization=self.request.org)
return Event.objects.filter(opportunity__in=Opportunity.objects.filter(organization=self.request.org))
9 changes: 9 additions & 0 deletions commcare_connect/templates/events/event_table_htmx.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ <h1>Events</h1>

{% block javascript %}
{{ block.super }}
<!-- This is required for select2 'user' field-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<script>
window.addEventListener("DOMContentLoaded", (e) => {
$('select').on('select2:select', function (e) {
$(this).closest('form').get(0).dispatchEvent(new Event('change'));
});
})
</script>

{% endblock %}

{% block css %}
Expand Down

0 comments on commit e1c03fd

Please sign in to comment.