コード例 #1
0
ファイル: views.py プロジェクト: jezGo/SDAEWeb
def LostAndFoundDetails(request,lostandfoundID):
		
	lostandfound = get_object_or_404(Publication, pk=lostandfoundID).lostandfound

	if request.method != 'POST':
		commentForm = CommentForm()
	else:
		commentForm = CommentForm(request.POST)
		if commentForm.is_valid():
			comment = commentForm.save(commit = False)

			comment.publication = Publication.objects.get(pk=lostandfound.publication.id)
			comment.author = SDAEUser.objects.get(user = request.user)

			comment.save()

	if not request.user.is_authenticated():
		isAuthor = False
		userVote = None
	else:
		# requestUser = SDAEUser.objects.get(user=request.user)
		requestUser = request.user.sdaeuser
		try:
			userVote = Vote.objects.get(author=requestUser, publication=lostandfound.publication)
		except:
			userVote = None

		publicationAuthor = lostandfound.publication.author
		isAuthor = (requestUser == lostandfound.publication.author)

	blockPositiveVote = False
	blockNegativeVote = False

	if userVote:
		if userVote.isPositive:
			blockPositiveVote = True
		else:
			blockNegativeVote = True

	publicationPoints = len(lostandfound.publication.vote_set.filter(isPositive=True)) - len(lostandfound.publication.vote_set.filter(isPositive=False))

	context = {
	'lostandfound': lostandfound,
	'publication': lostandfound.publication,
	'publicationPoints': publicationPoints,
	'blockPositiveVote': blockPositiveVote,
	'blockNegativeVote': blockNegativeVote,
	'isAuthor': isAuthor,
	'commentForm': commentForm,
	}

	return render(request, 'publications/foundlost_details.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: jezGo/SDAEWeb
def BuySellDetail(request,buysellID):
	buysell = get_object_or_404(Publication, pk=buysellID).buysell

	if request.method != 'POST':
		commentForm = CommentForm()
	else:
		commentForm = CommentForm(request.POST)
		if commentForm.is_valid():
			comment = commentForm.save(commit = False)

			comment.publication = Publication.objects.get(pk=buysell.publication.id)
			comment.author = SDAEUser.objects.get(user = request.user)

			comment.save()

	if not request.user.is_authenticated():
		isAuthor = False
		userVote = None
	else:
		# requestUser = SDAEUser.objects.get(user=request.user)
		requestUser = request.user.sdaeuser
		try:
			userVote = Vote.objects.get(author=requestUser, publication=buysell.publication)
		except:
			userVote = None

		publicationAuthor = buysell.publication.author
		isAuthor = (requestUser == buysell.publication.author)

	blockPositiveVote = False
	blockNegativeVote = False

	if userVote:
		if userVote.isPositive:
			blockPositiveVote = True
		else:
			blockNegativeVote = True

	publicationPoints = len(buysell.publication.vote_set.filter(isPositive=True)) - len(buysell.publication.vote_set.filter(isPositive=False))

	context = {
	'buysell': buysell,
	'publication':buysell.publication,
	'publicationPoints': publicationPoints,
	'blockPositiveVote': blockPositiveVote,
	'blockNegativeVote': blockNegativeVote,
	'isAuthor': isAuthor,
	'commentForm': commentForm,
	}
	return render(request, 'publications/buysell_details.html', context)
コード例 #3
0
 def get_context_data(self, **kwargs):
     context = super(PublicationDisplay, self).get_context_data(**kwargs)
     # adding comment to the view, better order by
     context['comments'] = Comment.objects.filter(
         publication=self.kwargs["pk"]).order_by('validated',
                                                 '-comment_type',
                                                 'corrected',
                                                 '-seriousness',
                                                 'creation_date')
     # put the initial licence as the licence of the publication
     try:
         context['is_editor'] = self.get_is_editor(
             context["publication_detail"].editor)
         context['is_reviewer'] = self.get_is_reviewer()
         context['evaluated'] = self.get_evaluated()
         if context['is_reviewer']:
             context['reviewer_registration'] = reviewer_action(
                 self.request.user, self.kwargs["pk"], "leave")
         else:
             context['reviewer_registration'] = reviewer_action(
                 self.request.user, self.kwargs["pk"], "become")
     except KeyError:
         context['is_editor'] = False
         context['is_reviewer'] = False
         context['evaluated'] = False
     context['constants'] = CONSTANTS_TEMPLATE
     context['order'] = PUBLICATION
     context['alert'] = self.get_alert_status(context)
     context['form_comment'] = CommentForm()
     context['form_eif'] = EstimatedImpactFactorForm()
     return context
コード例 #4
0
ファイル: views.py プロジェクト: FroVolod/mynews
 def get_context_data(self, *args, **kwargs):
     context = super(PublicationDetailView,
                     self).get_context_data(*args, **kwargs)
     publication = Publication.objects.get(
         slug=self.kwargs.get('page_alias'))
     context['form'] = CommentForm()
     context['comments'] = Comment.objects.filter(publication=publication)
     context['user'] = self.request.user
     return context
コード例 #5
0
ファイル: views.py プロジェクト: jezGo/SDAEWeb
def AdvertisementDetail(request, advertisementID):
	advertisement = get_object_or_404(Publication, pk=advertisementID).advertisement
	if request.method != 'POST':
		commentForm = CommentForm()
	else:
		commentForm = CommentForm(request.POST)
		if commentForm.is_valid():
			comment = commentForm.save(commit = False)

			comment.publication = Publication.objects.get(pk=advertisement.publication.id)
			comment.author = SDAEUser.objects.get(user = request.user)

			comment.save()

	if not request.user.is_authenticated():
		blockVotes = True
		isAuthor = False
		userVotes = []
	else:
		requestUser = SDAEUser.objects.get(user=request.user)
		userVotes = Vote.objects.filter(author=requestUser, publication=advertisement.publication)
		publicationAuthor = advertisement.publication.author
		isAuthor = (requestUser == advertisement.publication.author)

	blockVotes = False
	if len(userVotes) > 0:
		blockVotes = True

	publicationPoints = len(advertisement.publication.vote_set.filter(isPositive=True)) - len(advertisement.publication.vote_set.filter(isPositive=False))

	context = {
	'advertisement': advertisement,
	'publication': advertisement.publication,
	'publicationPoints': publicationPoints,
	'blockVotes': blockVotes,
	'isAuthor': isAuthor,
	'commentForm': commentForm,
	}

	return render(request, 'publications/advertisement_details.html', context)