Skip to content

Commit

Permalink
Merge pull request #79 from RadicalxChange/group-admins
Browse files Browse the repository at this point in the history
Group admins
  • Loading branch information
alexrandaccio authored Dec 2, 2021
2 parents 1ae46d6 + e1a4df3 commit 5288ccf
Show file tree
Hide file tree
Showing 107 changed files with 3,502 additions and 2,615 deletions.
54 changes: 34 additions & 20 deletions backend/RxcVoiceApi/main/admin.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
from django.contrib import admin
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
from guardian.shortcuts import assign_perm
import uuid

from .models import (Election, Proposal, Delegate, Process, Conversation, Transfer, MatchPayment)
from .models import (Vote, Stage, Election, Proposal, Delegate, Profile, Process, Conversation, Delegation, Transfer, MatchPayment)
from .signals import send_register_mail

class ElectionAdmin(admin.ModelAdmin):
list_display = ['id','title','start_date','end_date']

def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
class StageChildAdmin(PolymorphicChildModelAdmin):
# base admin class for all child models
base_model = Stage

def save_related(self, request, form, formsets, change):
super(ElectionAdmin, self).save_related(request, form, formsets, change)
for group in form.instance.groups.all():
assign_perm('can_vote', group, form.instance)

class StageParentAdmin(PolymorphicParentModelAdmin):
# parent model base admin
base_model = Stage
child_models = (Delegation, Conversation, Election)

class ConversationAdmin(admin.ModelAdmin):
list_display = ['id','title','start_date','end_date']

def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
if not change:
form.instance.uuid = str(uuid.uuid1())
form.instance.save()
class DelegationAdmin(StageChildAdmin):
base_model = Delegation
list_display = ['id', 'title', 'start_date', 'end_date', 'process', 'position', 'matching_pool', 'allow_transfers', 'allow_invites', 'num_credits']


class ConversationAdmin(StageChildAdmin):
base_model = Conversation
list_display = ['id', 'title', 'start_date', 'end_date', 'process', 'position', 'show_report', 'report_id']


class ElectionAdmin(StageChildAdmin):
base_model = Election
list_display = ['id', 'title', 'start_date', 'end_date', 'process', 'position', 'negative_votes']


class ProfileAdmin(admin.ModelAdmin):
list_display = ['id','user','public_username','is_verified']


class DelegateAdmin(admin.ModelAdmin):
list_display = ['id','user','public_username','is_verified','credit_balance','invited_by']
list_display = ['id','profile','credit_balance','invited_by']


class TransferAdmin(admin.ModelAdmin):
list_display = ['id','sender','recipient','amount','date','status','process']
list_display = ['id','sender','recipient','amount','date','status', 'delegation']


class ProcessAdmin(admin.ModelAdmin):
list_display = ['id','title','start_date','end_date','matching_pool','status']
list_display = ['id','title','start_date','end_date']


class ProposalAdmin(admin.ModelAdmin):
list_display = ['id','title','ballot_ratification','election']


class MatchPaymentAdmin(admin.ModelAdmin):
list_display = ['id','recipient','amount','date','process']
list_display = ['id','recipient','amount','date','delegation']


admin.site.register(Stage, StageChildAdmin)
admin.site.register(Delegation, DelegationAdmin)
admin.site.register(Election, ElectionAdmin)
admin.site.register(Vote)
admin.site.register(Proposal, ProposalAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(Delegate, DelegateAdmin)
admin.site.register(Process, ProcessAdmin)
admin.site.register(Conversation, ConversationAdmin)
Expand Down
Loading

0 comments on commit 5288ccf

Please sign in to comment.