Exemplo n.º 1
0
def share_report(request):
    if request.method == 'POST':
        shared_data_form = SharedDataForm(request.POST, instance=SharedData())
        if shared_data_form.is_valid():
            shared_data = shared_data_form.save(commit=False)
            shared_data.user = request.user
            shared_data.creation_date = datetime.date.today()
            shared_data.save()
            shared_data_form.save_m2m()
            # format the email better here TODO
            subject = 'Shared Variant Report: {}'.format(
                shared_data_form['name'].value())
            absolute_uri = request.build_absolute_uri('/')
            uuid = str(shared_data.uuid).replace('-', '')
            share_url = absolute_uri + 'viewer/shared/view/' + uuid + '/'
            recipients = [str(contact) for contact in shared_data.shared_recipient.all()]

            message = 'A variant report has been shared with you. Go to the following link to view: '
            message += share_url

            print subject
            print message

            # send_mail(subject, message, '*****@*****.**',
            #           recipients, fail_silently=False)

        return HttpResponseRedirect(reverse('manage_report'))
        # I don't know that we should necessarily redirect
        # Maybe just close the modal box, return to page?
        # but then how do we assure success? Or report failure? TODO
    else:
        project_pk = request.session.get('viewing_project', None)
        if project_pk is None:
            return HttpResponseRedirect(reverse('no_project'))
        report_ids = request.GET.getlist('reportid')
        reports = Report.objects.filter(pk__in=report_ids)
        shared_data_form = SharedDataForm(instance=SharedData(), initial={
            'field_lookup': simplejson.dumps({'report_id__in': report_ids})
        })
        shared_data_form.fields['shared_recipient'].queryset = Project.objects.get(pk=project_pk).contact_set.all()
        context = {
            'reports_name': ', '.join([report.name for report in reports]),
            'shared_data_form': shared_data_form
        }
        return render(request, 'viewer/share/share_report.html', context)
Exemplo n.º 2
0
def new_shared_data(request):
    if request.method == 'POST':
        shared_data_form = SharedDataForm(request.POST, instance=SharedData())
        if shared_data_form.is_valid():
            shared_data_form.save()
        return HttpResponseRedirect