diff -r d1dbae2ca603 manager urls py --- manager urls py Fri Nov 28 15

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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<task_id>\d+)/places/(?P<status>.+)/$', views.places),
url(r'^task/(?P<task_id>\d+)/export_to_excel/',
excel_views.export_to_excel, name='export_to_excel'),
+
+ url(r'^task/(?P<task_id>\d+)/export_places_to_pdf/',
+ views.export_places_to_pdf, name='export_places_to_pdf'),
+
url(r'^task/(?P<task_id>\d+)/supplier_template/',
excel_views.supplier_template, name='supplier_template'),
url(r'^task/(?P<task_id>\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 @@
<li class="send"><a href="#" onclick="return process_places('{% url excel.views.export_to_excel task.id %}', 'taskplace_id', 'places_form', {status: '{{ status }}'})">РЎР_С:С_Р°Р_РёС'С_ Р_ Excel</a></li>
+<li class="send"><a href="#" onclick="return process_places('{% url manager.views.export_places_to_pdf task.id %}', 'taskplace_id', 'places_form', {status: '{{ status }}'})">РЎР_С:С_Р°Р_РёС'С_ Р_ PDF</a></li>
\ No newline at end of file