-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
365 lines (302 loc) · 10.2 KB
/
views.py
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.views.generic import simple, list_detail
from django.http import Http404
from excurtion.models import Excurtion
from excurtion.models import PhotoPostExcurtion
from news.models import New
from cimblings.models import Cimbling
from customizedtravels.models import CustomizedTravel
from educationtravels.models import EducationTravel
from contacts.forms import ContactoForm
from contacts.models import ContactGroup
from datetime import datetime
from activities.models import Activitie
from userprofile.models import UserProfile, Logo
import time
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import get_object_or_404, render_to_response
from forms import UploadFileForm
from models import Video
def index(request):
object_list = Excurtion.objects.all()
incoming = object_list.filter(date__gte=datetime.now())[:10]
recent = object_list.filter(date__lt=datetime.now(), publish_last_exc=True)[:6]
news_news = New.objects.all()[:1]
list_videos = Video.objects.all()[:1]
return simple.direct_to_template(
request,
'index.html',
extra_context = {
'object_list': object_list,
'incoming': incoming,
'recent_excurtions': recent,
'news':news_news,
'list_videos':list_videos,
}
)
def activitie_detail(request,id):
obj = Activitie.objects.get(pk=int(id))
next_excurtion = Excurtion.objects.filter(activitie=obj.id,date__gte=datetime.now())
if len(next_excurtion)>0:
next_excurtion = next_excurtion[0]
else:
next_excurtion = None
return simple.direct_to_template(
request,
'activitie_detail.html',
extra_context = {
'object':obj,
'next_excurtion':next_excurtion,
}
)
#def new_detail(request,id):
# obj = New.objects.get(pk=int(id))
#
# return simple.direct_to_template(
# request,
# 'new_detail.html',
# extra_context = {
# 'object':obj,
# }
# )
def excurtion_detail(request, tag=None,type_object=None):
obj = {}
klass = {
'excurtion': Excurtion,
'new': New,
'ctravel': CustomizedTravel,
'cimbling': Cimbling,
'etravel': EducationTravel,
'user': UserProfile,
}
if type_object is not None:
obj = get_object_or_404(klass[type_object], pk=int(tag))
return simple.direct_to_template(
request,
'object_detail.html',
extra_context = {
'object':obj,
'type_object':type_object,
}
)
else:
raise Http404
def lastexcurtion_detail(request, id):
obj = Excurtion.objects.get(pk=int(id))
return simple.direct_to_template(
request,
'lastexcurtion_detail.html',
extra_context = {
'object':obj,
}
)
def excurtions(request,tag="tab-norte"):
queryset = Activitie.objects.all()
return list_detail.object_list(
request,
queryset,
template_name='excurtions.html',
extra_context = {
'selected':tag
}
)
def cimblings(request):
cimblings = Cimbling.objects.all()[:4]
return simple.direct_to_template(
request,
'escalada.html',
extra_context = {
'cimblings':cimblings,
}
)
def customizedtravels(request):
ctravels = CustomizedTravel.objects.all()[:4]
return simple.direct_to_template(
request,
'amedida.html',
extra_context = {
'ctravels':ctravels,
}
)
def educationtravels(request):
etravels = EducationTravel.objects.all()[:4]
return simple.direct_to_template(
request,
'educativos.html',
extra_context = {
'etravels':etravels,
}
)
def contact(request):
if request.method == 'POST':
# peticion POST con formulario relleno
form = ContactoForm()
if form.is_valid():
return simple.direct_to_template(
request,
'contacto.html',
extra_context = {
'form':form,
}
)
else: # formulario sin rellenar
form = ContactoForm()
return simple.direct_to_template(
request,
'contacto.html',
extra_context = {
'form': form,
}
)
def contact_sendmail(request):
from smtplib import SMTP
from_addr = request.POST.get('email')
to_addrs = ['[email protected]']
#msg = open('email_msg.txt','r').read()
msg = ""
msg += "Nombre: " + unicode(request.POST.get('nombre')) + "\n"
msg += "Apellido: " + unicode(request.POST.get('apellido')) + "\n"
msg += "Email: " + unicode(request.POST.get('email')) + "\n"
msg += "Excursion: " + unicode(request.POST.get('nombre_excursion')) + ' ' + "Fecha: " + unicode(request.POST.get('fecha')) + "\n"
msg += "Comentario: " + unicode(request.POST.get('comentario')) + "\n"
s = SMTP()
s.connect('smtp.webfaction.com')
s.login('senderonorte','s3nd3r0n0rt3')
s.sendmail(from_addr, to_addrs, msg)
return contact(request)
def feed_next_excurtion():
pass
def feed_detail(request,tag):
a = Excurtion.objects.get(pk=int(tag))
if a:
return simple.direct_to_template(
request,
'feed_detail.html',
extra_context = {
'obj':a,
}
)
else:
return simple.direct_to_template(
request,
'feed_detail.html',
extra_context = {
'obj':{},
}
)
def server_error(request):
return simple.direct_to_template(request, '500.html')
def not_found(request):
return simple.direct_to_template(request, '404.html')
def test(request):
return simple.direct_to_template(request, '404.html')
@login_required()
def issues(request):
from contacts.models import Contact, ContactGroup
grupos = ContactGroup.objects.all()
if request.method == "POST":
if 'file' in request.FILES:
import xlrd
from django.conf import settings
file = request.FILES['file']
wb = xlrd.open_workbook(file_contents=file.read())
sh = wb.sheet_by_index(0)
for rownum in range(1,sh.nrows):
row = sh.row_values(rownum)
ctc = Contact()
ctc.name = row[0]
ctc.last_name = row[1]
ctc.email = row[2]
ctc.grupo = ContactGroup.objects.get(pk=row[3])
ctc.save()
form = UploadFileForm()
return simple.direct_to_template(
request,
'issues.html',
extra_context = {
'grupos':grupos,
'formMass':form,
}
)
@login_required()
def mailing_preview(request):
excurtions = Excurtion.objects.all().filter(publish_newsletter=True)
news = New.objects.all().filter(publish_newsletter=True)
return simple.direct_to_template(
request,
'plantilla.html',
extra_context = {
'excurtions':excurtions,
'news':news,
}
)
@login_required()
def send_mailing(request):
from django.template import Context, Template
from django.template.loader import get_template
from django.template.loader import render_to_string
from contacts.models import Contact
from django.template import loader
from django.core.mail import send_mail, EmailMultiAlternatives
import smtplib
excurtions = Excurtion.objects.all().filter(publish_newsletter=True)
news = New.objects.all().filter(publish_newsletter=True)
#t = get_template("boletin.html")
c = Context({"excurtions": excurtions,"news":news})
#t = render_to_string('boletin.html',{"excurtions": excurtions,"news":news})
html_part = loader.get_template('%s.html' %("boletin")).render(c)
msg_mail = []
if request.method == 'POST':
heading = request.POST['title_newsletter']
else:
heading = '%s' %(':: Sendero Norte :: Boletin de Novedades')
contacts = []
groups = ContactGroup.objects.all()
for g in groups:
try:
if request.POST[g.name]:
contacts = contacts + list(Contact.objects.filter(grupo=g.id))
except:
pass
for i in range(0,len(contacts)):
msg_mail.append(contacts[i].email)
msg = EmailMultiAlternatives(subject=heading,from_email='[email protected]',bcc=msg_mail,to=['[email protected]'])
msg.attach_alternative(html_part, "text/html")
msg.send()
return issues(request)
def us_page(request):
staff = UserProfile.objects.all()
logos = Logo.objects.all()
return simple.direct_to_template(
request,
'nosotros.html',
extra_context = {
'staff':staff,
'logos':logos,
}
)
mnames = "Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre"
mnames = mnames.split()
def calendar(request, year=None):
"""Main listing, years and months; three years per page."""
# prev / next years
if year: year = int(year)
else: year = time.localtime()[0]
nowy, nowm = time.localtime()[:2]
lst = []
# create a list of months for each year, indicating ones that contain entries and current
for y in [year]:
mlst = []
for n, month in enumerate(mnames):
entry = current = False # are there entry(s) for this month; current month?
entries = Excurtion.objects.filter(date__year=y, date__month=n+1)
if entries:
entry = True
if y == nowy and n+1 == nowm:
current = True
mlst.append(dict(n=n+1, name=month, entry=entry, current=current,entries=entries))
lst.append((y, mlst))
return render_to_response("calendar.html", {'years':lst, 'year':year})
def refugios(request):
return render_to_response("refugios.html", {})