Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.5"
# version: "3.5"

# shared network to let these services connect to other containerized openstates services
networks:
Expand All @@ -17,6 +17,7 @@ services:
- openstates-network
db:
image: postgres
platform: linux/amd64 # added for Mac M1 compatibility
environment:
- POSTGRES_PASSWORD=test
- POSTGRES_USER=test
Expand Down
41 changes: 22 additions & 19 deletions openstates/data/admin/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ class BillIdentifierInline(IdentifierInline):
class BillActionInline(ReadOnlyTabularInline):
model = models.BillAction

@admin.display(description="Related Entities")
def get_related_entities(self, obj):
ents = obj.related_entities.all()
ent_list = [e.name for e in ents]
return ", ".join(ent_list)

get_related_entities.short_description = "Related Entities"
get_related_entities.allow_tags = True

list_select_related = ("BillActionRelatedEntity",)
readonly_fields = fields = ("date", "organization", "description", "get_related_entities")
readonly_fields = fields = (
"date",
"organization",
"description",
"get_related_entities",
)


class RelatedBillInline(ReadOnlyTabularInline):
Expand All @@ -54,16 +57,14 @@ class BillSponsorshipInline(ReadOnlyTabularInline):
class DocVersionInline(ReadOnlyTabularInline):
model = models.BillVersion

@admin.display(description="Links")
def get_links(self, obj):
return format_html_join(
'<br />',
"<br />",
'<a href="{}" target="_blank">{}</a>',
((link.url, link.url) for link in obj.links.all())
((link.url, link.url) for link in obj.links.all()),
)

get_links.short_description = "Links"
get_links.allow_tags = True

list_select_related = ("BillVersionLink",)
readonly_fields = ("note", "date", "get_links")

Expand Down Expand Up @@ -111,28 +112,26 @@ class BillAdmin(ModelAdmin):
def bill_classifications(self, obj):
return ", ".join(obj.classification)

@admin.display(description="Jurisdiction")
def get_jurisdiction_name(self, obj):
return obj.legislative_session.jurisdiction.name

get_jurisdiction_name.short_description = "Jurisdiction"

@admin.display(
description="Session",
ordering="legislative_session__name",
)
def get_session_name(self, obj):
return obj.legislative_session.name

get_session_name.short_description = "Session"
get_session_name.admin_order_field = "legislative_session__name"

@admin.display(description="Sponsors")
def get_truncated_sponsors(self, obj):
spons = ", ".join(s.name for s in obj.sponsorships.all()[:5])
return defaultfilters.truncatewords(spons, 10)

get_truncated_sponsors.short_description = "Sponsors"

@admin.display(description="Title")
def get_truncated_title(self, obj):
return defaultfilters.truncatewords(obj.title, 25)

get_truncated_title.short_description = "Title"

list_display = (
"identifier",
"get_jurisdiction_name",
Expand All @@ -142,4 +141,8 @@ def get_truncated_title(self, obj):
)

list_filter = ("legislative_session__jurisdiction__name",)
ordering = ("legislative_session__jurisdiction__name", "legislative_session", "identifier")
ordering = (
"legislative_session__jurisdiction__name",
"legislative_session",
"identifier",
)
12 changes: 4 additions & 8 deletions openstates/data/admin/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ class EventAdmin(admin.ModelAdmin):
("start_date", "end_date", "all_day"),
)

@admin.display(description="View source")
def source_link(self, obj):
source = obj.sources.filter(url__icontains="meetingdetail").get()
tmpl = u'<a href="{0}" target="_blank">View source</a>'
tmpl = '<a href="{0}" target="_blank">View source</a>'
return tmpl.format(source.url)

source_link.short_description = "View source"
source_link.allow_tags = True

list_display = ("jurisdiction", "name", "start_date", "source_link")

inlines = [EventParticipantInline]
Expand Down Expand Up @@ -66,16 +64,14 @@ class EventAgendaItemAdmin(admin.ModelAdmin):
readonly_fields = ("event",)
fields = ("event", "description", "classification", "order", "subjects", "notes")

@admin.display(description="Description")
def get_truncated_description(self, obj):
return defaultfilters.truncatewords(obj.description, 25)

get_truncated_description.short_description = "Description"

@admin.display(description="Event Name")
def get_truncated_event_name(self, obj):
return defaultfilters.truncatewords(obj.event.name, 8)

get_truncated_event_name.short_description = "Event Name"

list_display = ("get_truncated_event_name", "get_truncated_description")


Expand Down
49 changes: 26 additions & 23 deletions openstates/data/admin/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ class PostInline(admin.TabularInline):
ordering = ("label",)
can_delete = False

@admin.display(description="Label")
def get_label(self, post):
admin_url = reverse(
"admin:data_post_change", args=(post.pk,)
)
tmpl = u'<a href="%s">%s</a>'
admin_url = reverse("admin:data_post_change", args=(post.pk,))
tmpl = '<a href="%s">%s</a>'
return format_html(tmpl % (admin_url, post.label))

get_label.short_description = "Label"

def has_add_permission(self, request, obj=None):
return False

Expand All @@ -37,17 +34,15 @@ class OrganizationInline(ReadOnlyTabularInline):
fields = readonly_fields = ("get_name", "jurisdiction", "classification")
ordering = ("-classification", "name")

@admin.display(
description="ID",
ordering="organization__name",
)
def get_name(self, organization):
admin_url = reverse(
"admin:data_organization_change", args=(organization.pk,)
)
tmpl = u'<a href="%s">%s</a>'
admin_url = reverse("admin:data_organization_change", args=(organization.pk,))
tmpl = '<a href="%s">%s</a>'
return format_html(tmpl % (admin_url, organization.name))

get_name.short_description = "ID"
get_name.allow_tags = True
get_name.admin_order_field = "organization__name"


class OrgMembershipInline(ReadOnlyTabularInline):
model = models.Membership
Expand All @@ -61,7 +56,15 @@ class OrgMembershipInline(ReadOnlyTabularInline):

@admin.register(models.Post)
class PostAdmin(ModelAdmin):
readonly_fields = fields = ("id", "division", "organization", "label", "role", "maximum_memberships", "extras")
readonly_fields = fields = (
"id",
"division",
"organization",
"label",
"role",
"maximum_memberships",
"extras",
)
ordering = ("division__id", "organization", "role", "label")
inlines = (MembershipInline,)
list_display = ("division", "organization", "role", "label")
Expand All @@ -87,16 +90,20 @@ class OrganizationAdmin(ModelAdmin):
OrganizationInline,
]

@admin.display(
description="Name",
ordering="name",
)
def get_org_name(self, obj):
parent = obj.parent
if parent:
return "{org} ({parent})".format(org=obj.name, parent=parent.name)
return obj.name

get_org_name.short_description = "Name"
get_org_name.allow_tags = True
get_org_name.admin_order_field = "name"

@admin.display(
description="Jurisdiction",
ordering="jurisdiction__name",
)
def get_jurisdiction(self, obj):
jurisdiction = obj.jurisdiction
if jurisdiction:
Expand All @@ -108,10 +115,6 @@ def get_jurisdiction(self, obj):

return "(none)"

get_jurisdiction.short_description = "Jurisdiction"
get_jurisdiction.allow_tags = True
get_jurisdiction.admin_order_field = "jurisdiction__name"

list_select_related = ("jurisdiction",)
list_display = ("get_org_name", "get_jurisdiction", "classification")
ordering = ("jurisdiction__name", "-classification", "name")
49 changes: 30 additions & 19 deletions openstates/data/admin/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ class JurisdictionInline(ReadOnlyTabularInline):
)
ordering = ("id",)

@admin.display(
description="ID",
ordering="jurisdiction__name",
)
def get_id(self, jurisdiction):
admin_url = reverse(
"admin:data_jurisdiction_change", args=(jurisdiction.pk,)
)
tmpl = u'<a href="%s">%s</a>'
admin_url = reverse("admin:data_jurisdiction_change", args=(jurisdiction.pk,))
tmpl = '<a href="%s">%s</a>'
return format_html(tmpl % (admin_url, jurisdiction.name))

get_id.short_description = "ID"
get_id.allow_tags = True
get_id.admin_order_field = "jurisdiction__name"


@admin.register(models.Division)
class DivisionAdmin(ModelAdmin):
Expand All @@ -42,20 +40,24 @@ class DivisionAdmin(ModelAdmin):

class LegislativeSessionInline(ReadOnlyTabularInline):
model = models.LegislativeSession
readonly_fields = ("identifier", "get_name", "classification", "start_date", "end_date")
readonly_fields = (
"identifier",
"get_name",
"classification",
"start_date",
"end_date",
)
fields = readonly_fields
ordering = ("-identifier",)

@admin.display(description="NAME")
def get_name(self, legislative_session):
admin_url = reverse(
"admin:data_legislativesession_change", args=(legislative_session.pk,)
)
tmpl = u'<a href="%s">%s</a>'
tmpl = '<a href="%s">%s</a>'
return format_html(tmpl % (admin_url, legislative_session.name))

get_name.short_description = "NAME"
get_name.allow_tags = True


class BillInline(ReadOnlyTabularInline):
model = models.Bill
Expand All @@ -70,16 +72,22 @@ class BillInline(ReadOnlyTabularInline):
ordering = ("identifier",)

def get_identifier(self, bill):
admin_url = reverse(
"admin:data_bill_change", args=(bill.id,)
)
tmpl = u'<a href="%s">%s</a>'
admin_url = reverse("admin:data_bill_change", args=(bill.id,))
tmpl = '<a href="%s">%s</a>'
return format_html(tmpl % (admin_url, bill.identifier))


@admin.register(models.LegislativeSession)
class LegislativeSessionAdmin(ModelAdmin):
readonly_fields = ("jurisdiction", "identifier", "name", "active", "classification", "start_date", "end_date")
readonly_fields = (
"jurisdiction",
"identifier",
"name",
"active",
"classification",
"start_date",
"end_date",
)
inlines = [BillInline]


Expand All @@ -94,6 +102,9 @@ class JurisdictionAdmin(ModelAdmin):
"extras",
"url",
)
ordering = ("-classification", "id",)
ordering = (
"-classification",
"id",
)
search_fields = ("id", "name")
inlines = [LegislativeSessionInline, OrganizationInline]
3 changes: 1 addition & 2 deletions openstates/data/admin/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PersonAdmin(ModelAdmin):
MembershipInline,
]

@admin.display(description="Memberships")
def get_memberships(self, obj):
memberships = obj.memberships.select_related("organization__jurisdiction")
html = []
Expand All @@ -94,6 +95,4 @@ def get_memberships(self, obj):
html.append("And %d more" % more)
return mark_safe("<br/>".join(html))

get_memberships.short_description = "Memberships"

list_display = ("name", "id", "get_memberships")
6 changes: 2 additions & 4 deletions openstates/data/admin/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class VoteEventAdmin(ModelAdmin):
"counts",
)

@admin.display(description="Jurisdiction")
def get_jurisdiction_name(self, obj):
return obj.legislative_session.jurisdiction.name

get_jurisdiction_name.short_description = "Jurisdiction"

@admin.display(description="Vote Tally")
def get_vote_tally(self, obj):
yes = no = other = 0
for vc in obj.counts.all():
Expand All @@ -58,8 +58,6 @@ def get_vote_tally(self, obj):
other += vc.value
return "{}-{}-{}".format(yes, no, other)

get_vote_tally.short_description = "Vote Tally"

list_display = ("get_jurisdiction_name", "identifier", "bill", "get_vote_tally")

list_filter = ("legislative_session__jurisdiction__name",)
Expand Down
Loading