def delete(request): if request.user.is_anonymous(): return redirect('/login/') blast = get_object_or_404(Blast, pk = request.POST.get('id', '')) if blast.user == request.user: blast.delete() return redirect('/%s/' % request.user)
def post(request): if request.user.is_anonymous(): return redirect('/login/') message = request.POST.get('blast', '').strip() if message: Blast.objects.create( user = request.user, message = message, extended = request.POST.get('extended', ''), ) return redirect('/')
def favourite(request): if request.user.is_anonymous(): return redirect('/login/') key = [k for k in request.POST.keys() if 'fave' in k][0].split('.')[0] # key will now be uncheck-45 or check-23 verb, pk = key.split('-') blast = get_object_or_404(Blast, pk = pk) # Check the user is allowed to modify this blast blast.set_viewing_user(request.user) if not blast.user_can_favourite(): return HttpResponse('You are not allowed to favourite that') if verb == 'fave': blast.favourited_by.add(request.user) if verb == 'notfave': blast.favourited_by.remove(request.user) return redirect(request.POST.get('back_to', '') or '/')
def post(request): if request.user.is_anonymous(): return redirect('/login/') form = BlastForm(request.POST, request.FILES) if form.is_valid(): blast = form.save(commit = False) if blast.message.startswith('?'): return redirect('/search/?' + urllib.urlencode({ 'q': blast.message[1:].strip(), })) else: blast.message = blast.message.strip() blast.user = request.user blast.save() return redirect('/')
def toggle(request): if request.user.is_anonymous(): return redirect('/login/') key = [k for k in request.POST.keys() if 'check' in k][0].split('.')[0] # key will now be uncheck-45 or check-23 verb, pk = key.split('-') blast = get_object_or_404(Blast, pk = pk) # Check the user is allowed to modify this blast blast.set_viewing_user(request.user) if not blast.viewing_user_can_mark_done(): return HttpResponse('You are not allowed to check off that task') if verb == 'check': blast.done = True if verb == 'uncheck': blast.done = False blast.save() return redirect(request.POST.get('back_to', '') or '/')