def userlogin(request): if request.method == 'POST': # If the form has been submitted... username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) next = request.POST['next'] if next != "": return redirect(next) else: return redirect("/") else: message = _("Login failed.The account is disabled") else: message = _("Username and/or password wrong") context = util.generateContext(request, contextType = 'RequestContext', message = message) return render_to_response('main/login.html', context) else: if request.method == 'GET': try: next = request.GET['next'] except: next = "" context = util.generateContext(request, contextType = 'RequestContext', next=next) return render_to_response('main/login.html', context, title="Login")
def newHop(request): title = "New Hop" if request.method=='POST': form = HopForm(request.POST) if form.is_valid(): secretID = form.cleaned_data['secretID'] oid = request.POST['object'] object = get_object_or_404(Object, id=int(oid)) if secretID == object.secretID: country = form.cleaned_data['country'] city = form.cleaned_data['city'] zipcode = form.cleaned_data['zipcode'] street = form.cleaned_data['street'] housenumber = form.cleaned_data['housenumber'] longitude, latitude = util.getLonLat(country, city, zipcode, street, housenumber) l = Location( country = country, city = city, zipcode = zipcode, street = street, housenumber = housenumber, longitude = longitude, latitude = latitude ) l.save() note = form.cleaned_data['note'] hop = Hop(objectID=object, user=request.user, location=l, note=note, submissionDate=datetime.datetime.now()) hop.save() return redirect("/object/{0}".format(object.id)) else: message = "The SecretID wasn't correct. Are you shure you have the object?" else: message = "The entered information wasn't valid. please check it." t = loader.get_template('main/newhop.html') context = util.generateContext(request, contextType = 'RequestContext', form=form, message=message, title=title) return HttpResponseServerError(t.render(context)) else: form = HopForm() if request.method == 'GET': try: object = request.GET['obj'] except: return redirect("/") context = util.generateContext(request, contextType = 'RequestContext', form = form, obj=object, title=title) return render_to_response('main/newhop.html', context)
def searchAll(request): if request.method == 'POST': form = Searchform(request.POST) if form.is_valid(): searchstring = form.cleaned_data['searchbox'] entrylist = models.Entry.objects.filter(title__search='Leitbild') context = util.generateContext(request, title = _('Search'), entries = entrylist) return render_to_response('search/result.html', context)
def newObject(request): title = "New Object" if request.method == 'POST': # If the form has been submitted... form = ObjectForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass country = form.cleaned_data['country'] city = form.cleaned_data['city'] zipcode = form.cleaned_data['zipcode'] street = form.cleaned_data['street'] housenumber = form.cleaned_data['housenumber'] lon, lat = util.getLonLat(country, city, zipcode, street, housenumber) l = Location( country = country, city = city, zipcode = zipcode, street = street, housenumber = housenumber, longitude = lon, latitude = lat ) l.save() randID = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(10)) o = Object( name = form.cleaned_data['name'], description = form.cleaned_data['description'], secretID = randID, submissionDate = datetime.datetime.now(), sender = request.user, destination = l ) o.save() return HttpResponseRedirect('/object/{0}'.format(o.id)) # Redirect after POST else: message = "The entered information wasn't valid. please check it." t = loader.get_template('main/newobject.html') ontext = util.generateContext(request, contextType = 'RequestContext', form=form, message=message, title=title) return HttpResponseServerError(t.render(context)) else: form = ObjectForm() # An unbound form context = util.generateContext(request, contextType = 'RequestContext', form = form, title=title) return render_to_response('main/newobject.html', context)
def showUser(request, url=None): if url == None: if request.user.is_authenticated(): return redirect('/user/show/{0}'.format(request.user.username)) else: return redirect('/') else: user = get_object_or_404(User, username=url) print request.user.profile.url objectlist = Object.objects.all().filter(sender=user) context = util.generateContext(request, contextType = 'RequestContext', viewuser=user, objects=objectlist, title=user.username) return render_to_response('usermanag/show.html', context)
def listTags(request, url, page=None): try: url = int(util.stripSlash(url)) except: url = 1 entrylist = get_list_or_404(Entry, tags__name = url, published = True) paginator = Paginator(entrylist, 15) entrylist = paginator.page(page) title = "Blog: " + url uri = util.getUri(request) context = util.generateContext(request, title = title, entries = entrylist, fulluri = uri) return render_to_response('blog/standard.html', context)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass username = form.cleaned_data['username'] password = form.cleaned_data['password'] secpassword = form.cleaned_data['secpassword'] email = form.cleaned_data['email'] if password == secpassword: try: user = User.objects.create_user(username, email, password) except IntegrityError: t = loader.get_template('main/register.html') message = "Error: The Username is already taken" context = util.generateContext(request, contextType = 'RequestContext', form=form, message=message) return HttpResponseServerError(t.render(context)) #user.profile = UserProfile(user=user) user.profile.save() profile = user.get_profile() profile.url = username print profile.url print username profile.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/') else: message = "Error: The Passwords didn't match" else: message = "There was a problem with the entered values" t = loader.get_template('main/register.html') context = util.generateContext(request, contextType = 'RequestContext', form=form, message=message) return HttpResponseServerError(t.render(context)) else: form = RegisterForm() context = util.generateContext(request, contextType = 'RequestContext', form=form) return render_to_response('main/register.html', context)
def listAll(request, page=None): try: page = int(util.stripSlash(page)) except: page = 1 entrylist = Entry.objects.all().filter(published = True) paginator = Paginator(entrylist, 15) try: entrylist = paginator.page(page) except (EmptyPage, InvalidPage): return redirect("/blog/") uri = util.getUri(request) context = util.generateContext(request, contextType = 'RequestContext', entries = entrylist, fulluri = uri) return render_to_response('blog/standard.html', context)
def userlogin(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) title = _("Login was successful") message = _("Welcome {0}".format(username)) else: title = _("Login failed") message = _("The account is disabled") else: title = _("Login failed") message = _("Username and/or password wrong") context = util.generateContext(request, contextType = 'RequestContext', title = title, message = message) return render_to_response('user/login.html', context)
def editProfile(request): title="Edit Profile" if request.method == 'POST': userform = ProfileForm(request.POST) # A form bound to the POST data adressform = AdressForm(request.POST) if userform.is_valid(): # All validation rules pass oldpassword = userform.cleaned_data['oldpassword'] password = userform.cleaned_data['password'] secpassword = userform.cleaned_data['secpassword'] email = userform.cleaned_data['email'] if adressform.is_valid(): publicadress = adressform.cleaned_data['publicAdress'] country = adressform.cleaned_data['country'] city = adressform.cleaned_data['city'] zipcode = adressform.cleaned_data['zipcode'] street = adressform.cleaned_data['street'] housenumber = adressform.cleaned_data['housenumber'] userprofile = request.user.profile l = Location(country=country, city=city, zipcode=zipcode, street=street, housenumber=housenumber) l.save() userprofile.adress = l userprofile.publicAdress = publicadress userprofile.save() else: user = request.user try: userform = ProfileForm({'email': user.email,}) except: userform = UserForm() try: adressform = AdressForm({ 'publicAdress': user.profile.publicAdress, 'country': user.profile.adress.country, 'city': user.profile.adress.city, 'zipcode': user.profile.adress.zipcode, 'street': user.profile.adress.street, 'housenumber': user.profile.adress.housenumber}) except: adressform = AdressForm() context = util.generateContext(request, contextType = 'RequestContext', userform=userform, adressform=adressform, title=title) return render_to_response('usermanag/edit.html', context)
def showCalendar(request, url): today = date.today() url = util.stripSlash(url) if url == "": month = today.month year = today.year else: try: year, month = url.split("/") year = int(year) month = int(month) except: return redirect("/calendar/") weeks = calendar.monthcalendar(year, month) entrylist = Entry.objects.all().filter(published = True, startDay__year = year, startDay__month = month) for i in range(len(weeks)): for o in range(len(weeks[i])): eventlist = [] if weeks[i][o] == 0: day = "" htmlclass = "noday" else: day = weeks[i][o] if day == today.day and month == today.month and year == today.year: htmlclass = "today" else: htmlclass = "day" for entry in entrylist: if entry.startDay.day <= day and entry.endDay.day >= day: eventlist.append(entry) weeks[i][o] = [day, htmlclass, eventlist] monthname = calendar.month_name[month] weekdays = [_("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa"), _("Su")] context = util.generateContext(request, contextType = 'RequestContext', title = _('Calendar'), entries = weeks, url = url, year = year, month = month, monthname = monthname, weekdays = weekdays, contentwidth = "wide") return render_to_response('calendar/show.html', context)
def showlogin(request): context = util.generateContext(request, contextType = 'RequestContext', title = _("Login")) return render_to_response('user/login.html', context)
def userlogout(request): logout(request) context = util.generateContext(request, contextType = 'RequestContext', message = _("You were successfully logged out")) return redirect('/')
def showlogin(request): if request.user.is_authenticated(): return redirect('/') else: context = util.generateContext(request, contextType = 'RequestContext') return render_to_response('main/login.html', context)
def mainview(request): objectlist = Object.objects.all() context = util.generateContext(request, contextType = 'RequestContext', objects = objectlist) return render_to_response('main/standard.html', context)
def singleObject(request, url): singleObject = get_object_or_404(Object, id=url) hoplist = Hop.objects.filter(objectID=singleObject) title = singleObject.name context = util.generateContext(request, contextType = 'RequestContext', object = singleObject, hops = hoplist, title=title) return render_to_response('main/single.html', context)
def userlogout(request): logout(request) context = util.generateContext(request, contextType = 'RequestContext', title = _("Logout was successful"), message = _("You were successfully logged out")) return render_to_response('user/login.html', context)
def showEvent(request, url): url = util.stripSlash(url) entry = get_object_or_404(Entry, url = url, published = True) context = util.generateContext(request, contextType = 'RequestContext', title = _('Event'), event = entry, url = url) return render_to_response('calendar/single.html', context)
def show(request, url): url = util.stripSlash(url) entry = get_object_or_404(Entry, url = url, published = True) searchform = Searchform() context = util.generateContext(request, contextType = 'RequestContext', title = entry.title, entry = entry, searchform = searchform, url = url) return render_to_response('blog/show.html', context)