Loading elections/admin.py +1 −13 Changes for elections/admin.py: 1 added line, 13 removed lines. Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ class OptionInline(admin.TabularInline): extra = 1 class ElectionAdmin(admin.ModelAdmin): list_display = ['name', 'start_date', 'end_date', 'is_active_status', 'view_live_results', 'view_statistics'] list_display = ['name', 'start_date', 'end_date', 'is_active_status'] ordering = ['-created_at', '-updated_at'] exclude = ['invalid_votes', 'local_votes_entered'] Loading @@ -21,17 +21,5 @@ class ElectionAdmin(admin.ModelAdmin): def is_active_status(self, obj): return obj.is_active @admin.display(description='Aktualne wyniki') def view_live_results(self, obj): url = reverse('stats:live_results', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) @admin.display(description='Statystyki') def view_statistics(self, obj): if obj.is_active: return format_html('<span style="color: #999;">{}Dostępne po zakończeniu głosowania</span>', '') url = reverse('stats:statistics', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) # Register your models here. admin.site.register(Election, ElectionAdmin) No newline at end of file stats/admin.py +53 −6 Changes for stats/admin.py: 53 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -2,15 +2,52 @@ from django.contrib import admin from django.shortcuts import render, get_object_or_404 from django.db.models import Count, Q from django.contrib.admin.views.decorators import staff_member_required from django.urls import reverse from django.utils.html import format_html from django.utils.safestring import mark_safe from django.urls import path from elections.models import Election from vote.models import Participation from voters.models import Voter, Group from .models import ElectionStats from elections.admin import OptionInline import re @staff_member_required def live_results(request, election_id): class ElectionStatsAdmin(admin.ModelAdmin): list_display = ['name', 'view_live_results', 'view_statistics'] ordering = ['-created_at', '-updated_at'] exclude = ['invalid_votes', 'local_votes_entered'] inlines = (OptionInline, ) @admin.display(description="Aktywne", boolean=True) def is_active_status(self, obj): return obj.is_active @admin.display(description='Aktualne wyniki') def view_live_results(self, obj): url = reverse('admin:live_results', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) @admin.display(description='Pełne statystyki') def view_statistics(self, obj): if obj.is_active: return mark_safe('<span style="color: #999;">Dostępne po zakończeniu głosowania</span>') url = reverse('admin:statistics', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) def get_urls(self): urls = super().get_urls() custom_urls = [ path('live-results/<int:election_id>', self.admin_site.admin_view(self.live_results_view), name='live_results'), path('statistics/<int:election_id>', self.admin_site.admin_view(self.statistics_view), name='statistics') ] return custom_urls + urls def live_results_view(self, request, election_id): context = admin.site.each_context(request) context.update({ Loading @@ -18,10 +55,9 @@ def live_results(request, election_id): 'title' : 'Wyniki na żywo' }) return render(request, 'stats/live_results.html', context) return render(request, 'admin/live_results.html', context) @staff_member_required def statistics(request, election_id): def statistics_view(self, request, election_id): election = get_object_or_404(Election, id=election_id) context = admin.site.each_context(request) Loading Loading @@ -81,4 +117,15 @@ def statistics(request, election_id): 'stationary_percentage': stationary_percentage, }) return render(request, 'stats/statistics.html', context) No newline at end of file return render(request, 'admin/statistics.html', context) def has_add_permission(self, request): return False def has_change_permission(self, request, obj = None): return False def has_delete_permission(self, request, obj = None): return False admin.site.register(ElectionStats, ElectionStatsAdmin) No newline at end of file stats/apps.py +1 −0 Changes for stats/apps.py: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ from django.apps import AppConfig class StatsConfig(AppConfig): name = 'stats' verbose_name = 'Statystyki' No newline at end of file stats/models.py +7 −1 Changes for stats/models.py: 7 added lines, 1 removed line. Original line number Diff line number Diff line from django.db import models # Create your models here. from elections.models import Election class ElectionStats(Election): class Meta: proxy = True verbose_name = 'Przeglądaj' verbose_name_plural = 'Przeglądaj' No newline at end of file stats/templates/stats/live_results.html→stats/templates/admin/live_results.html +0 −0 File moved. View file Loading
elections/admin.py +1 −13 Changes for elections/admin.py: 1 added line, 13 removed lines. Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ class OptionInline(admin.TabularInline): extra = 1 class ElectionAdmin(admin.ModelAdmin): list_display = ['name', 'start_date', 'end_date', 'is_active_status', 'view_live_results', 'view_statistics'] list_display = ['name', 'start_date', 'end_date', 'is_active_status'] ordering = ['-created_at', '-updated_at'] exclude = ['invalid_votes', 'local_votes_entered'] Loading @@ -21,17 +21,5 @@ class ElectionAdmin(admin.ModelAdmin): def is_active_status(self, obj): return obj.is_active @admin.display(description='Aktualne wyniki') def view_live_results(self, obj): url = reverse('stats:live_results', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) @admin.display(description='Statystyki') def view_statistics(self, obj): if obj.is_active: return format_html('<span style="color: #999;">{}Dostępne po zakończeniu głosowania</span>', '') url = reverse('stats:statistics', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) # Register your models here. admin.site.register(Election, ElectionAdmin) No newline at end of file
stats/admin.py +53 −6 Changes for stats/admin.py: 53 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -2,15 +2,52 @@ from django.contrib import admin from django.shortcuts import render, get_object_or_404 from django.db.models import Count, Q from django.contrib.admin.views.decorators import staff_member_required from django.urls import reverse from django.utils.html import format_html from django.utils.safestring import mark_safe from django.urls import path from elections.models import Election from vote.models import Participation from voters.models import Voter, Group from .models import ElectionStats from elections.admin import OptionInline import re @staff_member_required def live_results(request, election_id): class ElectionStatsAdmin(admin.ModelAdmin): list_display = ['name', 'view_live_results', 'view_statistics'] ordering = ['-created_at', '-updated_at'] exclude = ['invalid_votes', 'local_votes_entered'] inlines = (OptionInline, ) @admin.display(description="Aktywne", boolean=True) def is_active_status(self, obj): return obj.is_active @admin.display(description='Aktualne wyniki') def view_live_results(self, obj): url = reverse('admin:live_results', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) @admin.display(description='Pełne statystyki') def view_statistics(self, obj): if obj.is_active: return mark_safe('<span style="color: #999;">Dostępne po zakończeniu głosowania</span>') url = reverse('admin:statistics', args=[obj.id]) return format_html('<a href={}>WYŚWIETL</a>', url) def get_urls(self): urls = super().get_urls() custom_urls = [ path('live-results/<int:election_id>', self.admin_site.admin_view(self.live_results_view), name='live_results'), path('statistics/<int:election_id>', self.admin_site.admin_view(self.statistics_view), name='statistics') ] return custom_urls + urls def live_results_view(self, request, election_id): context = admin.site.each_context(request) context.update({ Loading @@ -18,10 +55,9 @@ def live_results(request, election_id): 'title' : 'Wyniki na żywo' }) return render(request, 'stats/live_results.html', context) return render(request, 'admin/live_results.html', context) @staff_member_required def statistics(request, election_id): def statistics_view(self, request, election_id): election = get_object_or_404(Election, id=election_id) context = admin.site.each_context(request) Loading Loading @@ -81,4 +117,15 @@ def statistics(request, election_id): 'stationary_percentage': stationary_percentage, }) return render(request, 'stats/statistics.html', context) No newline at end of file return render(request, 'admin/statistics.html', context) def has_add_permission(self, request): return False def has_change_permission(self, request, obj = None): return False def has_delete_permission(self, request, obj = None): return False admin.site.register(ElectionStats, ElectionStatsAdmin) No newline at end of file
stats/apps.py +1 −0 Changes for stats/apps.py: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,3 +3,4 @@ from django.apps import AppConfig class StatsConfig(AppConfig): name = 'stats' verbose_name = 'Statystyki' No newline at end of file
stats/models.py +7 −1 Changes for stats/models.py: 7 added lines, 1 removed line. Original line number Diff line number Diff line from django.db import models # Create your models here. from elections.models import Election class ElectionStats(Election): class Meta: proxy = True verbose_name = 'Przeglądaj' verbose_name_plural = 'Przeglądaj' No newline at end of file
stats/templates/stats/live_results.html→stats/templates/admin/live_results.html +0 −0 File moved. View file