Ejemplo n.º 1
0
def showAddKnowledge(request):
    user = users.models.getKnowledgeUser(request.user)
    success = False
    if request.method == 'GET':
        form = KnowledgeForm()
    if request.method == 'POST':
        form = KnowledgeForm(request.POST, request.FILES)
        print('---- validating form')
        if form.is_valid():
            print(request.FILES)
            print(request.POST)
            print('---- valid form')
            kn = form.save(commit=False)
            kn.author = user
            if kn.access > user.privilege:
                return HttpResponseForbidden('access denied.')
            print('---- add author to knowledge :' + str(user))
            success = True

            kn.save()
            Log.log_action(request, 'دانش ' + kn.subject + ' ساخته شد.')

        else:
            print('---- invalid form')

    return render(
        request, 'knowledge/add-knowledge.html',
        addUserInfoContext(
            request, {
                'page_title': 'Add knowledge',
                'form': form,
                'success': success,
                'action': 'افزودن',
            }))
Ejemplo n.º 2
0
def showEditKnowledge(request, knowledge_id):
	user = users.models.getKnowledgeUser(request.user)
	kn = get_object_or_404(knowledge.models.Knowledge, pk=knowledge_id)
	if user != kn.author:
		return HttpResponseForbidden('access denied.')

	success = False
	if request.method == 'GET':
		form = KnowledgeForm(instance=kn)
	if request.method == 'POST':
		form = KnowledgeForm(request.POST, request.FILES, instance=kn)
		print('---- validating form')
		if form.is_valid():
			print(request.FILES)
			print(request.POST)
			print('---- valid form')
			kn = form.save()
			print('---- edit knowledge :' + str(kn))
			success = True

			Log.log_action(request, 'دانش ' + kn.subject + ' ویرایش شد.')

		else :
			print('---- invalid form')


	return render(request, 'knowledge/add-knowledge.html', addUserInfoContext(request, {
		'page_title': 'edit knowledge',
		'form': form,
		'success': success,
		'action': 'ویرایش',
	}))
Ejemplo n.º 3
0
def showAddKnowledge(request):
	user = users.models.getKnowledgeUser(request.user)
	success = False
	if request.method == 'GET':
		form = KnowledgeForm()
	if request.method == 'POST':
		form = KnowledgeForm(request.POST, request.FILES)
		print('---- validating form')
		if form.is_valid():
			print(request.FILES)
			print(request.POST)
			print('---- valid form')
			kn = form.save(commit=False)
			kn.author = user
			if kn.access > user.privilege:
				return HttpResponseForbidden('access denied.')
			print('---- add author to knowledge :' + str(user))
			success = True

			kn.save()
			Log.log_action(request, 'دانش ' + kn.subject + ' ساخته شد.')

		else :
			print('---- invalid form')


	return render(request, 'knowledge/add-knowledge.html', addUserInfoContext(request, {
		'page_title': 'Add knowledge',
		'form': form,
		'success': success,
		'action': 'افزودن',
	}))
Ejemplo n.º 4
0
def showKnowledge(request, knowledge_id):
	user = users.models.getKnowledgeUser(request.user)
	kn = get_object_or_404(knowledge.models.Knowledge, pk=knowledge_id)

	if user.privilege < kn.access:
		return HttpResponseForbidden('access denied.')

	rate_up = knowledge.models.Rate.objects.filter(knowledge=kn, up=True).count()
	rate_down = knowledge.models.Rate.objects.filter(knowledge=kn, up=False).count()
	user_rate = ''
	try:
		rt = knowledge.models.Rate.objects.get(knowledge=kn, voter=user)
		if rt and rt.up:
			user_rate = 'up'
		else:
			user_rate = 'down'
	except:
		pass

	print('show knowledge:')
	print(kn)
	Log.log_action(request, 'دانش ' + kn.subject + ' مشاهده شد.')
	return render(request, 'knowledge/show-knowledge.html', addUserInfoContext(request, {
		'page_title': kn.subject,
		'knowledge': kn,
		'add_relation_form': InterKnowledgeRelationshipForm(),
		'add_tag_form': TagForm(),
		'rate_up': rate_up,
		'rate_down': rate_down,
		'user_rate': user_rate,
	}))
Ejemplo n.º 5
0
def showEditKnowledge(request, knowledge_id):
    user = users.models.getKnowledgeUser(request.user)
    kn = get_object_or_404(knowledge.models.Knowledge, pk=knowledge_id)
    if user != kn.author:
        return HttpResponseForbidden('access denied.')

    success = False
    if request.method == 'GET':
        form = KnowledgeForm(instance=kn)
    if request.method == 'POST':
        form = KnowledgeForm(request.POST, request.FILES, instance=kn)
        print('---- validating form')
        if form.is_valid():
            print(request.FILES)
            print(request.POST)
            print('---- valid form')
            kn = form.save()
            print('---- edit knowledge :' + str(kn))
            success = True

            Log.log_action(request, 'دانش ' + kn.subject + ' ویرایش شد.')

        else:
            print('---- invalid form')

    return render(
        request, 'knowledge/add-knowledge.html',
        addUserInfoContext(
            request, {
                'page_title': 'edit knowledge',
                'form': form,
                'success': success,
                'action': 'ویرایش',
            }))
Ejemplo n.º 6
0
def showSource(request, source_id):
	src = get_object_or_404(knowledge.models.Source, pk=source_id)
	print('show source: ')
	print(src)
	Log.log_action(request, 'منبع ' + src.subject + ' مشاهده شد.')
	return render(request, 'knowledge/show-source.html', addUserInfoContext(request, {
		'page_title': src.subject,
		'source': src,
	}))
Ejemplo n.º 7
0
def showSearchSource(request):
	print('search source')
	if request.method == 'POST':
		raise Http404

	sources = knowledge.engine.SearchEngine.searchSource(request.GET)

	return render(request, 'knowledge/search-source.html', addUserInfoContext(request, {
		'page_title': 'Search source',
		'sources': sources,
	}))
Ejemplo n.º 8
0
def showSource(request, source_id):
    src = get_object_or_404(knowledge.models.Source, pk=source_id)
    print('show source: ')
    print(src)
    Log.log_action(request, 'منبع ' + src.subject + ' مشاهده شد.')
    return render(
        request, 'knowledge/show-source.html',
        addUserInfoContext(request, {
            'page_title': src.subject,
            'source': src,
        }))
Ejemplo n.º 9
0
def showSearchKnowledge(request):
	print('search knowledge')
	if request.method == 'POST':
		raise Http404

	kns = knowledge.engine.SearchEngine.searchKnowledge(request.GET)

	return render(request, 'knowledge/search-knowledge.html', addUserInfoContext(request, {
		'page_title': 'Search knowledge',
		'knowledge': kns,

	}))
Ejemplo n.º 10
0
def showSearchSource(request):
    print('search source')
    if request.method == 'POST':
        raise Http404

    sources = knowledge.engine.SearchEngine.searchSource(request.GET)

    return render(
        request, 'knowledge/search-source.html',
        addUserInfoContext(request, {
            'page_title': 'Search source',
            'sources': sources,
        }))
Ejemplo n.º 11
0
def showSearchKnowledge(request):
    print('search knowledge')
    if request.method == 'POST':
        raise Http404

    kns = knowledge.engine.SearchEngine.searchKnowledge(request.GET)

    return render(
        request, 'knowledge/search-knowledge.html',
        addUserInfoContext(request, {
            'page_title': 'Search knowledge',
            'knowledge': kns,
        }))
Ejemplo n.º 12
0
def showAddTagType(request):
	success = False
	if request.method == 'GET':
		form = TagTypeForm()
	if request.method == 'POST':
		form = TagTypeForm(request.POST)
		print('---- validating form')
		if form.is_valid():
			print('---- valid form')
			tagt = form.save()
			success = True
			Log.log_action(request,'نوع برچسب ' + tagt.presentation() + ' ساخته شد.')
		else :
			print('---- invalid form')

	return render(request, 'knowledge/add-tag-type.html', addUserInfoContext(request, {
		'page_title': 'Add Tag type',
		'form': form,
		'success': success
	}))
Ejemplo n.º 13
0
def showAddSource(request):
	success = False
	if request.method == 'GET':
		form = SourceForm()
	if request.method == 'POST':
		form = SourceForm(request.POST)
		print('---- validating form')
		if form.is_valid():
			print('---- valid form')
			sc = form.save()
			success = True
			Log.log_action(request, 'منبع ' + sc.subject + ' ساخنه شد.')

		else :
			print('---- invalid form')

	return render(request, 'knowledge/add-source.html', addUserInfoContext(request, {
		'page_title': 'Add source',
		'form': form,
		'success': success
	}))
Ejemplo n.º 14
0
def showAddSource(request):
    success = False
    if request.method == 'GET':
        form = SourceForm()
    if request.method == 'POST':
        form = SourceForm(request.POST)
        print('---- validating form')
        if form.is_valid():
            print('---- valid form')
            sc = form.save()
            success = True
            Log.log_action(request, 'منبع ' + sc.subject + ' ساخنه شد.')

        else:
            print('---- invalid form')

    return render(
        request, 'knowledge/add-source.html',
        addUserInfoContext(request, {
            'page_title': 'Add source',
            'form': form,
            'success': success
        }))
Ejemplo n.º 15
0
def showAddTagType(request):
    success = False
    if request.method == 'GET':
        form = TagTypeForm()
    if request.method == 'POST':
        form = TagTypeForm(request.POST)
        print('---- validating form')
        if form.is_valid():
            print('---- valid form')
            tagt = form.save()
            success = True
            Log.log_action(request,
                           'نوع برچسب ' + tagt.presentation() + ' ساخته شد.')
        else:
            print('---- invalid form')

    return render(
        request, 'knowledge/add-tag-type.html',
        addUserInfoContext(request, {
            'page_title': 'Add Tag type',
            'form': form,
            'success': success
        }))
Ejemplo n.º 16
0
def showKnowledge(request, knowledge_id):
    user = users.models.getKnowledgeUser(request.user)
    kn = get_object_or_404(knowledge.models.Knowledge, pk=knowledge_id)

    if user.privilege < kn.access:
        return HttpResponseForbidden('access denied.')

    rate_up = knowledge.models.Rate.objects.filter(knowledge=kn,
                                                   up=True).count()
    rate_down = knowledge.models.Rate.objects.filter(knowledge=kn,
                                                     up=False).count()
    user_rate = ''
    try:
        rt = knowledge.models.Rate.objects.get(knowledge=kn, voter=user)
        if rt and rt.up:
            user_rate = 'up'
        else:
            user_rate = 'down'
    except:
        pass

    print('show knowledge:')
    print(kn)
    Log.log_action(request, 'دانش ' + kn.subject + ' مشاهده شد.')
    return render(
        request, 'knowledge/show-knowledge.html',
        addUserInfoContext(
            request, {
                'page_title': kn.subject,
                'knowledge': kn,
                'add_relation_form': InterKnowledgeRelationshipForm(),
                'add_tag_form': TagForm(),
                'rate_up': rate_up,
                'rate_down': rate_down,
                'user_rate': user_rate,
            }))