diff -r d1dbae2ca603 manager/urls.py --- a/manager/urls.py Fri Nov 28 15:23:52 2008 +0600 +++ b/manager/urls.py Mon Dec 01 12:13:19 2008 +0500 @@ -17,6 +17,10 @@ url(r'^task/(?P\d+)/places/(?P.+)/$', views.places), url(r'^task/(?P\d+)/export_to_excel/', excel_views.export_to_excel, name='export_to_excel'), + + url(r'^task/(?P\d+)/export_places_to_pdf/', + views.export_places_to_pdf, name='export_places_to_pdf'), + url(r'^task/(?P\d+)/supplier_template/', excel_views.supplier_template, name='supplier_template'), url(r'^task/(?P\d+)/upload_sup_answer/', diff -r d1dbae2ca603 manager/views.py --- a/manager/views.py Fri Nov 28 15:23:52 2008 +0600 +++ b/manager/views.py Mon Dec 01 12:13:19 2008 +0500 @@ -843,6 +843,95 @@ @managers_only +def export_places_to_pdf(request, task_id): + + if not request.user.is_admin() and\ + not task.compaign in request.user.compaigns.all(): + return HttpResponseDenied() + + taskplace_id = request.POST.getlist('taskplace_id') + from reportlab.pdfgen import canvas + from reportlab.lib import pagesizes + from reportlab.lib.units import inch + from reportlab.pdfbase import pdfmetrics + from reportlab.pdfbase.ttfonts import TTFont + from reportlab.lib.units import cm + from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle + from reportlab.platypus import Paragraph, Frame + + fh = StringIO.StringIO() + + c = canvas.Canvas(fh, pagesize=pagesizes.A4) + pwidth, pheight = pagesizes.A4 + margin = inch + img_width = (pwidth - (margin * 3))/2 + img_height = (pheight - (margin * 5))/2 + + places = Place.objects.select_related(depth=5).filter(taskplaces__in=taskplace_id) + if not places: + flash.error_next(u'Р'С< Р_Рч Р_С<Р+С_Р°Р>Рё Р_РчС_С'Р°') + return HttpResponseRedirect(backurl) + + coords = [{ + 'x': margin, + 'y': pheight - img_height - margin + }, { + 'x': margin + img_width + margin, + 'y': margin*4 + img_height + }, { + 'x': margin, + 'y': margin*2 + }, { + 'x': margin + img_width + margin, + 'y': margin*2 + }] + pdfmetrics.registerFont(TTFont('Arial', os.path.join(settings.MEDIA_ROOT, 'fonts', 'Arial.ttf'))) + styles = getSampleStyleSheet() + image_text_style = ParagraphStyle(name='normal',fontName='Arial', + fontSize=12,leading=1.2*12,parent=styles['Normal']) + + + page_img_place = -1 + + + for place in places: + page_img_place+=1 + if page_img_place>3: + c.showPage() + page_img_place=0 + + #Drawing image description + c.setFillColorRGB(0.9,0.9,0.9) + c.rect(coords[page_img_place]['x'], coords[page_img_place]['y']-margin, + img_width, margin, fill=1, stroke=0) + c.setFillColorRGB(0,0,0) + story = [Paragraph(unicode(place.address),style=image_text_style)] + f = Frame(coords[page_img_place]['x'], coords[page_img_place]['y']-margin, + img_width, margin, showBoundary=0) + f.addFromList(story,c) + + try: + photo = place.images.all().order_by('-created')[0] + photo = PILImage.open(photo.big_path) + c.drawInlineImage(photo, coords[page_img_place]['x'], coords[page_img_place]['y'], + width=img_width, height=img_height, + preserveAspectRatio=True) + except IndexError,e: + c.setFillColorRGB(1,1,1) + c.rect(coords[page_img_place]['x'], coords[page_img_place]['y'], + img_width, img_height, fill=1, stroke=1) + c.setFillColorRGB(0,0,0) + + + + c.save() + + resp = HttpResponse(fh.getvalue(), content_type='application/pdf') + resp['Content-Disposition'] = 'attachment; filename="photo_report.pdf"' + return resp + + +@managers_only @render_to('manager/places_map.html') def map(request, task_id): task = get_object_or_404(Task, pk=task_id) diff -r d1dbae2ca603 static/templates/manager/places_content_common.html --- a/static/templates/manager/places_content_common.html Fri Nov 28 15:23:52 2008 +0600 +++ b/static/templates/manager/places_content_common.html Mon Dec 01 12:13:19 2008 +0500 @@ -1,1 +1,2 @@
  • РЎР_С:С_Р°Р_РёС'С_ Р_ Excel
  • +
  • РЎР_С:С_Р°Р_РёС'С_ Р_ PDF
  • \ No newline at end of file