Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enhance ApiToken admin #157

Merged
merged 1 commit into from

3 participants

@bruth
Owner

No description provided.

@coveralls

Coverage Status

Coverage decreased (-0.55%) when pulling f610443 on issue-156 into 1325089 on 2.3.

@naegelyd naegelyd merged commit 85b1091 into from
@naegelyd naegelyd deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2014
  1. @bruth
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 3 deletions.
  1. +17 −1 serrano/admin.py
  2. +2 −2 serrano/models.py
View
18 serrano/admin.py
@@ -1,4 +1,20 @@
from django.contrib import admin
from .models import ApiToken
-admin.site.register(ApiToken)
+
+class ApiTokenAdmin(admin.ModelAdmin):
+ list_display = ('user', 'token', 'revoked', 'created')
+ list_editable = ('revoked',)
+ list_filter = ('user', 'revoked')
+ fields = ('user', 'token_display', 'revoked')
+ readonly_fields = ('token_display',)
+
+ def token_display(self, instance):
+ if instance.pk:
+ return instance.token
+ return '<em>(displayed once saved)</em>'
+
+ token_display.short_description = 'Token'
+ token_display.allow_tags = True
+
+admin.site.register(ApiToken, ApiTokenAdmin)
View
4 serrano/models.py
@@ -19,7 +19,7 @@ def get_active_token(self, token):
class ApiToken(models.Model):
"Token for use as authentication for API access."
user = models.ForeignKey(User)
- token = models.CharField(max_length=32)
+ token = models.CharField(max_length=32, editable=False)
revoked = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
@@ -35,4 +35,4 @@ def __unicode__(self):
def save(self, *args, **kwargs):
if not self.token:
self.token = generate_random_token(32, test=unique_token)
- return super(self.__class__, self).save(*args, **kwargs)
+ return super(ApiToken, self).save(*args, **kwargs)
Something went wrong with that request. Please try again.