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': 'ویرایش', }))
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': 'ویرایش', }))
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': 'افزودن', }))
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': 'افزودن', }))