1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
import datetime
import os
from django.utils import timezone
from django.contrib.gis.db import models
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.urls import reverse
from django.apps import apps
from django.conf import settings
from django.contrib.sitemaps import Sitemap
from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image
def get_upload_path(self, filename):
return "images/post-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
class GTDOutcome(models.Model):
title = models.CharField(max_length=300)
body_markdown = models.TextField()
body_html = models.TextField(blank=True)
date_goal = models.DateField(blank=True, null=True)
date_ended = models.DateField(blank=True, null=True)
def __str__(self):
return self.title
class Meta:
ordering = ('-date_goal',)
def get_absolute_url(self):
return reverse('gtd:outcome-detail', kwargs={"pk": self.pk})
def save(self, *args, **kwargs):
created = self.pk is None
if not created:
md = render_images(self.body_markdown)
self.body_html = markdown_to_html(md)
super(GTDOutcome, self).save(*args, **kwargs)
class GTDProject(models.Model):
PROJECT_TYPE = (
(0, 'wired'),
(1, 'lbh'),
(2, 'personal'),
(3, 'lxf'),
)
title = models.CharField(max_length=200)
short_title = models.CharField(max_length=200, blank=True, null=True)
body_markdown = models.TextField(null=True, blank=True)
body_html = models.TextField(blank=True)
date_goal = models.DateField(blank=True, null=True)
date_ended = models.DateField(blank=True, null=True)
project_type = models.IntegerField(choices=PROJECT_TYPE, default=2)
outcome = models.ForeignKey(GTDOutcome, on_delete=models.SET_NULL, null=True, blank=True)
class Meta:
ordering = ('-date_goal',)
get_latest_by = 'date_goal'
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('gtd:project-detail', kwargs={"pk": self.id})
@property
def get_previous_admin_url(self):
n = self.get_previous_by_date_goal()
return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] )
@property
def get_next_admin_url(self):
model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
try:
return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_date_goal().pk] )
except model.DoesNotExist:
return ''
def save(self, *args, **kwargs):
created = self.pk is None
if not created:
md = render_images(self.body_markdown)
self.body_html = markdown_to_html(md)
super(GTDProject, self).save(*args, **kwargs)
class NoteType(models.IntegerChoices):
ACTION = 0, ('action')
REMINDER = 1, ('reminder')
REFERENCE = 2, ('reference')
class GTDNote(models.Model):
title = models.CharField(max_length=200)
body_markdown = models.TextField(null=True, blank=True)
body_html = models.TextField(blank=True)
date_completed = models.DateField(null=True, blank=True)
date_created = models.DateTimeField(auto_now=True)
note_type = models.IntegerField(choices=NoteType.choices, default=NoteType.ACTION)
reminder = models.BigIntegerField(help_text="In days", null=True, blank=True)
project = models.ForeignKey(GTDProject, on_delete=models.SET_NULL, null=True, blank=True)
STATUS = (
(0, 'None'),
(1, 'Open'),
(2, 'Completed'),
)
status = models.IntegerField(choices=STATUS, default=0)
class Meta:
ordering = ('-date_created',)
get_latest_by = 'date_created'
def __str__(self):
return self.title
def get_absolute_url(self, *args, **kwargs):
return reverse('gtd:note-edit', kwargs={"pk": self.pk})
def save(self, *args, **kwargs):
self.body_html = markdown_to_html(self.body_markdown)
super(GTDNote, self).save(*args, **kwargs)
class PostType(models.IntegerChoices):
REVIEW = 0, ('review')
GUIDE = 1, ('guide')
HOWTO = 2, ('how-to')
class TemplateType(models.IntegerChoices):
STORY = 0, ('story')
GALLERY = 1, ('gallery')
class PostStatus(models.IntegerChoices):
ASSIGNED = 0, ('Assigned')
TURNEDIN = 1, ('turned in')
PUBLISHED = 2, ('published')
class WiredPost(models.Model):
# an entry in a feed
title = models.CharField(max_length=512, blank=True, null=True)
body = models.TextField(blank=True, null=True)
url = models.CharField(max_length=512, blank=True, null=True)
edit_url = models.CharField(max_length=512, blank=True, null=True)
date_last_pub = models.DateField(blank=True, null=True)
guid = models.CharField(max_length=512, blank=True, null=True, db_index=True)
author = models.CharField(max_length=255, blank=True, null=True)
post_type = models.IntegerField(choices=PostType.choices, default=PostType.GUIDE)
template_type = models.IntegerField(choices=TemplateType.choices, default=TemplateType.STORY)
update_frequency = models.BigIntegerField(help_text="In days")
#products = models.ManyToManyField(ProductLink, blank=True, null=True)
needs_update = models.BooleanField(default=False)
is_live = models.BooleanField(default=True)
post_status = models.IntegerField(choices=PostStatus.choices, default=PostStatus.PUBLISHED)
class Meta:
ordering = ('date_last_pub',)
def __str__(self):
return self.title
def time_since_update(self):
td = datetime.date.today() - self.date_last_pub
return int(td.days)
#def get_needs_update(self):
# if self.time_since_update() > self.update_frequency:
# return True
# else:
# return False
def days_overdue(self):
if self.needs_update == True:
return self.time_since_update() - self.update_frequency
else:
return 0
def admin_url(self):
return format_html('<a target="_blank" href="%s">%s</a>' % (self.url, self.url))
admin_link.short_description = 'Link'
def get_absolute_url(self):
return reverse('gtd:wiredpost-detail', kwargs={"pk": self.id})
def save(self, *args, **kwargs):
if self.date_last_pub:
td = timezone.localdate() - self.date_last_pub
if td.days > self.update_frequency and self.post_status != 1:
self.needs_update = True
else:
self.needs_update = False
super(WiredPost, self).save()
class WiredNote(models.Model):
title = models.CharField(max_length=400)
url = models.CharField(max_length=400, blank=True, null=True)
body_markdown = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(default=timezone.now)
post = models.ForeignKey(WiredPost, on_delete=models.CASCADE, null=True, blank=True)
STATUS = (
(0, 'Call In'),
(1, 'Asked For'),
(2, 'Coming'),
(3, 'Testing'),
(4, 'Done'),
(5, 'Live'),
)
status = models.IntegerField(choices=STATUS, default=0)
PLAN = (
(0, 'For Guide'),
(1, 'Review'),
(2, 'Rave/Rant'),
(3, 'No Plan'),
)
plan = models.IntegerField(choices=PLAN, default=0)
class Meta:
ordering = ('date_created', 'status')
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('gtd:wirednote-edit', kwargs={"pk": self.pk})
def save(self, *args, **kwargs):
super(WiredNote, self).save()
|