2017-12-26 17:46:27 +01:00
|
|
|
from django.contrib import admin
|
2018-02-27 05:03:56 +01:00
|
|
|
from django.utils.safestring import mark_safe
|
2018-09-05 04:14:59 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django.contrib.admin import SimpleListFilter
|
2017-12-26 17:46:27 +01:00
|
|
|
|
|
|
|
# Register your models here.
|
|
|
|
from .models.locale import Language, Continent, Country, SPR, City
|
2018-04-22 04:14:15 +02:00
|
|
|
from .models.profiles import (
|
|
|
|
UserProfile,
|
|
|
|
Organization,
|
2018-08-06 17:08:51 +02:00
|
|
|
OrgTeamRequest,
|
2018-04-22 04:14:15 +02:00
|
|
|
Team,
|
|
|
|
Member,
|
|
|
|
Category,
|
|
|
|
Topic,
|
2018-05-20 18:35:52 +02:00
|
|
|
Sponsor,
|
2018-04-22 04:14:15 +02:00
|
|
|
)
|
2017-12-26 17:46:27 +01:00
|
|
|
from .models.search import Searchable
|
2018-04-22 04:14:15 +02:00
|
|
|
from .models.events import (
|
|
|
|
Place,
|
|
|
|
Event,
|
|
|
|
EventComment,
|
|
|
|
EventSeries,
|
|
|
|
EventPhoto,
|
|
|
|
CommonEvent,
|
|
|
|
Attendee,
|
2018-04-25 16:36:01 +02:00
|
|
|
)
|
|
|
|
from .models.speakers import (
|
|
|
|
Speaker,
|
|
|
|
Talk,
|
2018-04-22 04:14:15 +02:00
|
|
|
Presentation,
|
2018-04-25 16:36:01 +02:00
|
|
|
SpeakerRequest,
|
2018-04-22 04:14:15 +02:00
|
|
|
)
|
2017-12-26 17:46:27 +01:00
|
|
|
|
|
|
|
admin.site.register(Language)
|
|
|
|
admin.site.register(Continent)
|
|
|
|
admin.site.register(Country)
|
|
|
|
|
2018-09-05 04:14:59 +02:00
|
|
|
from django.db.models import Count
|
|
|
|
class NumberOfEventsFilter(SimpleListFilter):
|
|
|
|
title = _('Event Count')
|
|
|
|
parameter_name = 'event_count'
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
return (
|
|
|
|
('0', '0'),
|
2018-12-17 04:37:36 +01:00
|
|
|
('1', '1'),
|
|
|
|
('2', '2 - 9'),
|
2018-09-05 04:14:59 +02:00
|
|
|
('10', '10 - 99'),
|
|
|
|
('100', '100+'),
|
|
|
|
('>0', '> 0')
|
|
|
|
)
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
if self.value() == '0':
|
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events=0)
|
|
|
|
if self.value() == '>0':
|
2018-12-17 04:39:40 +01:00
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events__gte=0)
|
2018-09-05 04:14:59 +02:00
|
|
|
if self.value() == '1':
|
2018-12-17 04:39:40 +01:00
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events=1)
|
2018-12-17 04:37:36 +01:00
|
|
|
if self.value() == '2':
|
2018-12-17 04:39:40 +01:00
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events__gte=2, num_events__lte=9)
|
2018-09-05 04:14:59 +02:00
|
|
|
if self.value() == '10':
|
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events__gte=10, num_events__lte=99)
|
|
|
|
if self.value() == '100':
|
|
|
|
return queryset.annotate(num_events=Count('event')).filter(num_events__gte=100)
|
|
|
|
|
|
|
|
class NumberOfMembersFilter(SimpleListFilter):
|
|
|
|
title = _('Member Count')
|
|
|
|
parameter_name = 'member_count'
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
return (
|
|
|
|
('0', '0'),
|
2018-12-17 04:37:36 +01:00
|
|
|
('1', '1'),
|
|
|
|
('2', '2 - 9'),
|
2018-09-05 04:14:59 +02:00
|
|
|
('10', '10 - 99'),
|
|
|
|
('100', '100+'),
|
|
|
|
('>0', '> 0')
|
|
|
|
)
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
if self.value() == '0':
|
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events=0)
|
|
|
|
if self.value() == '>0':
|
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events__gt=0)
|
|
|
|
if self.value() == '1':
|
2018-12-17 04:37:36 +01:00
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events=1)
|
|
|
|
if self.value() == '2':
|
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events__gte=2, num_events__lte=9)
|
2018-09-05 04:14:59 +02:00
|
|
|
if self.value() == '10':
|
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events__gte=10, num_events__lte=99)
|
|
|
|
if self.value() == '100':
|
|
|
|
return queryset.annotate(num_events=Count('member')).filter(num_events__gte=100)
|
|
|
|
|
2018-12-17 04:37:36 +01:00
|
|
|
class NumberOfAttendeesFilter(SimpleListFilter):
|
|
|
|
title = _('Attendee Count')
|
|
|
|
parameter_name = 'attendee_count'
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
return (
|
|
|
|
('0', '0'),
|
|
|
|
('1', '1'),
|
|
|
|
('2', '2 - 9'),
|
|
|
|
('10', '10 - 99'),
|
|
|
|
('100', '100+'),
|
|
|
|
('>0', '> 0')
|
|
|
|
)
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
if self.value() == '0':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events=0)
|
|
|
|
if self.value() == '>0':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events__gt=0)
|
|
|
|
if self.value() == '1':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events=1)
|
|
|
|
if self.value() == '2':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events__gte=2, num_events__lte=9)
|
|
|
|
if self.value() == '10':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events__gte=10, num_events__lte=99)
|
|
|
|
if self.value() == '100':
|
|
|
|
return queryset.annotate(num_events=Count('attendee')).filter(num_events__gte=100)
|
|
|
|
|
2017-12-26 17:46:27 +01:00
|
|
|
class SPRAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('country',)
|
2018-01-04 05:44:27 +01:00
|
|
|
list_filter =('country',)
|
|
|
|
search_fields = ('name', 'country__name')
|
2017-12-26 17:46:27 +01:00
|
|
|
admin.site.register(SPR, SPRAdmin)
|
|
|
|
|
|
|
|
class CityAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('spr',)
|
2018-09-27 23:42:23 +02:00
|
|
|
list_display = ('name', 'spr', 'latitude', 'longitude', 'population')
|
2018-01-04 05:44:27 +01:00
|
|
|
list_filter =('spr__country',)
|
|
|
|
search_fields = ('name', 'spr__name')
|
2017-12-26 17:46:27 +01:00
|
|
|
admin.site.register(City, CityAdmin)
|
|
|
|
|
2018-01-27 03:06:33 +01:00
|
|
|
class ProfileAdmin(admin.ModelAdmin):
|
2018-04-21 16:28:04 +02:00
|
|
|
raw_id_fields = ('city',)
|
2018-08-05 19:06:22 +02:00
|
|
|
list_display = ('user', 'realname', 'city', 'web_url', 'send_notifications', 'do_not_track')
|
|
|
|
list_filter = ('send_notifications', 'do_not_track', 'user__last_login')
|
2018-01-27 03:06:33 +01:00
|
|
|
admin.site.register(UserProfile, ProfileAdmin)
|
2018-01-04 05:44:27 +01:00
|
|
|
|
|
|
|
class OrgAdmin(admin.ModelAdmin):
|
2018-09-28 00:00:42 +02:00
|
|
|
list_display = ('name', 'slug', 'team_count', 'owner_profile', 'site')
|
|
|
|
def team_count(self, org):
|
|
|
|
return org.teams.all().count()
|
|
|
|
team_count.short_description = 'Teams'
|
2018-01-04 05:44:27 +01:00
|
|
|
admin.site.register(Organization, OrgAdmin)
|
2017-12-26 17:46:27 +01:00
|
|
|
|
2018-08-06 17:08:51 +02:00
|
|
|
class OrgRequestAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('organization', 'team', 'request_origin', 'requested_by', 'requested_date', 'accepted_by', 'joined_date')
|
|
|
|
list_filter = ('organization', 'request_origin')
|
|
|
|
admin.site.register(OrgTeamRequest, OrgRequestAdmin)
|
|
|
|
|
2018-05-20 18:35:52 +02:00
|
|
|
class SponsorAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('name', 'web_url')
|
|
|
|
admin.site.register(Sponsor, SponsorAdmin)
|
|
|
|
|
2017-12-26 17:46:27 +01:00
|
|
|
class TeamAdmin(admin.ModelAdmin):
|
2018-05-20 18:35:52 +02:00
|
|
|
raw_id_fields = ('country', 'spr', 'city', 'owner_profile', 'admin_profiles', 'contact_profiles', 'sponsors')
|
2018-08-25 16:21:22 +02:00
|
|
|
list_display = ('__str__', 'active', 'member_count', 'event_count', 'owner_profile', 'created_date', 'access')
|
2018-09-05 04:14:59 +02:00
|
|
|
list_filter = ('access', 'organization', NumberOfMembersFilter, NumberOfEventsFilter, ('country',admin.RelatedOnlyFieldListFilter), 'active')
|
2018-02-13 13:33:23 +01:00
|
|
|
ordering = ('-created_date',)
|
2018-08-17 06:07:29 +02:00
|
|
|
|
2018-02-13 13:33:23 +01:00
|
|
|
def member_count(self, team):
|
|
|
|
return team.members.all().count()
|
|
|
|
member_count.short_description = 'Members'
|
2018-04-28 00:11:05 +02:00
|
|
|
def event_count(self, team):
|
|
|
|
return team.event_set.all().count()
|
|
|
|
event_count.short_description = 'Events'
|
2017-12-26 17:46:27 +01:00
|
|
|
admin.site.register(Team, TeamAdmin)
|
|
|
|
|
2018-02-15 02:01:43 +01:00
|
|
|
class SearchableAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('event_url', 'start_time', 'federation_node', 'federation_time')
|
|
|
|
list_filter = ('federation_node',)
|
|
|
|
ordering = ('-start_time',)
|
|
|
|
admin.site.register(Searchable, SearchableAdmin)
|
2017-12-26 17:46:27 +01:00
|
|
|
|
|
|
|
class PlaceAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('city',)
|
|
|
|
admin.site.register(Place, PlaceAdmin)
|
|
|
|
|
|
|
|
class EventAdmin(admin.ModelAdmin):
|
2018-05-20 18:35:52 +02:00
|
|
|
raw_id_fields = ('place', 'created_by', 'sponsors')
|
2018-03-11 08:19:44 +01:00
|
|
|
list_display = ('__str__', 'attendee_count', 'start_time', 'created_by', 'created_time')
|
2018-12-17 04:37:36 +01:00
|
|
|
list_filter = ('created_time', 'start_time', NumberOfAttendeesFilter, ('team__country',admin.RelatedOnlyFieldListFilter))
|
2018-03-11 08:19:44 +01:00
|
|
|
ordering = ('-start_time',)
|
2018-02-13 13:33:23 +01:00
|
|
|
def attendee_count(self, event):
|
|
|
|
return event.attendees.all().count()
|
|
|
|
attendee_count.short_description = 'Attendees'
|
2017-12-26 17:46:27 +01:00
|
|
|
admin.site.register(Event, EventAdmin)
|
|
|
|
|
2018-03-18 17:37:23 +01:00
|
|
|
class EventPhotoAdmin(admin.ModelAdmin):
|
2018-03-24 05:00:38 +01:00
|
|
|
raw_id_fields = ('event',)
|
2018-03-18 17:37:23 +01:00
|
|
|
list_display = ('title', 'event', 'view')
|
|
|
|
def view(self, photo):
|
|
|
|
return mark_safe('<a href="%s" target="_blank"><img src="%s" height="90px"></a>' % (photo.src.url, photo.thumbnail.url))
|
|
|
|
view.short_description = 'Photo'
|
|
|
|
admin.site.register(EventPhoto, EventPhotoAdmin)
|
2018-03-17 22:37:56 +01:00
|
|
|
|
2018-03-24 05:00:38 +01:00
|
|
|
class EventCommentAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('event', 'author')
|
|
|
|
list_display = ('event', 'author', 'status', 'created_time')
|
|
|
|
admin.site.register(EventComment, EventCommentAdmin)
|
|
|
|
|
2018-03-17 20:29:17 +01:00
|
|
|
class CommonEventAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('place', 'city', 'spr', 'country')
|
|
|
|
list_display = ('__str__', 'participant_count', 'organization', 'start_time', 'country', 'spr', 'city')
|
|
|
|
ordering = ('-start_time',)
|
|
|
|
def participant_count(self, event):
|
|
|
|
return event.participating_events.all().count()
|
|
|
|
participant_count.short_description = 'Participants'
|
|
|
|
admin.site.register(CommonEvent, CommonEventAdmin)
|
|
|
|
|
2018-04-14 17:14:40 +02:00
|
|
|
class EventSeriesAdmin(admin.ModelAdmin):
|
|
|
|
raw_id_fields = ('place', 'team')
|
|
|
|
list_display = ('__str__', 'instance_count', 'team', 'start_time', 'last_time')
|
|
|
|
ordering = ('-last_time',)
|
|
|
|
def instance_count(self, series):
|
|
|
|
return series.instances.all().count()
|
|
|
|
instance_count.short_description = 'Instances'
|
|
|
|
admin.site.register(EventSeries, EventSeriesAdmin)
|
|
|
|
|
2018-03-04 20:10:37 +01:00
|
|
|
class MemberAdmin(admin.ModelAdmin):
|
2018-05-13 23:09:15 +02:00
|
|
|
list_display = ('__str__', 'role', 'joined_date')
|
|
|
|
list_filter = ('role', 'team', 'joined_date')
|
2018-03-04 20:10:37 +01:00
|
|
|
admin.site.register(Member, MemberAdmin)
|
|
|
|
|
|
|
|
class AttendeeAdmin(admin.ModelAdmin):
|
2018-05-13 22:59:03 +02:00
|
|
|
list_display = ('__str__', 'role', 'status', 'joined_date', 'last_reminded')
|
|
|
|
list_filter = ('role', 'status', 'joined_date')
|
2018-03-04 20:10:37 +01:00
|
|
|
admin.site.register(Attendee, AttendeeAdmin)
|
2018-01-24 05:15:14 +01:00
|
|
|
|
2018-02-27 05:03:56 +01:00
|
|
|
class CategoryAdmin(admin.ModelAdmin):
|
2018-04-21 16:28:04 +02:00
|
|
|
list_display = ('name', 'slug', 'image')
|
|
|
|
exclude = ('slug', )
|
2018-02-27 05:03:56 +01:00
|
|
|
def image(self, obj):
|
|
|
|
return (mark_safe('<img src="%s" title="%s" height="64px" />' % (obj.img_url, obj.name)))
|
|
|
|
image.short_description = 'Image'
|
|
|
|
admin.site.register(Category, CategoryAdmin)
|
2017-12-26 17:46:27 +01:00
|
|
|
|
2018-02-27 05:03:56 +01:00
|
|
|
class TopicAdmin(admin.ModelAdmin):
|
2018-04-21 16:28:04 +02:00
|
|
|
list_display = ('name', 'slug', 'category')
|
2018-02-27 05:03:56 +01:00
|
|
|
list_filter = ('category',)
|
2018-04-21 16:28:04 +02:00
|
|
|
exclude = ('slug', )
|
|
|
|
admin.site.register(Topic, TopicAdmin)
|
|
|
|
|
2018-04-24 16:22:16 +02:00
|
|
|
class SpeakerAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('title', 'user', 'avatar')
|
|
|
|
admin.site.register(Speaker, SpeakerAdmin)
|
|
|
|
|
|
|
|
class TalkAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('title', 'speaker', 'category')
|
|
|
|
list_filter = ('category',)
|
|
|
|
admin.site.register(Talk, TalkAdmin)
|
|
|
|
|
|
|
|
class PresentationAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('talk', 'status', 'event')
|
|
|
|
list_filter = ('status',)
|
|
|
|
admin.site.register(Presentation, PresentationAdmin)
|
2018-04-22 04:14:15 +02:00
|
|
|
|