Mercurial > public > sg101
comparison downloads/models.py @ 1023:a5ebc74dc3f3
Perform image_check on downloads.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 10 Dec 2015 20:57:50 -0600 |
parents | 3e1905e523be |
children | 5ba2508939f7 |
comparison
equal
deleted
inserted
replaced
1022:82f1f6f905eb | 1023:a5ebc74dc3f3 |
---|---|
67 try: | 67 try: |
68 return filesizeformat(self.file.size) | 68 return filesizeformat(self.file.size) |
69 except OSError: | 69 except OSError: |
70 return '?' | 70 return '?' |
71 | 71 |
72 def save(self, *args, **kwargs): | |
73 if not self.pk: | |
74 self.date_added = datetime.datetime.now() | |
75 self.update_date = self.date_added | |
76 else: | |
77 self.update_date = datetime.datetime.now() | |
78 | |
79 self.html = kwargs.pop('html', None) | |
80 if not self.html and self.description: | |
81 self.html = site_markup(self.description) | |
82 super(DownloadBase, self).save(*args, **kwargs) | |
83 | |
72 | 84 |
73 class PendingDownload(DownloadBase): | 85 class PendingDownload(DownloadBase): |
74 """This model represents pending downloads created by users. These pending | 86 """This model represents pending downloads created by users. These pending |
75 downloads must be approved by an admin before they turn into "real" | 87 downloads must be approved by an admin before they turn into "real" |
76 Downloads and are visible on site. | 88 Downloads and are visible on site. |
78 class Meta: | 90 class Meta: |
79 ordering = ('date_added', ) | 91 ordering = ('date_added', ) |
80 | 92 |
81 def __unicode__(self): | 93 def __unicode__(self): |
82 return self.title | 94 return self.title |
83 | |
84 def save(self, *args, **kwargs): | |
85 if not self.pk: | |
86 self.date_added = datetime.datetime.now() | |
87 self.update_date = self.date_added | |
88 else: | |
89 self.update_date = datetime.datetime.now() | |
90 | |
91 self.html = site_markup(self.description) | |
92 super(PendingDownload, self).save(*args, **kwargs) | |
93 | 95 |
94 | 96 |
95 class Download(DownloadBase): | 97 class Download(DownloadBase): |
96 """Model to represent a download.""" | 98 """Model to represent a download.""" |
97 hits = models.IntegerField(default=0) | 99 hits = models.IntegerField(default=0) |
107 return self.title | 109 return self.title |
108 | 110 |
109 @models.permalink | 111 @models.permalink |
110 def get_absolute_url(self): | 112 def get_absolute_url(self): |
111 return ('downloads-details', [str(self.id)]) | 113 return ('downloads-details', [str(self.id)]) |
112 | |
113 def save(self, *args, **kwargs): | |
114 if not self.pk: | |
115 self.date_added = datetime.datetime.now() | |
116 self.update_date = self.date_added | |
117 else: | |
118 self.update_date = datetime.datetime.now() | |
119 | |
120 self.html = site_markup(self.description) | |
121 super(Download, self).save(*args, **kwargs) | |
122 | 114 |
123 def vote(self, vote_value): | 115 def vote(self, vote_value): |
124 """receives a vote_value and updates internal score accordingly""" | 116 """receives a vote_value and updates internal score accordingly""" |
125 total_score = self.average_score * self.total_votes | 117 total_score = self.average_score * self.total_votes |
126 total_score += vote_value | 118 total_score += vote_value |