home

Fix bug with viewport size setting

Author
Maarten 'Vngngdn' Vangeneugden
Date
July 8, 2017, 4:52 a.m.
Hash
8916b9a670a81e91ae8a21509d73bce6ace5bfc9
Parent
d9f44a8c0c40ad784a1e7b3eafeeeceeda453ea4
Modified file
views.py

views.py

1 addition and 1 deletion.

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
89
        timezone.activate("Europe/Brussels")
90
90
        dt = timezone.localtime(timezone.now())
91
91
92
92
    day = dt.weekday()
93
93
    hour = dt.time().hour
94
94
    print(hour)
95
95
    minute = dt.time().minute
96
96
97
97
    """ Note on usage of the range() function:
98
98
    range(x, y) returns a list, beginning from x, but excluding y. So if a
99
99
    course runs from 13:00 to 15:00, then y should still be 15. Why? Because
100
100
    that makes it so that 14:59 is included, but 15:00 is not. if y would be 16,
101
101
    then 15:30 would also be included.
102
102
    """
103
103
104
104
    if day == 4:  # Friday... <3
105
105
        if hour >= 17:
106
106
            return _("❤ Spending time with someone very special... ❤")
107
107
    if day == 5:
108
108
        return _("I'm in love. Best thing that ever happened to me... ❤")
109
109
110
110
111
111
    if day == 0:  # Monday
112
112
        if hour in [9, 10] or (hour == 11 and minute <= 30):
113
113
            return _("Studying Mathematics @ C104. See you around noon!")
114
114
        if hour in range(13, 15):
115
115
            return _("Following college: Informatics Management @ A101.")
116
116
    if day == 1:  # Tuesday
117
117
        if hour == 10 or (hour == 11 and minute <= 30):
118
118
            return _("Studying Computer Graphics @ C105. Back in C24 at noon!")
119
119
        if (hour == 13 and minute >= 30) or \
120
120
           (hour == 14) or \
121
121
           (hour == 15 and minute < 30):
122
122
            return _("Trying to understand Artificial Intelligence @ H1...")
123
123
    if day == 3:  # Thursday
124
124
        if hour in range(10, 12):
125
125
            return _("Engineering the Software @ A7. Tough nut to crack...")
126
126
        if hour in range(13, 15):
127
127
            return _("Fighting boredom of Informatics Management. Looking \
128
128
            forward to the weekend!")
129
129
130
130
    # General answers that span over multiple days
131
131
    # They may overlap with previous tests, but that means they fill in gaps
132
132
    # like study time
133
133
    if hour <= 8:
134
134
        return _("I'm asleep. See you tomorrow! =D")
135
135
    if day in [0, 1, 3]:
136
136
        if hour == 12:
137
137
            return _("Having lunch in C24. I'm available if you need me!")
138
138
        elif hour in range(9, 18):
139
139
            return _("At UHasselt! Studying in C24. Come by for a chat, or email me!")
140
140
    if day in [2, 4, 5, 6]:
141
141
        if hour in range(13, 19):
142
142
            return _("Studying from home, or other work. Perhaps I'll see you in the evening?")
143
143
        elif hour in range(19, 24):
144
144
            #return _("Relaxing, and enjoying my free time. Feel free to talk! 😃")
145
145
            return _("Relaxing, and enjoying my free time. Feel free to talk! 😃")
146
146
147
147
    # If nothing's returned by now, return a general response
148
148
    return _("Probably chilling a bit. Feel free to talk! ❤")
149
149
150
150
# Views:
151
151
152
152
def index(request):
153
153
    timezone.activate("Europe/Brussels")
154
154
    time_string = timezone.localtime(timezone.now()).strftime(" (%H:%M) ")
155
155
    status = _("Current status/location:") + time_string + get_current_status()
156
156
    template = "about/index.html"
157
157
158
158
    cards = Card.objects.order_by('?') # The '?' indicates the objects must be ordered randomly.
159
159
    quotes = Quote.objects.all()
160
160
    randomQuote = random.choice(quotes)
161
161
162
162
    largeSizes = []
163
163
    mediumSizes = []
164
164
    for i in range(0, len(cards)):
165
165
        newLargeSizes = [6, 4, 2]
166
166
        newMediumSizes = [8, 4]
167
167
        random.shuffle(newLargeSizes)
168
168
        random.shuffle(newMediumSizes)
169
169
        largeSizes.extend(newLargeSizes)
170
170
        mediumSizes.extend(newMediumSizes)
171
171
172
172
    contextList = []
173
173
    i = 0
174
174
    for card in cards:
175
175
        contextList.append([card, mediumSizes[i], largeSizes[i]])
176
176
        i += 1
177
177
178
178
    # TODO: Move this stuff to the template module. This is basically a description
179
179
    # of HOW to display data, but the view module is only responsible for WHAT data
180
180
    # to display.
181
181
    context = {
182
182
            'status': status,
183
183
            'materialDesign_color': "blue",
184
184
            'materialDesign_accentColor': "orange",
185
185
            'navbar_title': "Maarten's website",
186
186
            'navbar_fixed': False,
187
187
            'parallax_src': "<img style=\"height:100vw;\" src=\"/media/about/images/parallax.png\">",
188
-
            'footer_title': "Home pages",
+
188
            'footer_title': "Home pages",
189
189
            'footer_description': footer_description,
190
190
            'footer_links': footer_links,
191
191
            'cards': contextList,
192
192
            'quote': randomQuote,
193
193
            }
194
194
195
195
    return render(request, template, context)
196
196
197
197
def myself(request):
198
198
    template = "about/about.html"
199
199
 
200
200
    context = {
201
201
            'subject': "Myself",
202
202
            'navbar_title': "Myself",
203
203
            'age': get_age(),
204
204
            }
205
205
    context.update(standard_context())
206
206
    return render(request, template, context)
207
207
208
208
def principles(request):
209
209
    template = "about/principles.html"
210
210
 
211
211
    data = Principle.objects.order_by('title')
212
212
213
213
    context = {
214
214
            'subject': "principles",
215
215
            'navbar_title': "Principles",
216
216
            'data': data,
217
217
            }
218
218
    context.update(standard_context())
219
219
    return render(request, template, context)
220
220
    
221
221
def hacking(request):
222
222
    template = "about/hacking.html"
223
223
 
224
224
    data = Hack.objects.order_by('title')
225
225
226
226
    context = {
227
227
            'subject': "hacking",
228
228
            'navbar_title': "Hacking",
229
229
            'data': data,
230
230
            }
231
231
    context.update(standard_context())
232
232
    return render(request, template, context)
233
233
    
234
234
def me(request):
235
235
    template = "about/me.html"
236
236
237
237
    data = AboutMe.objects.order_by('title')
238
238
239
239
    context = {
240
240
            'subject': "me",
241
241
            'navbar_title': "Me",
242
242
            'data': data,
243
243
            }
244
244
    context.update(standard_context())
245
245
    return render(request, template, context)
246
246
247
247
def webstack(request):
248
248
    template = "about/webstack.html"
249
249
 
250
250
    data = Stack.objects.order_by('title')
251
251
252
252
    context = {
253
253
            'subject': "web stack",
254
254
            'navbar_title': "Web stack",
255
255
            'data': data,
256
256
            }
257
257
    context.update(standard_context())
258
258
    return render(request, template, context)
259
259
    
260
260
def software(request):
261
261
    template = "about/software.html"
262
262
 
263
263
    data = Program.objects.order_by('title')
264
264
265
265
    context = {
266
266
            'subject': "software",
267
267
            'navbar_title': "Software",
268
268
            'data': data,
269
269
            }
270
270
    context.update(standard_context())
271
271
    return render(request, template, context)
272
272
    # WARNING:
273
273
    # 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
274
275
275
def security(request):
276
276
    template = "about/security.html"
277
277
 
278
278
    data = SecurityMeasure.objects.order_by('title')
279
279
280
280
    context = {
281
281
            'subject': "security",
282
282
            'navbar_title': "Security",
283
283
            'data': data,
284
284
            }
285
285
    context.update(standard_context())
286
286
    return render(request, template, context)
287
287
 
288
288
def roadmap(request):
289
289
    template = "about/roadmap.html"
290
290
 
291
291
    data = Goal.objects.order_by('title')
292
292
293
293
    context = {
294
294
            'subject': "roadmap",
295
295
            'navbar_title': "Roadmap",
296
296
            'data': data,
297
297
            }
298
298
    context.update(standard_context())
299
299
    return render(request, template, context)
300
300
 
301
301