home

Change status message to a static one for the day

Author
Maarten 'Vngngdn' Vangeneugden
Date
July 8, 2017, 6:01 a.m.
Hash
a34b2c17ca7fd323e9d456f51e6ad96b2e7450c3
Parent
8916b9a670a81e91ae8a21509d73bce6ace5bfc9
Modified file
views.py

views.py

4 additions and 0 deletions.

View changes Hide changes
1
1
from datetime import date
2
2
from django.utils import timezone
3
3
from django.shortcuts import get_object_or_404, render # This allows to render the template with the view here. It's pretty cool and important.
4
4
from django.http import HttpResponseRedirect, HttpResponse # Why?
5
5
from django.core.urlresolvers import reverse # Why?
6
6
from django.utils.translation import ugettext as _
7
7
from .models import *
8
8
9
9
# First, I list some standard variables that are common for most of the sites of this app.
10
10
11
11
def get_age():
12
12
    """Returns my current age."""
13
13
    today = date.today()
14
14
    birthday = date(1996, 8, 28)
15
15
    age = today - birthday
16
16
    years = str(int(age.days / 365))
17
17
    return years
18
18
19
19
def footer_description():
20
20
    years = get_age()
21
21
22
22
    """
23
23
    Grandpa easter egg: The Dutch version of the most ingenius algorithm I ever wrote:
24
24
    vandaag = datum.vandaag()
25
25
    geboortedatum = datum(28-08-1996)
26
26
    leeftijd = vandaag - geboortedatum
27
27
    jaren = leeftijd.jaren()
28
28
    This will help me explain what programming has brought me. =3
29
29
    """
30
30
31
31
    return "Main pages of Maarten's website, a " + years + " year old Belgian programmer. Also an undergraduate informatics student @ UHasselt."
32
32
33
33
def footer_links():
34
34
    footer_links = [
35
35
            ["Contact", "mailto:maarten.vangeneugden@student.uhasselt.be"],
36
36
            ["UHasselt", "https://www.uhasselt.be"],
37
37
            ]
38
38
    return footer_links
39
39
40
40
# TODO: Move this stuff to the template module. This is basically a description
41
41
# of HOW to display data, but the view module is only responsible for WHAT data
42
42
# to display.
43
43
def standard_context():
44
44
    context = {
45
45
            'materialDesign_color': "blue",
46
46
            'materialDesign_accentColor': "orange",
47
47
            'navbar_backArrow': True,
48
48
            'footer_title': "Home pages",
49
49
            'footer_description': footer_description(),
50
50
            'footer_links': footer_links(),
51
51
            }
52
52
    return context
53
53
54
54
def get_current_status(dt = None):
55
55
    """Returns a string specifying my current state (and sometimes location).
56
56
57
57
    This function is actually based on my weekly schedule. I'd normally hook it
58
58
    up to my iCal files, but that doesn't include things like sleeping. Not to
59
59
    mention my university has a hard time following standards like "Put the
60
60
    location in the location field, not in the title of the appointment". I
61
61
    figured a simple function would do the job just as well.
62
62
    
63
63
    Keyword arguments:
64
64
    dt -- The datetime object of the day to check (defaults to current local time)
65
65
    """
66
66
67
67
    """ Readable standard schedule of my week (00:00 - 08:00 is always sleep):
68
68
    Monday:
69
69
        09:00 - 11:30: Mathematics @ C104
70
70
        13:00 - 15:00: Informatics Management @ A101
71
71
    Tuesday:
72
72
        10:00 - 11:30: Computer Graphics @ C105
73
73
        13:30 - 15:30: AI @ H1
74
74
    Wednesday: Free!
75
75
    Thursday:
76
76
        10:00 - 12:00: Software Engineering @ A7 (Temporary; prone to change!)
77
77
        13:00 - 15:00: Beleidsinformatica @ <variable>
78
78
    Friday - Sunday: Free!
79
79
    On free days, the planning is usually this:
80
80
    14:00 - 19:00: Studying / general work
81
81
    20:00 - 23:59: Leisure =D
82
82
83
83
    Temporary addition: My lovely nightfox <3
84
84
    Friday:
85
85
        17:30 - 23:59: Time with Jonathan
86
86
    """
87
87
    
88
88
    if dt == None:
+
89
    return _("Good morning my love. How do you like it? I'll be with you soon
+
90
    enough again... ❤❤")
+
91
    
+
92
    if dt == None:
89
93
        timezone.activate("Europe/Brussels")
90
94
        dt = timezone.localtime(timezone.now())
91
95
92
96
    day = dt.weekday()
93
97
    hour = dt.time().hour
94
98
    print(hour)
95
99
    minute = dt.time().minute
96
100
97
101
    """ Note on usage of the range() function:
98
102
    range(x, y) returns a list, beginning from x, but excluding y. So if a
99
103
    course runs from 13:00 to 15:00, then y should still be 15. Why? Because
100
104
    that makes it so that 14:59 is included, but 15:00 is not. if y would be 16,
101
105
    then 15:30 would also be included.
102
106
    """
103
107
104
108
    if day == 4:  # Friday... <3
105
109
        if hour >= 17:
106
110
            return _("❤ Spending time with someone very special... ❤")
107
111
    if day == 5:
108
112
        return _("I'm in love. Best thing that ever happened to me... ❤")
109
113
110
114
111
115
    if day == 0:  # Monday
112
116
        if hour in [9, 10] or (hour == 11 and minute <= 30):
113
117
            return _("Studying Mathematics @ C104. See you around noon!")
114
118
        if hour in range(13, 15):
115
119
            return _("Following college: Informatics Management @ A101.")
116
120
    if day == 1:  # Tuesday
117
121
        if hour == 10 or (hour == 11 and minute <= 30):
118
122
            return _("Studying Computer Graphics @ C105. Back in C24 at noon!")
119
123
        if (hour == 13 and minute >= 30) or \
120
124
           (hour == 14) or \
121
125
           (hour == 15 and minute < 30):
122
126
            return _("Trying to understand Artificial Intelligence @ H1...")
123
127
    if day == 3:  # Thursday
124
128
        if hour in range(10, 12):
125
129
            return _("Engineering the Software @ A7. Tough nut to crack...")
126
130
        if hour in range(13, 15):
127
131
            return _("Fighting boredom of Informatics Management. Looking \
128
132
            forward to the weekend!")
129
133
130
134
    # General answers that span over multiple days
131
135
    # They may overlap with previous tests, but that means they fill in gaps
132
136
    # like study time
133
137
    if hour <= 8:
134
138
        return _("I'm asleep. See you tomorrow! =D")
135
139
    if day in [0, 1, 3]:
136
140
        if hour == 12:
137
141
            return _("Having lunch in C24. I'm available if you need me!")
138
142
        elif hour in range(9, 18):
139
143
            return _("At UHasselt! Studying in C24. Come by for a chat, or email me!")
140
144
    if day in [2, 4, 5, 6]:
141
145
        if hour in range(13, 19):
142
146
            return _("Studying from home, or other work. Perhaps I'll see you in the evening?")
143
147
        elif hour in range(19, 24):
144
148
            #return _("Relaxing, and enjoying my free time. Feel free to talk! 😃")
145
149
            return _("Relaxing, and enjoying my free time. Feel free to talk! 😃")
146
150
147
151
    # If nothing's returned by now, return a general response
148
152
    return _("Probably chilling a bit. Feel free to talk! ❤")
149
153
150
154
# Views:
151
155
152
156
def index(request):
153
157
    timezone.activate("Europe/Brussels")
154
158
    time_string = timezone.localtime(timezone.now()).strftime(" (%H:%M) ")
155
159
    status = _("Current status/location:") + time_string + get_current_status()
156
160
    template = "about/index.html"
157
161
158
162
    cards = Card.objects.order_by('?') # The '?' indicates the objects must be ordered randomly.
159
163
    quotes = Quote.objects.all()
160
164
    randomQuote = random.choice(quotes)
161
165
162
166
    largeSizes = []
163
167
    mediumSizes = []
164
168
    for i in range(0, len(cards)):
165
169
        newLargeSizes = [6, 4, 2]
166
170
        newMediumSizes = [8, 4]
167
171
        random.shuffle(newLargeSizes)
168
172
        random.shuffle(newMediumSizes)
169
173
        largeSizes.extend(newLargeSizes)
170
174
        mediumSizes.extend(newMediumSizes)
171
175
172
176
    contextList = []
173
177
    i = 0
174
178
    for card in cards:
175
179
        contextList.append([card, mediumSizes[i], largeSizes[i]])
176
180
        i += 1
177
181
178
182
    # TODO: Move this stuff to the template module. This is basically a description
179
183
    # of HOW to display data, but the view module is only responsible for WHAT data
180
184
    # to display.
181
185
    context = {
182
186
            'status': status,
183
187
            'materialDesign_color': "blue",
184
188
            'materialDesign_accentColor': "orange",
185
189
            'navbar_title': "Maarten's website",
186
190
            'navbar_fixed': False,
187
191
            'parallax_src': "<img style=\"width:100vw;\" src=\"/media/about/images/parallax.png\">",
188
192
            'footer_title': "Home pages",
189
193
            'footer_description': footer_description,
190
194
            'footer_links': footer_links,
191
195
            'cards': contextList,
192
196
            'quote': randomQuote,
193
197
            }
194
198
195
199
    return render(request, template, context)
196
200
197
201
def myself(request):
198
202
    template = "about/about.html"
199
203
 
200
204
    context = {
201
205
            'subject': "Myself",
202
206
            'navbar_title': "Myself",
203
207
            'age': get_age(),
204
208
            }
205
209
    context.update(standard_context())
206
210
    return render(request, template, context)
207
211
208
212
def principles(request):
209
213
    template = "about/principles.html"
210
214
 
211
215
    data = Principle.objects.order_by('title')
212
216
213
217
    context = {
214
218
            'subject': "principles",
215
219
            'navbar_title': "Principles",
216
220
            'data': data,
217
221
            }
218
222
    context.update(standard_context())
219
223
    return render(request, template, context)
220
224
    
221
225
def hacking(request):
222
226
    template = "about/hacking.html"
223
227
 
224
228
    data = Hack.objects.order_by('title')
225
229
226
230
    context = {
227
231
            'subject': "hacking",
228
232
            'navbar_title': "Hacking",
229
233
            'data': data,
230
234
            }
231
235
    context.update(standard_context())
232
236
    return render(request, template, context)
233
237
    
234
238
def me(request):
235
239
    template = "about/me.html"
236
240
237
241
    data = AboutMe.objects.order_by('title')
238
242
239
243
    context = {
240
244
            'subject': "me",
241
245
            'navbar_title': "Me",
242
246
            'data': data,
243
247
            }
244
248
    context.update(standard_context())
245
249
    return render(request, template, context)
246
250
247
251
def webstack(request):
248
252
    template = "about/webstack.html"
249
253
 
250
254
    data = Stack.objects.order_by('title')
251
255
252
256
    context = {
253
257
            'subject': "web stack",
254
258
            'navbar_title': "Web stack",
255
259
            'data': data,
256
260
            }
257
261
    context.update(standard_context())
258
262
    return render(request, template, context)
259
263
    
260
264
def software(request):
261
265
    template = "about/software.html"
262
266
 
263
267
    data = Program.objects.order_by('title')
264
268
265
269
    context = {
266
270
            'subject': "software",
267
271
            'navbar_title': "Software",
268
272
            'data': data,
269
273
            }
270
274
    context.update(standard_context())
271
275
    return render(request, template, context)
272
276
    # WARNING:
273
277
    # Because I haven't been able to figure out yet how to add colors to hyperlinks, I put them hardcoded in the database. IF YOU FIND A WAY TO DO IT RIGHT, DO SO ASAP!
274
278
275
279
def security(request):
276
280
    template = "about/security.html"
277
281
 
278
282
    data = SecurityMeasure.objects.order_by('title')
279
283
280
284
    context = {
281
285
            'subject': "security",
282
286
            'navbar_title': "Security",
283
287
            'data': data,
284
288
            }
285
289
    context.update(standard_context())
286
290
    return render(request, template, context)
287
291
 
288
292
def roadmap(request):
289
293
    template = "about/roadmap.html"
290
294
 
291
295
    data = Goal.objects.order_by('title')
292
296
293
297
    context = {
294
298
            'subject': "roadmap",
295
299
            'navbar_title': "Roadmap",
296
300
            'data': data,
297
301
            }
298
302
    context.update(standard_context())
299
303
    return render(request, template, context)
300
304
 
301
305