Exemplo n.º 1
0
Arquivo: views.py Projeto: xueqi/lab
def list(request):
    boxes = Box.objects.all()
    if len(boxes) == 0:
        b = Box()
        b.save()
        boxes = Box.objects.all()
    return render(request, "box/list.html", {"boxes":boxes})
Exemplo n.º 2
0
def boxv(request):
	v='48'
	user=request.user
	box_list=[]
	notexist=True
	if not request.user.is_authenticated():
		return HttpResponseRedirect("/login/")
	else:	
		myusername=User.objects.get(username=user)
		mymember=Member.objects.get(member=myusername)
		mybox=Box.objects.filter(member=mymember)	
		if request.method =='POST':
			new_simn=request.POST.get('simn','')
			new_adresse=request.POST.get('adres','')
			try:
				new_simn=int(new_simn)
			except ValueError:
				for boxu in Box.objects.filter(member=mymember):
    					box_list.append(boxu)
				t=get_template('box.html')
				html = t.render(RequestContext(request, {'username':user,'mybox_list':box_list,'error':'PLEASE ENTER A NUMBER',}))
				return HttpResponse(html)
			for box in mybox:
				b=int(box.sim.number)
				if(b==new_simn):
					current_sim=box.sim
					current_box=box
					notexist=False
	
			if notexist:
				new_sim=Sim(number=new_simn, description=new_adresse)
				new_sim.save()
				new_box=Box(sim=new_sim,address=new_adresse)
				new_box.save()
				new_box.member.add(mymember)
			else:
				current_sim.description=new_adresse
				current_sim.save()
				current_box.sim=current_sim
				current_box.address=new_adresse
				current_box.save()
			return HttpResponseRedirect("/box/")
		else:
			if not request.user.is_authenticated():
				return HttpResponseRedirect("/login/")
			else:
				for boxu in Box.objects.filter(member=mymember):
    					box_list.append(boxu)
				t=get_template('box.html')
				html = t.render(RequestContext(request, {'username':user,'mybox_list':box_list}))
				return HttpResponse(html)
Exemplo n.º 3
0
def add_box(request):

    try:
        # フィード登録
        box = Box(
            box_name="新規ボックス",
            user=request.user,
        )
        box.add_box()
    except Exception:
        # ボックスの登録失敗
        return HttpResponseRedirect(reverse('common_error'))

    return HttpResponseRedirect(reverse('common_edit'))
Exemplo n.º 4
0
    def set_default_box(self, request):

        # 現在日時取得
        now = datetime.datetime.now()

        box = Box()
        box.box_name = "デフォルトボックス"
        box.user = request.user
        box.add_box()

        self.user = request.user
        self.default_box = box
        self.create_date = now
        self.updated_date = now
        self.del_flg = False
        self.save()