def signup(request): rider = get_rider(request) if rider: return HttpResponseRedirect('/entourage/') if request.method == 'POST': form = RegistrationForm(request.POST, request.FILES) if form.is_valid(): rider = form.save(commit=False) if not rider.avatar: fname = generate_filename(rider, 'default.jpg') rider.avatar = fname default = settings.MEDIA_ROOT + 'riders/default.jpg' with open(default) as default: with open(fname, 'w') as f: f.write(default.read()) rider.save() else: return render(request, 'entourage/signup.html', {'form': form}) return HttpResponseRedirect('/entourage/login') else: form = RegistrationForm() return render(request, 'entourage/signup.html', {'form': form})
def login(request): rider = get_rider(request) if rider: return HttpResponseRedirect('/entourage/') if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') if not username or not password: return HttpResponseRedirect('/entourage/login') try: rider = Rider.objects.get(username=username) except Rider.DoesNotExist: return HttpResponseRedirect('/entourage/login') if rider.password == hashlib.sha1(password).hexdigest(): request.session['rider_id'] = rider.id return HttpResponseRedirect('/entourage') else: return HttpResponseRedirect('/entourage/login') else: return render(request, 'entourage/login.html')
def home(request): if request.session.get('first_fb_login'): request.session['first_fb_login'] = False del request.session['first_fb_login'] return HttpResponseRedirect('/entourage/edit_profile') news = Entry.objects.order_by('-created_on')[:3] shs = Shs.objects.all() return render(request, 'pages/home.html', {'news_entries': news, 'shs': shs, 'show_fb_stream': True})
def profile_edit(request): rider = get_rider(request) if not rider: return HttpResponseRedirect('/entourage/login') if request.method == 'POST': data = request.POST open('/home/spectrum/test', 'a').write(str(data)) rider.name_first = data.get('name_first') rider.name_last = data.get('name_last') rider.email = data.get('email') rider.phone_main = data.get('phone_main') rider.phone_mobile = data.get('phone_mobile') rider.settings_updates_fb = (data.get('settings_updates_fb') == 'on') rider.settings_updates_email = (data.get('settings_updates_email') == 'on') rider.settings_updates_sms = (data.get('settings_updates_sms') == 'on') rider.settings_fb_post = (data.get('settings_fb_post') == 'on') rider.settings_profile_private = (data.get('settings_profile_private') == 'on') avatar = request.FILES.get('avatar') if avatar: def handle_upload(f): destination = open(settings.MEDIA_ROOT + rider.avatar.name, 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() handle_upload(avatar) try: rider.save() return HttpResponseRedirect('/entourage') except: return render(request, 'entourage/edit_profile.html', { 'rider': rider}) else: return render(request, 'entourage/edit_profile.html', { 'rider': rider})
def profile(request, rider_id): try: rider = Rider.objects.get(id=rider_id) except Rider.DoesNotExist: return HttpResponseRedirect('/') if (rider.settings_profile_private and request.session.get('rider_id') != rider.id): return render(request, 'entourage/profile.html', { 'error': 'profile_private'}) all_friends = get_friends(request, rider) friends = [] for fid in all_friends: try: friend = Rider.objects.get(facebook=str(fid)) except Rider.DoesNotExist: pass else: friends.append(friend) return render(request, 'entourage/profile.html', {'rider': rider, 'friends': friends})
def photos_new(request): rider = get_rider(request) if not rider: return redirect('/entourage/login') if request.method == 'POST': form = PhotoForm(request.POST) if form.is_valid(): photo = form.save(commit=False) photo.added_by = rider photo.save() form.save_m2m() return redirect('/gallery/%s' % photo.id) else: form = PhotoForm() return render(request, 'gallery/new.html', {'form': form})
def index(request): today = datetime.datetime.today() this_month = today.month this_year = today.year month = request.GET.get("month", this_month) year = request.GET.get("year", this_year) try: month, year = int(month), int(year) except ValueError: month, year = this_month, this_year if month not in range(1, 13) or year not in range(10000): month, year = this_month, this_year entries = Entry.objects.filter(created_on__year=year, created_on__month=month) return render( request, "news/index.html", {"entries": entries, "year_range": xrange(2009, year + 1), "current_year": year, "current_month": month}, )
def index(request): return render(request, 'gallery/index.html', {'photos': Photo.objects.all()})
def photos_view(request, id): photo = get_object_or_404(Photo, id=id) return render(request, 'gallery/view.html', {'photo': photo})
def view(request, slug): entry = get_object_or_404(Entry, slug=slug) return render(request, "news/entry.html", {"entry": entry})