def add(request): current_page = 'link' page_title = '链接' # 处理GET请求 if request.method == 'GET': form = LinkForm() return render('link_add.html',locals(),context_instance=RequestContext(request)) # 处理POST请求 form = LinkForm(request.POST) # 处理用户提交的数据 if form.is_valid(): try: form.save() except Exception,e: messages.error('保存数据时出错') if request.user.is_authenticated(): # 增加声望 profile = request.user.get_profile() profile.score += 1 profile.save() messages.success(request,'分享酷站成功,声望+1') return render('link_posted.html',locals(),context_instance=RequestContext(request))
def add(request): # 处理GET请求 if request.method == 'GET': form = LinkForm() return render('link_add.html',locals(),context_instance=RequestContext(request)) # 处理POST请求 form = LinkForm(request.POST) # 处理用户提交的数据 if form.is_valid(): form.save() return render('link_posted.html',locals(),context_instance=RequestContext(request)) else: return render('link_add.html',locals(),context_instance=RequestContext(request))
def clear_CAM(request): User = get_user_model() block = Block() form_block = BlockForm() form_link = LinkForm() link = Link() block_data = {} clear_cam_valid = request.POST.get('clear_cam_valid') # clear cam if clear_cam_valid: # clear blocks associated with user blocks = Block.objects.filter(creator=request.user.username) for block in blocks: block.delete() # clear links associated with user links = Link.objects.filter(creator=request.user.username) for link in links: link.delete() # clear user blocks and links user = User.objects.get(username=request.user.username) user.blocks = [] user.links = [] user.save() content = { 'user': user, 'block': block, 'form_block': form_block, 'new_block': block_data, 'link': link, 'form_link': form_link } return render(request, 'index.html', content)
def add(request): current_page = 'link' page_title = '链接' # 处理GET请求 if request.method == 'GET': form = LinkForm() return render('link_add.html', locals(), context_instance=RequestContext(request)) # 处理POST请求 form = LinkForm(request.POST) # 处理用户提交的数据 if form.is_valid(): try: form.save() except Exception, e: messages.error('保存数据时出错') if request.user.is_authenticated(): # 增加声望 profile = request.user.get_profile() profile.score += 1 profile.save() messages.success(request, '分享酷站成功,声望+1') return render('link_posted.html', locals(), context_instance=RequestContext(request))
def add_link(request): User = get_user_model() link_data = {} if request.method == 'POST': link_valid = request.POST.get('link_valid') if link_valid: # If we are only adding a new element link_data['starting_block'] = request.POST.get('start_global_id') link_data['ending_block'] = request.POST.get('end_global_id') # Check if a link with these blocks already exists. If so, then delete links_already = Link.objects.filter( starting_block=request.POST.get('starting_block'), ending_block=request.POST.get('ending_block')) link_data['already'] = False # Is there already a link? if links_already: link_data['already'] = True links_already.delete() if request.user.is_authenticated: link_data['creator'] = request.user.get_username() else: link_data['creator'] = 'Anonymous' form_link = LinkForm(link_data) link = form_link.save() #link_data['name'] = link.id link_data['num_link'] = link.id link_data['id'] = link.id user = User.objects.get(username=request.user.username) user.links.append(link.id) user.save() # Add lines to blocks start_block = Block.objects.get( id=request.POST.get('start_global_id')) start_block.links.append(link.id) start_block.save() end_block = Block.objects.get(id=request.POST.get('end_global_id')) end_block.links.append(link.id) end_block.save() # Now add block info to the link... link.start_x = start_block.x_pos link.start_y = start_block.y_pos link.end_x = end_block.x_pos link.end_y = end_block.y_pos link.save() return JsonResponse(link_data)
def add(request): # 处理GET请求 if request.method == 'GET': form = LinkForm() return render('link_add.html', locals(), context_instance=RequestContext(request)) # 处理POST请求 form = LinkForm(request.POST) # 处理用户提交的数据 if form.is_valid(): form.save() return render('link_posted.html', locals(), context_instance=RequestContext(request)) else: return render('link_add.html', locals(), context_instance=RequestContext(request))