def post_share(request, post_id): post = get_object_or_404(Post, id=post_id, status='published') sent = False if request.method == "POST": form = EmailPostForm(request.POST) if form.is_valid(): cd = form.cleaned_data post_url = request.build_absolute_uri(post.get_absolute_url()) subject = '{} ({}) recommends your reading "{}"'.format( cd['name'], cd['email'], post.title) message = 'Read "{}" at {}\n\n{}\'s comments:{}'.format( post.title, post_url, cd['name'], cd['comments']) send_mail(subject, message, '*****@*****.**', [cd['to']]) sent = True else: form = EmailPostForm() return render(request, 'blog/post/share.html', { 'post': post, 'form': form, 'sent': sent })
def _normalize_django_request(request): if not _django_available: raise TypeError("django is not installed") if not isinstance(request, (django.http.request.HttpRequest)): raise TypeError("Cannot normalize this request object") return Request( request.build_absolute_uri(), request.method.lower(), content_type=request.META.get('CONTENT_TYPE'), body=request.body, request=request, )
def post(self, request): form = ImageUploadForm(self.request.POST, self.request.FILES) if form.is_valid(): photo = form.save() data = { 'is_valid': True, 'name': photo.file.name, 'url': request.build_absolute_uri(photo.file.url), } else: data = { 'is_valid': False, 'errors': form.errors, } return JsonResponse(data)
def get_shopItemImages(self, obj): try: shopItemImages = model.ImageUploader.objects.filter( shopItem_id=obj.id).order_by('-entry_date').values() request = self.context.get('request', None) file_prefix = '' if request is not None: file_prefix = request.build_absolute_uri('/').strip('/') if shopItemImages: arr_shopItem = [] for item in shopItemImages: item['img'] = file_prefix + '/media/' + item['img'] arr_shopItem.append(item) return arr_shopItem except model.ImageUploader.DoesNotExist: return []
def post_share(request, post_id): # Retrieve post by id post = get_object_or_404(Post, id=post_id, status='published') sent = False if request.method == 'POST': # Form was submitted form = EmailPostForm(request.POST) if form.is_valid(): # Form fields passed validation cd = form.cleaned_data # ... send email post_url = request.build_absolute_uri(post.get_absolute_url()) subject = f"{cd['name']} recommends you watch this movie "f"{post.title}" message = f"Read {post.title} at {post_url}\n\n" f"{cd['name']}\'s comments: {cd['comments']}" send_mail(subject, message, '*****@*****.**',[cd['to']]) sent = True else: form = EmailPostForm() return render(request, 'blog/share.html',{'post': post, 'form': form, 'sent' : sent})
def post_share(request, post_id): post = get_object_or_404(Post, id=post_id, status='published') sent = False if request.method == 'POST': #FORM SUBMISSION form = EmailPostForm(request.POST) if form.is_valid(): #form validation cd = form.cleaned_data post_url = request.build_absolute_uri(post.get_absolute_url()) subject = f"{cd['name']} ({cd['name']}) recommends you reading '{post.title}'" message = f"Read '{post.title}' at {post_url} \n \n {cd['name']}\'s comments: {cd['comments']}" send_mail(subject, message, '*****@*****.**', [cd['to']]) sent = True else: form = EmailPostForm() return render(request, 'blog/post/share.html', { 'post': post, 'form': form, 'sent': sent })
def post_share(request, post_id): # Retrieve post by id post = get_object_or_404(Post, id=post_id, status="published") sent = False if request.method == "POST": # Form was submitted form = EmailPostForm(request.POST) if form.is_valid(): # Form fields passed validation cd = form.cleaned_data post_url = request.build_absolute_uri(post.get_absolute_url()) subject = f"{cd['name']} recommends you read " f"{post.title}" message = (f"Read {post.title} at {post_url}\n\n" f"{cd['name']}'s comments: {cd['comments']}") send_mail(subject, message, "*****@*****.**", [cd["to"]]) sent = True else: form = EmailPostForm() return render(request, "blog/post/share.html", { "post": post, "form": form, "sent": sent })
def Get_shopItems(self, obj): try: itemOrderShopItems = list( model.ItemOrderShopItems.objects.filter( itemOrder__orderNum=obj.orderNum).values()) arr_itemOrderShopItem = [] request = self.context.get('request', None) prefix = '' if request is not None: prefix = request.build_absolute_uri('/').strip('/') for item in itemOrderShopItems: shopItem = model.ShopItem.objects.get(id=item['shopItem_id']) item['title'] = shopItem.title item['description'] = shopItem.description if shopItem.img: item['img'] = prefix + shopItem.img.url else: item['img'] = '' arr_itemOrderShopItem.append(item) return arr_itemOrderShopItem except model.ItemOrderShopItems.DoesNotExist: return []
def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs, uri=request.build_absolute_uri()) return self.render_to_response(context)
def ConvertDischarge(request): pid = request.POST['pid'] discharge = request.POST['discharge'] MedicationFAVIPIRAVIR = request.POST['MedicationFAVIPIRAVIR'] DoseFAVIPIRAVIR = request.POST['DoseFAVIPIRAVIR'] DaysFAVIPIRAVIR = request.POST['DaysFAVIPIRAVIR'] MedicationTMEDROL = request.POST['MedicationTMEDROL'] DoseTMEDROL = request.POST['DoseTMEDROL'] DaysTMEDRO = request.POST['DaysTMEDRO'] tpandsr = request.POST.get('tpan', '') DoseTTPANDSR = request.POST['DoseTTPANDSR'] daysTPANDSR = request.POST['daysTPANDSR'] TDABIGTRONmedication = request.POST['TDABIGTRONmedication'] doseTDABIGTRON = request.POST['doseTDABIGTRON'] daysTDABIGTRON = request.POST['daysTDABIGTRON'] TECOSPRIRINmed = request.POST['TECOSPRIRINmed'] TECOSPRIRINdose = request.POST['TECOSPRIRINdose'] daysecosprin = request.POST['daysecosprin'] fora = request.POST['fora'] fora2 = request.POST['fora2'] days = request.POST['days'] duolin = request.POST['duolin'] doseduolin = request.POST['doseduolin'] daysduolin = request.POST['daysduolin'] vitamin = request.POST['vitamin'] mg = request.POST['mg'] bd = request.POST['bd'] zincovit = request.POST['zincovit'] dosezincovit = request.POST['dosezincovit'] dayszincovit = request.POST['dayszincovit'] sypascoril = request.POST['sypascoril'] dosesypascoril = request.POST['dosesypascoril'] daysdosesypascoril = request.POST['daysdosesypascoril'] clinicall = request.POST['clinical'] patient = PatientDetails.objects.get(id=pid) symptom = Symptoms.objects.get(patient=pid) examin = Examination.objects.get(patient=pid) # dailyupdate = dailyUpdate.objects.filter(dpatient=pid).order_by('-dday').first() # treatment = Treatment.objects.filter(tpatient=pid).order_by('-tday').first() try: dailyupdate = dailyUpdate.objects.filter(dpatient=pid).latest('date') except dailyUpdate.DoesNotExist: dailyupdate = '' treatments = Treatment.objects.filter(tpatient=pid).order_by('tday') currentDate = date.today() context = { 'patient': patient, 'symptom': symptom, 'examin': examin, 'dailyupdate': dailyupdate, 'treatment': treatment, 'discharge': discharge, 'MedicationFAVIPIRAVIR': MedicationFAVIPIRAVIR, 'DoseFAVIPIRAVIR': DoseFAVIPIRAVIR, 'DaysFAVIPIRAVIR': DaysFAVIPIRAVIR, 'MedicationTMEDROL': MedicationTMEDROL, 'DoseTMEDROL': DoseTMEDROL, 'DaysTMEDRO': DaysTMEDRO, 'tpandsr': tpandsr, 'DoseTTPANDSR': DoseTTPANDSR, 'daysTPANDSR': daysTPANDSR, 'TDABIGTRONmedication': TDABIGTRONmedication, 'doseTDABIGTRON': doseTDABIGTRON, 'daysTDABIGTRON': daysTDABIGTRON, 'TECOSPRIRINmed': TECOSPRIRINmed, 'TECOSPRIRINdose': TECOSPRIRINdose, 'daysecosprin': daysecosprin, 'fora': fora, 'fora2': fora2, 'days': days, 'duolin': duolin, 'doseduolin': doseduolin, 'daysduolin': daysduolin, 'vitamin': vitamin, 'mg': mg, 'bd': bd, 'zincovit': zincovit, 'dosezincovit': dosezincovit, 'dayszincovit': dayszincovit, 'sypascoril': sypascoril, 'dosesypascoril': dosesypascoril, 'daysdosesypascoril': daysdosesypascoril, 'clinicall': clinicall, 'currentDate': currentDate } # return render(request, 'summary.html', context) # patient = PatientDetails.objects.get(id=pid) html_string = render_to_string('summary.html', context) html = HTML(string=html_string, base_url=request.build_absolute_uri()) result = html.write_pdf() # Creating http response response = HttpResponse(content_type='application/pdf;') filename = patient.name + '-' + str(patient.age) response[ 'Content-Disposition'] = 'inline; filename={}_Discharge_summary.pdf'.format( filename) response['Content-Transfer-Encoding'] = 'binary' with tempfile.NamedTemporaryFile(delete=True) as output: output.write(result) output.flush() output = open(output.name, 'rb') response.write(output.read()) return response
def Get_hostUrl(self, obj): request = self.context.get('request', None) if request is not None: return request.build_absolute_uri('/').strip('/') return ''