Beispiel #1
0
def index(request):
	if request.method == 'POST':
		form = DocumentForm(request.POST, request.FILES)
		if form.is_valid():
			newdoc = Document()
			newdoc.docfile = request.FILES['docfile']
			newdoc.title = request.POST['title']
			#request.session['users_id'] = newdoc.users_id
			newdoc.save()
			return HttpResponseRedirect('/')
	else:
		form = DocumentForm()
		
	documents = Document.objects.all()
	categorys = Category.objects.all()
	a1 = []
	a2 = []
	a3 = []
	a4 = []
	a5 = []
	a6 = []
	a7 = []
	a8 = []
	for i in range(len(categorys)):
		for j in range(len(documents)):
			if categorys[i].id == documents[j].category_id:
				if categorys[i].id == 4:
					a1.append(documents[j])
				elif categorys[i].id == 5:
					a2.append(documents[j])
				elif categorys[i].id == 6:
					a3.append(documents[j])
				elif categorys[i].id == 7:
					a4.append(documents[j])
				elif categorys[i].id == 8:
					a5.append(documents[j])
				elif categorys[i].id == 9:
					a6.append(documents[j])
				elif categorys[i].id == 14:
					a7.append(documents[j])
				else:
					a8.append(documents[j])
			
	return render_to_response(
		'home/index.html',
		{'documents': documents, 'form': form, 'categorys': categorys,
		'a1':a1[:6], 'a2':a2[:6], 'a3':a3[:6], 'a4':a4[:6], 'a5':a5[:6], 'a6':a6[:6], 'a7':a7[:6], 'a8':a8[:6]},
		context_instance=RequestContext(request)
	)
Beispiel #2
0
def blog(request):
	# Handle file upload
	#tags = Tags.objects.all()
	s = request.session.get('users_id', None)
	if not s:
		return HttpResponseRedirect('/auth')
	if request.method == 'POST':
		form = DocumentForm(request.POST, request.FILES)
		if form.is_valid():
			newdoc = Document()
			newdoc.docfile = request.FILES['docfile']
			newdoc.title = request.POST['title']
			newdoc.users_id = request.POST['users']
			newdoc.summary = request.POST['summary']
			newdoc.content = request.POST['content']
			newdoc.publish = request.POST['publish']
			newdoc.category_id = request.POST['category']		
			request.session['users_id'] = newdoc.users_id
			newdoc = form.save(commit=False)
			newdoc.save()
			form.save_m2m()
			return HttpResponseRedirect('/blog')
	else:
		form = DocumentForm()  # A empty, unbound form
	# Load documents for the index page
	documents = Document.objects.all()
	paginator = Paginator(documents, 4)

	try:
		page = int(request.GET.get('page', '1'))
	except:
		page = 1
	try:
		documents = paginator.page(page)
	except(EmptyPage, InvalidPage):
		documents = paginator.page(paginator.num_pages)
		
	# Render index page with the documents and the form
	return render_to_response(
		'home/blog.html',
		{'documents': documents, 'form': form},
		context_instance=RequestContext(request)
	)
Beispiel #3
0
def index(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document()
            newdoc.docfile = request.FILES['docfile']
            newdoc.title = request.POST['title']
            #request.session['users_id'] = newdoc.users_id
            newdoc.save()
            return HttpResponseRedirect('/')
    else:
        form = DocumentForm()

    documents = Document.objects.all()
    categorys = Category.objects.all()
    a1 = []
    a2 = []
    a3 = []
    a4 = []
    a5 = []
    a6 = []
    a7 = []
    a8 = []
    for i in range(len(categorys)):
        for j in range(len(documents)):
            if categorys[i].id == documents[j].category_id:
                if categorys[i].id == 4:
                    a1.append(documents[j])
                elif categorys[i].id == 5:
                    a2.append(documents[j])
                elif categorys[i].id == 6:
                    a3.append(documents[j])
                elif categorys[i].id == 7:
                    a4.append(documents[j])
                elif categorys[i].id == 8:
                    a5.append(documents[j])
                elif categorys[i].id == 9:
                    a6.append(documents[j])
                elif categorys[i].id == 14:
                    a7.append(documents[j])
                else:
                    a8.append(documents[j])

    return render_to_response('home/index.html', {
        'documents': documents,
        'form': form,
        'categorys': categorys,
        'a1': a1[:6],
        'a2': a2[:6],
        'a3': a3[:6],
        'a4': a4[:6],
        'a5': a5[:6],
        'a6': a6[:6],
        'a7': a7[:6],
        'a8': a8[:6]
    },
                              context_instance=RequestContext(request))
Beispiel #4
0
def blog(request):
    # Handle file upload
    #tags = Tags.objects.all()
    s = request.session.get('users_id', None)
    if not s:
        return HttpResponseRedirect('/auth')
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document()
            newdoc.docfile = request.FILES['docfile']
            newdoc.title = request.POST['title']
            newdoc.users_id = request.POST['users']
            newdoc.summary = request.POST['summary']
            newdoc.content = request.POST['content']
            newdoc.publish = request.POST['publish']
            newdoc.category_id = request.POST['category']
            request.session['users_id'] = newdoc.users_id
            newdoc = form.save(commit=False)
            newdoc.save()
            form.save_m2m()
            return HttpResponseRedirect('/blog')
    else:
        form = DocumentForm()  # A empty, unbound form
    # Load documents for the index page
    documents = Document.objects.all()
    paginator = Paginator(documents, 4)

    try:
        page = int(request.GET.get('page', '1'))
    except:
        page = 1
    try:
        documents = paginator.page(page)
    except (EmptyPage, InvalidPage):
        documents = paginator.page(paginator.num_pages)

    # Render index page with the documents and the form
    return render_to_response('home/blog.html', {
        'documents': documents,
        'form': form
    },
                              context_instance=RequestContext(request))