Schule als Staat Projekt Web, Dokumente, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 line
2.6KB

  1. from django.contrib import admin
  2. from .models import Betrieb, Partei, PresidentCandidate, Question
  3. from startpage.models import Banned
  4. from django.contrib.admin import helpers
  5. from django.shortcuts import render
  6. from django.template.defaulttags import register
  7. @register.filter
  8. def get_item(dictionary, key):
  9. return dictionary.get(key)
  10. def ban_ip(modeladmin, request, queryset):
  11. for obj in queryset:
  12. banned = Banned(ip_address=obj.ip_address,
  13. reason="")
  14. banned.save()
  15. modeladmin.message_user(request, "Ausgewählte Urheber erfolgreich verbannt.")
  16. ban_ip.short_description = "Urheber ausgewählter Eintrage verbannen"
  17. def create_overview(modeladmin, request, queryset):
  18. if request.POST.get('back'):
  19. pass
  20. else:
  21. raummap = {}
  22. for b in queryset:
  23. if b.raum in raummap:
  24. raummap[b.raum]["anzahl"] += 1
  25. raummap[b.raum]["belegung"] += b.raumforderung
  26. else:
  27. raummap[b.raum] = {"anzahl": 1, "belegung": b.raumforderung}
  28. context = {'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
  29. 'betriebe': queryset,
  30. 'arbeitnehmer_gesamt': sum([b.arbeitnehmerzahl for b in
  31. queryset]),
  32. 'raummap': raummap,
  33. 'title': "Betriebsübersicht",
  34. 'kreditgesamt': sum([b.kredit for b in queryset])}
  35. return render(request, 'meingoethopia/betriebe_overview.html', context)
  36. create_overview.short_description = "Übersicht erstellen"
  37. # Register your models here.
  38. class BetriebAdmin(admin.ModelAdmin):
  39. list_display = ('name', 'manager', 'aufsicht', 'raum',
  40. 'arbeitnehmerzahl_kurz', 'confirmed',
  41. 'approved')
  42. list_filter = ('confirmed', 'approved', 'raum')
  43. search_fields = ('name', 'manager', 'raum', 'aufsicht')
  44. actions = [ban_ip, create_overview]
  45. class ParteiAdmin(admin.ModelAdmin):
  46. list_display = ('name', 'abbreviation', 'chef', 'description', 'confirmed',
  47. 'approved')
  48. list_filter = ('confirmed', 'approved')
  49. actions = [ban_ip]
  50. class PresidentAdmin(admin.ModelAdmin):
  51. list_display = ('name', 'confirmed', 'approved')
  52. list_filter = ('confirmed', 'approved')
  53. actions = [ban_ip]
  54. class QuestionAdmin(admin.ModelAdmin):
  55. list_display = ('subject', 'answered')
  56. list_filter = ('answered',)
  57. actions = [ban_ip]
  58. admin.site.register(Betrieb, BetriebAdmin)
  59. admin.site.register(Partei, ParteiAdmin)
  60. admin.site.register(PresidentCandidate, PresidentAdmin)
  61. admin.site.register(Question, QuestionAdmin)