Commit d0501fe0 authored by stammy31's avatar stammy31

Apply change: peer-->peers to admin site

parent 0510c9a3
......@@ -28,8 +28,15 @@ from accounts.models import UserProfile
class UserPrAdmin(admin.ModelAdmin):
search_fields = ['user__username', 'peer__peer_name']
list_display = ('user', 'peer')
search_fields = ['user__username']
list_display = ('username', 'get_userprofile_peers')
def get_userprofile_peers(self, instance):
# instance is User instance
peers = instance.peers.all()
return ''.join(('%s, ' % (peer.peer_name)) for peer in peers)[:-2]
get_userprofile_peers.short_description = "User Peer(s)"
admin.site.register(UserProfile, UserPrAdmin)
......
......@@ -25,15 +25,18 @@ from peers.models import Peer
class UserProfile(models.Model):
user = models.OneToOneField(User)
peer = models.ForeignKey(Peer)
peers = models.ManyToManyField(Peer, related_name='peer_info')
peers = models.ManyToManyField(Peer, related_name='user_profile')
class Meta:
permissions = (
("overview", "Can see registered users and rules"),
)
def username(self):
return "%s" % (self.user.username)
def __unicode__(self):
return "%s:%s" % (self.user.username, self.peer.peer_name)
return self.username()
def get_address_space(self):
networks = self.domain.networks.all()
......
......@@ -51,7 +51,7 @@ class RouteAdmin(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
list_display = ('name', 'status', 'applier', 'applier_peer', 'get_match', 'get_then', 'response', "expires", "comments")
list_display = ('name', 'status', 'applier_username', 'applier_peers', 'get_match', 'get_then', 'response', "expires", "comments")
fieldsets = [
(None, {'fields': ['name', 'applier']}),
......@@ -73,7 +73,7 @@ class UserProfileAdmin(UserAdmin):
add_form = UserCreationForm
form = UserChangeForm
actions = ['deactivate', 'activate']
list_display = ('username', 'email', 'first_name' , 'last_name', 'is_staff', 'is_active', 'is_superuser', 'get_userprofile_peer')
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'is_active', 'is_superuser', 'get_userprofile_peers')
inlines = [UserProfileInline]
def deactivate(self, request, queryset):
......@@ -84,10 +84,12 @@ class UserProfileAdmin(UserAdmin):
queryset = queryset.update(is_active=True)
activate.short_description = "Activate Selected Users"
def get_userprofile_peer(self, instance):
def get_userprofile_peers(self, instance):
# instance is User instance
return instance.get_profile().peer
get_userprofile_peer.short_description = "User Peer"
peers = instance.get_profile().peers.all()
return ''.join(('%s, ' % (peer.peer_name)) for peer in peers)[:-2]
get_userprofile_peers.short_description = "User Peer(s)"
# fields = ('name', 'applier', 'expires')
#def formfield_for_dbfield(self, db_field, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment