def main_view(request): if request.method == "POST": if not 'owner' in request.POST or not request.POST['owner']: request.POST['owner'] = request.user.pk form = AddRecordForm(request.POST, request.FILES) if form.is_valid(): form.save() else: form = AddRecordForm() images = CatRecord.objects.filter(is_private=False).order_by('id')[:10] if len(images) % 2 == 1: last_image = images[len(images)-1] else: last_image = None images_left = images[::2] images_right = images[1::2] images_list = zip(images_left, images_right) context = RequestContext(request) context['friend_token'] = CatUser.objects.get(pk=request.user.pk).friend_token context['form'] = form context['images'] = images_list context['last_image'] = last_image return render_to_response('index.html', context)
def EditUseRecordView(request, record_id): try: obj_list = UserRecord.objects.get(id=record_id) if request.method == 'POST': form = AddRecordForm(request.POST, instance=obj_list) if form.is_valid(): form.save() return HttpResponseRedirect('/userecord/') else: form = AddRecordForm(instance=obj_list) return render(request, 'include/userecord/edituserecord.html', {'form': form}) except UserRecord.DoesNotExist: raise PermissionDenied
def AddUseRecordView(request): if request.method == 'GET': form = AddRecordForm return render_to_response('include/userecord/adduserecord.html', RequestContext(request, {'form': form})) else: form = AddRecordForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/userecord/') else: form = AddRecordForm return render(request, 'include/userecord/adduserecord.html', {'form': form})