def get(self, request, message_id, format=None): if message_id.isnumeric(): try: message = Messages.objects.get(id=message_id) thumburl = settings.BASE_URL + settings.STATIC_URL + settings.MEDIA_URL + 'thumbs/' if message.toprofile.profilephoto: to_small_thumb = thumburl + 'small_' + message.toprofile.profilephoto to_medium_thumb = thumburl + 'medium_' + message.toprofile.profilephoto else: to_small_thumb = '' to_medium_thumb = '' if message.fromprofile.profilephoto: from_small_thumb = thumburl + 'small_' + message.fromprofile.profilephoto from_medium_thumb = thumburl + 'medium_' + message.fromprofile.profilephoto else: from_small_thumb = '' from_medium_thumb = '' if message.createdate: createdate = getDate(message.createdate) else: createdate = getDate(datetime.utcnow()) return json_response( { 'status': 'success', 'result': { 'id': message.id, 'toid': message.toprofile.id, 'to_firstname': message.toprofile.firstname, 'to_lastname': message.toprofile.lastname, 'to_companyname': message.toprofile.companyname, 'to_small_thumb': to_small_thumb, 'to_medium_thumb': to_medium_thumb, 'fromid': message.fromprofile.id, 'firstname': message.fromprofile.firstname, 'lastname': message.fromprofile.lastname, 'from_companyname': message.fromprofile.companyname, 'from_small_thumb': from_small_thumb, 'from_medium_thumb': from_medium_thumb, 'message': message.message, 'createdate': createdate, 'message': message.message } }, status=200) except Messages.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid Message Id' }, status=200) else: return json_response( { 'status': 'error', 'msg': 'Invalid Message Id' }, status=200)
def get(self, request, user_id, format=None): feedType = request.GET.get('feedType', 'A') page = int(request.GET.get('page', 1)) recordsPerPage = int(request.GET.get('recordsPerPage', 10)) searchText = request.GET.get('searchText', None) watcherId = request.GET.get('watcherId', None) isFollow = isFavorite = isSaveForLater = False field = [] if user_id.isnumeric(): try: user = Profiles.objects.get(userid=user_id) if searchText: if feedType != 'A': if feedType == 'P': productList = Products.objects.filter( profileid=user, title__icontains=searchText).order_by( '-createdate') postList = '' else: postList = Post.objects.filter( profileid=user, type=feedType, title__icontains=searchText).order_by( '-createdate') productList = '' else: postList = Post.objects.filter( profileid=user, title__icontains=searchText).order_by( '-createdate') productList = Products.objects.filter( profileid=user, title__icontains=searchText).order_by( '-createdate') else: if feedType != 'A': if feedType == 'P': productList = Products.objects.filter( profileid=user).order_by('-createdate') postList = '' else: postList = Post.objects.filter( profileid=user, type=feedType).order_by('-createdate') productList = '' else: postList = Post.objects.filter( profileid=user.id).order_by('-createdate') productList = Products.objects.filter( profileid=user.id).order_by('-createdate') result_list = sorted(chain(productList, postList), key=attrgetter('createdate'), reverse=True) #result_list = list(chain(productList, postList)) #Total followers totalFollowers = Followings.objects.filter( followingprofileid=user) # Total Text Post totalText = Post.objects.filter(profileid=user, type='T') # Total Video Post totalVideo = Post.objects.filter(profileid=user, type='V') # total Document totalDocument = Post.objects.filter(profileid=user, type='D') # Total Image Post totalImage = Post.objects.filter(profileid=user, type='I') #Total Product totalProduct = Products.objects.filter(profileid=user) #Total All Post totalAllPost = Post.objects.filter(profileid=user.id) if len(result_list) > 0: count = len(result_list) paginator = Paginator(result_list, recordsPerPage) try: postObj = paginator.page(page) except PageNotAnInteger: postObj = paginator.page(1) except EmptyPage: postObj = paginator.page(paginator.num_pages) for pObj in postObj: if hasattr(pObj, 'thumbnailurl'): mainUrl = settings.BASE_URL + settings.STATIC_URL + settings.POST_MEDIA_URL thumburl = mainUrl + 'thumbs/' if pObj.thumbnailurl and pObj.type == 'I': small_thumb = thumburl + 'small_' + pObj.thumbnailurl medium_thumb = thumburl + 'medium_' + pObj.thumbnailurl original_img = mainUrl + pObj.thumbnailurl elif pObj.thumbnailurl and pObj.type == 'V': small_thumb = pObj.thumbnailurl medium_thumb = pObj.thumbnailurl original_img = pObj.thumbnailurl elif pObj.thumbnailurl and pObj.type == 'D': small_thumb = mainUrl + pObj.thumbnailurl medium_thumb = mainUrl + pObj.thumbnailurl original_img = mainUrl + pObj.thumbnailurl else: original_img = small_thumb = medium_thumb = '' tableName = 'Post' else: pimageUrl = settings.BASE_URL + settings.STATIC_URL + settings.PRODUCT_MEDIA_URL pthumburl = pimageUrl + 'thumbs/' if pObj.imageurl: small_thumb = pthumburl + 'small_' + pObj.imageurl medium_thumb = pthumburl + 'medium_' + pObj.imageurl original_img = pimageUrl + pObj.imageurl else: original_img = small_thumb = medium_thumb = '' tableName = 'Products' if hasattr(pObj, 'scope'): scopeVal = pObj.scope else: scopeVal = 0 if hasattr(pObj, 'type'): typeVal = pObj.type else: typeVal = 'P' if hasattr(pObj, 'posturl'): postUrl = pObj.posturl else: postUrl = '' if hasattr(pObj, 'length'): vimeoId = pObj.length else: vimeoId = '' if pObj.createdate: createdate = getDate(pObj.createdate) else: createdate = getDate(settings.CURRENTDATE) if pObj.profileid.lastname: postedBy = pObj.profileid.firstname + " " + pObj.profileid.lastname else: postedBy = pObj.profileid.firstname # CategoryList cat_list = [] categorylist = Postcategory.objects.filter( postid=pObj.id) for catObj in categorylist: cat_list.append(catObj.categoryid.id) cat_id_in = ','.join(map(str, cat_list)) # Tags removed from benefit """ # TagList tag_list = [] tagList = Imagetag.objects.filter(postid=pObj.id) for tagObj in tagList: tag_list.append(tagObj.tagtext) tag_id_in = ','.join(map(str, tag_list)) """ tag_id_in = '' # Total Likes totalLikes = Postlikes.objects.filter(postid=pObj.id) # Total Comments totalComment = Comments.objects.filter(postid=pObj.id) if watcherId: watcherid = Profiles.objects.get(userid=watcherId) myFavorite = Favorites.objects.filter( postid=pObj.id, profileid=watcherid, type='F') mySaveForLater = Favorites.objects.filter( postid=pObj.id, profileid=watcherid, type='B') if myFavorite: isFavorite = 1 else: isFavorite = 0 if mySaveForLater: isSaveForLater = 1 else: isSaveForLater = 0 field.append({ 'id': pObj.id, 'title': pObj.title, 'description': pObj.description, 'scope': scopeVal, 'type': typeVal, 'posturl': postUrl, 'vimeoId': vimeoId, 'profileid': pObj.profileid.id, 'userid': pObj.profileid.userid.id, 'categoryid': cat_id_in, 'tagList': tag_id_in, 'createdate': createdate, 'small_thumb': small_thumb, 'medium_thumb': medium_thumb, 'original_img': original_img, 'totalComment': len(totalComment), 'totalLikes': len(totalLikes), 'isFavorite': isFavorite, 'isSaveForLater': isSaveForLater, 'tableName': tableName, }) return json_response( { 'status': 'success', 'result': json.dumps(field), 'totalpost': len(totalAllPost), 'totalfollowers': len(totalFollowers), 'totalText': len(totalText), 'totalVideo': len(totalVideo), 'totalImage': len(totalImage), 'totalDocument': len(totalDocument), 'totalrows': len(result_list), 'totalProduct': len(totalProduct) }, status=200) else: return json_response( { 'status': 'success', 'result': 'Record not found', 'msg': 'No records found', 'isFollow': isFollow, 'totalpost': len(totalAllPost), 'totalfollowers': len(totalFollowers), 'totalText': len(totalText), 'totalVideo': len(totalVideo), 'totalImage': len(totalImage), 'totalDocument': len(totalDocument), 'totalrows': 0, 'totalProduct': len(totalProduct) }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User Id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User Id' }, status=200)
def get(self, request, user_id, format=None): page = int(request.GET.get('page', 1)) recordsPerPage = int(request.GET.get('recordsPerPage', 10)) feedType = request.GET.get('feedType', 'A') searchText = request.GET.get('searchText', None) isFollow = isFavorite = isSaveForLater = False field = [] if user_id.isnumeric(): try: user = Profiles.objects.get(userid=user_id) followingUsers = Followings.objects.filter(profileid=user) """ if len(followingUsers)>0: if searchText: if feedType!='A': if feedType=='P': productList = Products.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers],title__icontains=searchText).order_by('-createdate') postList = '' else: postList = Post.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers],type=feedType,title__icontains=searchText).order_by('-createdate') productList = '' else: postList = Post.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers],title__icontains=searchText) .order_by('-createdate') productList = Products.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers],title__icontains=searchText).order_by('-createdate') else: if feedType!='A': if feedType=='P': productList = Products.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers]).order_by('-createdate') postList = '' else: postList = Post.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers],type=feedType).order_by('-createdate') productList = '' else: postList = Post.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers]) .order_by('-createdate') productList = Products.objects.filter(profileid__in=[p.followingprofileid for p in followingUsers]).order_by('-createdate') else: if searchText: if feedType!='A': if feedType=='P': productList = Products.objects.filter(title__icontains=searchText).order_by('-createdate') postList = '' else: postList = Post.objects.filter(type=feedType,title__icontains=searchText).order_by('-createdate') productList = '' else: postList = Post.objects.filter(title__icontains=searchText).order_by('-createdate') productList = Products.objects.filter(title__icontains=searchText).order_by('-createdate') else: if feedType!='A': if feedType=='P': productList = Products.objects.all().order_by('-createdate') postList = '' else: postList = Post.objects.filter(type=feedType).order_by('-createdate') productList = '' else: postList = Post.objects.all().order_by('-createdate') productList = Products.objects.all().order_by('-createdate') """ blockedUsers = Userblock.objects.filter(profileid=user) if len(blockedUsers) > 0: product = Products.objects.filter(profileid__in=[ p.blockedprofileid for p in blockedUsers ]) post = Post.objects.filter(profileid__in=[ p.blockedprofileid for p in blockedUsers ]) if searchText: if feedType != 'A': if feedType == 'P': productList = Products.objects.filter( title__icontains=searchText).exclude( id__in=[p.pk for p in product ]).order_by('-createdate') postList = '' else: postList = Post.objects.filter( poststatus=1, type=feedType, title__icontains=searchText).exclude( id__in=[p.pk for p in post]).order_by( '-createdate') productList = '' else: postList = Post.objects.filter( ~Q(type='D'), poststatus=1, title__icontains=searchText).exclude( id__in=[p.pk for p in post]).order_by( '-createdate') productList = Products.objects.filter( title__icontains=searchText).exclude( id__in=[p.pk for p in product]).order_by( '-createdate') else: if feedType != 'A': if feedType == 'P': productList = Products.objects.exclude( id__in=[p.pk for p in product]).order_by( '-createdate') postList = '' else: postList = Post.objects.filter( poststatus=1, type=feedType).exclude( id__in=[p.pk for p in post]).order_by( '-createdate') productList = '' else: postList = Post.objects.filter( ~Q(type='D'), poststatus=1).exclude( id__in=[p.pk for p in post]).order_by( '-createdate') productList = Products.objects.exclude( id__in=[p.pk for p in product]).order_by( '-createdate') else: if searchText: if feedType != 'A': if feedType == 'P': productList = Products.objects.filter( title__icontains=searchText).order_by( '-createdate') postList = '' else: postList = Post.objects.filter( poststatus=1, type=feedType, title__icontains=searchText).order_by( '-createdate') productList = '' else: postList = Post.objects.filter( poststatus=1, title__icontains=searchText).exclude( type='D').order_by('-createdate') productList = Products.objects.filter( title__icontains=searchText).order_by( '-createdate') else: if feedType != 'A': if feedType == 'P': productList = Products.objects.all().order_by( '-createdate') postList = '' else: postList = Post.objects.filter( poststatus=1, type=feedType).order_by('-createdate') productList = '' else: postList = Post.objects.filter( poststatus=1).exclude( type='D').order_by('-createdate') productList = Products.objects.all().order_by( '-createdate') result_list = sorted(chain(productList, postList), key=attrgetter('createdate'), reverse=True) #result_list = list(chain(productList, postList)) if len(result_list) > 0: count = len(result_list) paginator = Paginator(result_list, recordsPerPage) try: postObj = paginator.page(page) except PageNotAnInteger: postObj = paginator.page(1) except EmptyPage: postObj = paginator.page(paginator.num_pages) for pObj in postObj: if hasattr(pObj, 'thumbnailurl'): mainUrl = settings.BASE_URL + settings.STATIC_URL + settings.POST_MEDIA_URL thumburl = mainUrl + 'thumbs/' if pObj.thumbnailurl and pObj.type == 'I': small_thumb = thumburl + 'small_' + pObj.thumbnailurl medium_thumb = thumburl + 'medium_' + pObj.thumbnailurl original_img = mainUrl + pObj.thumbnailurl elif pObj.thumbnailurl and pObj.type == 'V': small_thumb = pObj.thumbnailurl medium_thumb = pObj.thumbnailurl original_img = pObj.thumbnailurl elif pObj.thumbnailurl and pObj.type == 'D': small_thumb = mainUrl + pObj.thumbnailurl medium_thumb = mainUrl + pObj.thumbnailurl original_img = mainUrl + pObj.thumbnailurl else: original_img = small_thumb = medium_thumb = '' tableName = 'Post' else: pimageUrl = settings.BASE_URL + settings.STATIC_URL + settings.PRODUCT_MEDIA_URL pthumburl = pimageUrl + 'thumbs/' if pObj.imageurl: small_thumb = pthumburl + 'small_' + pObj.imageurl medium_thumb = pthumburl + 'medium_' + pObj.imageurl original_img = pimageUrl + pObj.imageurl else: original_img = small_thumb = medium_thumb = '' tableName = 'Products' if hasattr(pObj, 'scope'): scopeVal = pObj.scope else: scopeVal = 0 if hasattr(pObj, 'type'): typeVal = pObj.type else: typeVal = 'P' if hasattr(pObj, 'posturl'): postUrl = pObj.posturl else: postUrl = '' if hasattr(pObj, 'length'): vimeoId = pObj.length else: vimeoId = '' if pObj.createdate: createdate = getDate(pObj.createdate) else: createdate = getDate(settings.CURRENTDATE) if pObj.profileid.lastname: postedBy = pObj.profileid.firstname + " " + pObj.profileid.lastname else: postedBy = pObj.profileid.firstname # Total Likes totalLikes = Postlikes.objects.filter(postid=pObj.id) myLikes = Postlikes.objects.filter(postid=pObj.id, profileid=user) # Total Comments totalComment = Comments.objects.filter(postid=pObj.id) # Total Favorite totalFavorites = Favorites.objects.filter( postid=pObj.id, type='F') myFavorites = Favorites.objects.filter(postid=pObj.id, profileid=user, type='F') totalBoomark = Favorites.objects.filter(postid=pObj.id, type='B') myBookmark = Favorites.objects.filter(postid=pObj.id, profileid=user, type='B') totalFavoritesRecord = Favorites.objects.filter( postid=pObj.id) if myFavorites: isFavorite = True else: isFavorite = False if myBookmark: isSaveForLater = True else: isSaveForLater = False field.append({ 'id': pObj.id, 'title': pObj.title, 'description': pObj.description, 'scope': scopeVal, 'type': typeVal, 'posturl': postUrl, 'vimeoId': vimeoId, 'profileid': pObj.profileid.id, 'userid': pObj.profileid.userid.id, 'categoryid': '', 'createdate': createdate, 'small_thumb': small_thumb, 'medium_thumb': medium_thumb, 'original_img': original_img, 'postedBy': postedBy, 'myLikes': len(myLikes), 'myFavorites': len(myFavorites), 'totalLikes': len(totalLikes), 'totalComment': len(totalComment), 'totalFavorites': len(totalFavorites), 'totalBoomark': len(totalBoomark), 'myBookmark': len(myBookmark), 'totalFavoritesRecord': len(totalFavoritesRecord), 'isFavorite': isFavorite, 'isSaveForLater': isSaveForLater, 'tableName': tableName, }) return json_response( { 'status': 'success', 'result': json.dumps(field), 'total': len(result_list), 'count': count }, status=200) else: return json_response( { 'status': 'error', 'msg': 'No records found', 'result': 'Record not found' }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User Id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User Id' }, status=200)
def get(self, request, user_id, format=None): if user_id.isnumeric(): page = int(request.GET.get('page', 1)) recordsPerPage = int(request.GET.get('recordsPerPage', 10)) try: profile = Profiles.objects.get(userid=user_id) sentlist = Messages.objects.filter(fromprofile=profile, fromdelete='N') field = [] thumburl = settings.BASE_URL + settings.STATIC_URL + settings.MEDIA_URL + 'thumbs/' if len(sentlist) > 0: count = sentlist.count() paginator = Paginator(sentlist, recordsPerPage) try: sentObj = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. sentObj = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. sentObj = paginator.page(paginator.num_pages) for mObj in sentObj: if mObj.toprofile.profilephoto: to_small_thumb = thumburl + 'small_' + mObj.toprofile.profilephoto to_medium_thumb = thumburl + 'medium_' + mObj.toprofile.profilephoto else: to_small_thumb = '' to_medium_thumb = '' if mObj.fromprofile.profilephoto: from_small_thumb = thumburl + 'small_' + mObj.fromprofile.profilephoto from_medium_thumb = thumburl + 'medium_' + mObj.fromprofile.profilephoto else: from_small_thumb = '' from_medium_thumb = '' if mObj.createdate: createdate = getDate(mObj.createdate) else: createdate = getDate(settings.CURRENTDATE) field.append({ 'id': mObj.id, 'toid': mObj.toprofile.id, 'to_firstname': mObj.toprofile.firstname, 'to_lastname': mObj.toprofile.lastname, 'to_small_thumb': to_small_thumb, 'to_medium_thumb': to_medium_thumb, 'fromid': mObj.fromprofile.id, 'firstname': mObj.fromprofile.firstname, 'lastname': mObj.fromprofile.lastname, 'from_small_thumb': from_small_thumb, 'from_medium_thumb': from_medium_thumb, 'message': mObj.message, 'createdate': createdate, }) return json_response( { 'status': 'success', 'result': json.dumps(field), 'total': len(sentlist) }, status=200) else: return json_response( { 'status': 'success', 'msg': 'Empty result', 'result': 'Record not found' }, status=200) except Profiles.DoesNotExist: return json_response( { 'status': 'error', 'msg': 'Invalid User id' }, status=200) else: return json_response({ 'status': 'error', 'msg': 'Invalid User id' }, status=400)
def post(self, request, format=None): userId = int(request.POST.get('userId', None)) page = int(request.GET.get('page', 1)) recordsPerPage = int(request.GET.get('recordsPerPage', 10)) markRead = request.POST.get('markRead', False) if userId and userId is not None: try: Profile = Profiles.objects.get(userid=userId) try: pushMessages = Pushnotification.objects.filter( receiverprofileid=Profile).order_by('-createdate') paginator = Paginator(pushMessages, recordsPerPage) try: pushMessagesObj = paginator.page(page) except PageNotAnInteger: pushMessagesObj = paginator.page(1) except EmptyPage: pushMessagesObj = paginator.page(paginator.num_pages) messageList = [] for msg in pushMessagesObj: if msg.senderprofileid > 0: senderName = msg.senderprofileid.firstname if msg.senderprofileid.profilephoto: senderPhoto = settings.BASE_URL + settings.STATIC_URL + settings.MEDIA_URL + msg.senderprofileid.profilephoto else: senderPhoto = "assets/vendor/theme/img/avatar.png" else: senderName = senderPhoto = '' messageList.append({ 'id': msg.id, 'message': msg.message, #'profileid' : msg.profileid.id, 'userName': senderName, 'companyname': msg.senderprofileid.companyname, 'userPhoto': senderPhoto, 'isPostRead': msg.is_post_read, 'isPushRead': msg.is_push_read, 'isDeliver': msg.is_deliver, 'actionId': msg.action_id, 'actionType': msg.action_type, 'createdDate': getDate(msg.createdate) }) if markRead: Pushnotification.objects.filter( receiverprofileid=Profile).update(is_push_read=1) return json_response({ 'status': 'success', 'msg': 'PushNotification List', 'result': json.dumps(messageList), 'total': len(pushMessages) }) except Pushnotification.DoesNotExist: return json_response({ 'status': 'success', 'msg': 'PushNotification List Exc', 'result': json.dumps([]) }) except Profiles.DoesNotExist: return json_response({ 'status': 'error', 'msg': 'Invalid User' }, status=status.HTTP_400_BAD_REQUEST) else: return json_response({ 'status': 'error', 'msg': 'Invalid Data' }, status=status.HTTP_400_BAD_REQUEST)
def get_context_data(self, **kwargs): context = super(PostDetailView, self).get_context_data(**kwargs) #context['book_list'] = self.post_id postId = self.kwargs['post_id'] if postId: context['postid'] = postId try: post = Post.objects.get(id=postId) if post.createdate: post_createdate = getDate(post.createdate) else: post_createdate = 'N/A' thumburl = settings.BASE_URL + settings.STATIC_URL + settings.POST_MEDIA_URL + 'thumbs/' if post.thumbnailurl: small_thumb = thumburl + 'small_' + post.thumbnailurl medium_thumb = thumburl + 'medium_' + post.thumbnailurl else: small_thumb = '' medium_thumb = '' # CategoryList try: cat_list = [] categorylist = Postcategory.objects.filter(postid=post) for catObj in categorylist: cat_list.append({ 'id': catObj.categoryid.id, 'title': catObj.categoryid.name }) except Postcategory.DoesNotExist: cat_id_in = '' # TagList try: tag_list = [] tagList = Imagetag.objects.filter(postid=post) for tagObj in tagList: tag_list.append({ 'id': tagObj.id, 'tagtext': tagObj.tagtext }) except Imagetag.DoesNotExist: tag_id_in = '' # Total Likes totalLikes = Postlikes.objects.filter(postid=postId) # Total Comments totalComment = Comments.objects.filter(postid=postId) field = [] if totalComment: for cmtObj in totalComment: createdate = getDate(cmtObj.createdate) if cmtObj.profileid.profilephoto: mediumthumbimg = settings.BASE_URL + settings.STATIC_URL + settings.MEDIA_URL + 'thumbs/medium_' + cmtObj.profileid.profilephoto smallthumbimg = settings.BASE_URL + settings.STATIC_URL + settings.MEDIA_URL + 'thumbs/small_' + cmtObj.profileid.profilephoto else: smallthumbimg = mediumthumbimg = '' field.append({ 'id': cmtObj.id, 'comment': cmtObj.comment, 'commentOn': createdate, 'postid': cmtObj.postid.id, 'userid': cmtObj.profileid.userid.id, 'commentBy': cmtObj.profileid.firstname, 'user_small_img': smallthumbimg, 'user_medium_img': mediumthumbimg, }) context['title'] = post.title context['description'] = post.description context['createdate'] = post_createdate context['scope'] = post.scope context['type'] = post.type context['post_owner_id'] = post.profileid.userid.id context['category'] = cat_list context['post_small_thumb'] = small_thumb context['post_medium_thumb'] = medium_thumb context['tagList'] = tag_list context['totalLikes'] = len(totalLikes) context['totalComment'] = len(totalComment) context['comments'] = field except Post.DoesNotExist: context['result'] = 'Invalid' else: context['result'] = 'Invalid' return context