Made it work for users that already exist in database

This commit is contained in:
David Taylor
2015-04-19 17:28:22 +01:00
parent d0c44c921f
commit 9f902eabb6
2 changed files with 19 additions and 5 deletions

View File

@@ -16,8 +16,8 @@ from decimal import Decimal
class Profile(AbstractUser):
initials = models.CharField(max_length=5, unique=True, null=True, blank=False)
phone = models.CharField(max_length=13, null=True, blank=True)
api_key = models.CharField(max_length=40,blank=False,editable=True,default=lambda: make_api_key())
api_key = models.CharField(max_length=40,blank=True,editable=False, null=True)
@classmethod
def make_api_key(cls):
size=20

View File

@@ -43,7 +43,8 @@
<div class="pull-right">
<a href="{% url 'reset_api_key' %}" class="btn">
Reset API Key <span class="glyphicon glyphicon-repeat"></span>
{% if user.api_key %}Reset API Key{% else %}Generate API Key{% endif %}
<span class="glyphicon glyphicon-repeat"></span>
</a>
</div>
@@ -51,11 +52,24 @@
<dl class="dl-horizontal">
<dt>API Key</dt>
<dd>{{user.api_key}}</dd>
<dd>
{% if user.api_key %}
{{user.api_key}}
{% else %}
No API Key Generated
{% endif %}
</dd>
<dt>Calendar URL</dt>
<dd><pre>https://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}</pre></dd>
<dd>
{% if user.api_key %}
<pre>https://{{ request.get_host }}{% url 'ics_calendar' api_pk=user.pk api_key=user.api_key %}</pre>
{% else %}
<pre>No API Key Generated</pre>
{% endif %}
</dd>
</dl>
{% endif %}
</div>