cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
key.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.clm.models.key
22 # @author Tomek Sośnicki <tom.sosnicki@gmail.com>
23 # @author Maciej Nabożny <di.dijo@gmail.com>
24 #
25 
26 from django.db import models
27 from clm.models.user import User
28 from datetime import datetime
29 
30 
31 ##
32 #
33 # @model{KEY}
34 # Key is responsible for public RSA key file. CTX mechanizm of CC1 enables
35 # an injection of such a file.
36 #
37 class Key(models.Model):
38  ## this Key's owner @field
39  user = models.ForeignKey(User)
40  ## this Key's human-friendly name @field
41  name = models.CharField(max_length=45)
42  ## this Key's fingerprint @field
43  fingerprint = models.CharField(max_length=47)
44  ## content of this Key @field
45  data = models.TextField()
46  ## creation date @field
47  creation_date = models.DateTimeField(default=datetime.now)
48 
49  class Meta:
50  app_label = 'clm'
51 
52  ##
53  #
54  # @returns name of this Key
55  #
56  def __unicode__(self):
57  return self.name
58 
59  @property
60  ##
61  #
62  # @returns{dict} this Key's data
63  # \n fields:
64  # @dictkey{key_id,int} id of this Key
65  # @dictkey{name,string} this Key's name
66  # @dictkey{data,string} this Key's content
67  # @dictkey{fingerprint,string} this Key's fingerprint
68  # @dictkey{creation_date,datetime.datetime} date when this Key was created
69  #
70  def dict(self):
71  d = {}
72  d['key_id'] = self.id
73  d['name'] = self.name
74  d['data'] = self.data
75  d['fingerprint'] = self.fingerprint
76  d['creation_date'] = self.creation_date
77  return d
78