Exemplo n.º 1
0
Arquivo: views.py Projeto: wuxxin/ecs
def send_agenda_to_board(request, meeting_pk=None):
    meeting = get_object_or_404(Meeting, pk=meeting_pk)

    agenda_pdf = meeting.get_agenda_pdf(request)
    agenda_filename = '{}-{}-{}.pdf'.format(slugify(meeting.title),
        timezone.localtime(meeting.start).strftime('%d-%m-%Y'),
        slugify(_('agenda')))
    timetable_pdf = meeting.get_timetable_pdf(request)
    timetable_filename = '{}-{}-{}.pdf'.format(slugify(meeting.title),
        timezone.localtime(meeting.start).strftime('%d-%m-%Y'),
        slugify(_('time slot')))
    attachments = (
        (agenda_filename, agenda_pdf, 'application/pdf'),
        (timetable_filename, timetable_pdf, 'application/pdf'),
    )
    subject = _('EC Meeting {}').format(
        timezone.localtime(meeting.start).strftime('%d.%m.%Y'))
    reply_to = AdvancedSettings.objects.get().contact_email

    users = User.objects.filter(meeting_participations__entry__meeting=meeting).distinct()
    for user in users:
        timeframe = meeting._get_timeframe_for_user(user)
        if timeframe is None:
            continue
        start, end = timeframe
        htmlmail = str(render_html(request, \
                   'meetings/messages/boardmember_invitation.html', \
                   {'meeting': meeting, 'start': start, 'end': end, 'recipient': user}))
        deliver(user.email, subject=subject, message=None,
            message_html=htmlmail, from_email=settings.DEFAULT_FROM_EMAIL,
            rfc2822_headers={"Reply-To": reply_to},
            attachments=attachments)

    for user in User.objects.filter(groups__name__in=settings.ECS_MEETING_AGENDA_RECEIVER_GROUPS):
        start, end = meeting.start, meeting.end
        htmlmail = str(render_html(request, \
                    'meetings/messages/resident_boardmember_invitation.html', \
                    {'meeting': meeting, 'recipient': user}))
        deliver(user.email, subject=subject, message=None,
            message_html=htmlmail, from_email=settings.DEFAULT_FROM_EMAIL,
            rfc2822_headers={"Reply-To": reply_to},
            attachments=attachments)

    tops_with_primary_investigator = meeting.timetable_entries.filter(submission__invite_primary_investigator_to_meeting=True, submission__current_submission_form__primary_investigator__user__isnull=False, timetable_index__isnull=False)
    for top in tops_with_primary_investigator:
        sf = top.submission.current_submission_form
        for u in {sf.primary_investigator.user, sf.presenter, sf.submitter, sf.sponsor}:
            send_system_message_template(u, subject, 'meetings/messages/primary_investigator_invitation.txt', {'top': top}, submission=top.submission)

    meeting.agenda_sent_at = timezone.now()
    meeting.save()

    return redirect('ecs.meetings.views.meeting_details', meeting_pk=meeting.pk)
Exemplo n.º 2
0
def create_phantom_user(email, role=None):
    user = create_user(email)
    profile = user.profile
    profile.is_phantom = True
    profile.forward_messages_after_minutes = 5
    profile.save()

    if not role == 'investigator':  # see #4808
        invitation = Invitation.objects.create(user=user)

        subject = 'Erstellung eines Zugangs zum ECS'
        link = '{0}{1}'.format(
            settings.ABSOLUTE_URL_PREFIX,
            reverse('ecs.users.views.accept_invitation',
                    kwargs={'invitation_uuid': invitation.uuid.hex}))
        htmlmail = str(
            render_html(HttpRequest(),
                        'users/invitation/invitation_email.html', {
                            'link': link,
                        }))
        msgid, rawmail = deliver_to_recipient(email,
                                              subject,
                                              None,
                                              settings.DEFAULT_FROM_EMAIL,
                                              message_html=htmlmail)

    return user
Exemplo n.º 3
0
Arquivo: views.py Projeto: wuxxin/ecs
def get_vote_sign_data(request, task):
    vote = task.data
    html_template = 'votes/pdf/vote_preview.html'
    context = vote.get_render_context()
    return {
        'success_func':
        sign_success,
        'parent_pk':
        vote.pk,
        'parent_type':
        Vote,
        'document_uuid':
        uuid4().hex,
        'document_name':
        vote.submission_form.submission.get_ec_number_display(separator='-'),
        'document_type':
        "votes",
        'document_version':
        'signed-at',
        'document_filename':
        vote.pdf_filename,
        'document_barcodestamp':
        True,
        'html_preview':
        render_html(request, html_template, context),
        'pdf_data':
        vote.render_pdf()
    }
Exemplo n.º 4
0
def invite_user(request, email):
    comment = None
    try:
        sid = transaction.savepoint()
        user, created = User.objects.get_or_create(email=email, defaults={'username': email[:30]})
        if not created:
            raise ValueError(_(u'There is already a user with this email address.'))
        user.ecs_profile.phantom = True
        user.ecs_profile.save()

        invitation = Invitation.objects.create(user=user)

        subject = _(u'ECS account creation')
        link = request.build_absolute_uri(reverse('ecs.users.views.accept_invitation', kwargs={'invitation_uuid': invitation.uuid}))
        htmlmail = unicode(render_html(request, 'users/invitation/invitation_email.html', {
            'link': link,
        }))
        transferlist = deliver(subject, None, settings.DEFAULT_FROM_EMAIL, email, message_html=htmlmail)
        try:
            msgid, rawmail = transferlist[0]
            print rawmail
        except IndexError:
            raise ValueError(_(u'The email could not be delivered.'))
    except ValueError, e:
        transaction.savepoint_rollback(sid)
        comment = unicode(e)
Exemplo n.º 5
0
def submission_billing(request):
    unbilled_submissions = list(Submission.objects.filter(billed_at=None, current_submission_form__acknowledged=True))
    for submission in unbilled_submissions:
        submission.price = Price.objects.get_for_submission(submission)

    if request.method == 'POST':
        selected_for_billing = []
        for submission in unbilled_submissions:
            if request.POST.get('bill_%s' % submission.pk, False):
                selected_for_billing.append(submission)
                
        xls = SimpleXLS()
        xls.write_row(0, (_(u'amt.'), _(u'EC-Number'), _(u'company'), _(u'Eudract-Nr.'), _(u'applicant'), _(u'clinic'), _(u'sum')))
        for i, submission in enumerate(selected_for_billing):
            r = i + 1
            submission_form = submission.current_submission_form
            xls.write_row(i + 1, [
                "%s." % r,
                submission.get_ec_number_display(),
                _get_address(submission_form, submission_form.invoice_name and 'invoice' or 'sponsor'),
                submission_form.eudract_number or '?',
                submission_form.submitter_contact.full_name,
                _get_organizations(submission_form),
                submission.price.price,
            ])
        r = len(selected_for_billing) + 1
        xls.write(r, 6, xlwt.Formula('SUM(G2:G%s)' % r))
        
        xls_buf = StringIO()
        xls.save(xls_buf)
        now = datetime.datetime.now()
        doc = Document.objects.create_from_buffer(xls_buf.getvalue(), mimetype='application/vnd.ms-excel', date=now)

        Submission.objects.filter(pk__in=[s.pk for s in selected_for_billing]).update(billed_at=now)

        htmlmail = unicode(render_html(request, 'billing/email/submissions.html', {}))
        plainmail = whitewash(htmlmail)

        deliver(subject=_(u'Billing request'), 
            message=plainmail,
            message_html=htmlmail,
            attachments=[('billing-%s.xls' % now.strftime('%Y%m%d-%H%I%S'), xls_buf.getvalue(), 'application/vnd.ms-excel'),],
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=settings.BILLING_RECIPIENT_LIST, 
        )

        summary, total = collect_submission_billing_stats(selected_for_billing)
        
        return render(request, 'billing/submission_summary.html', {
            'summary': summary,
            'xls_doc': doc,
            'total': total,
        })
        return HttpResponseRedirect(reverse('ecs.billing.views.submission_billing'))

    return render(request, 'billing/submissions.html', {
        'submissions': unbilled_submissions,
    })
Exemplo n.º 6
0
Arquivo: diff.py Projeto: wuxxin/ecs
 def _render(plainhtml=False):
     data = {
         'doc': doc,
         'plainhtml': plainhtml,
         'submission_form': self.submission_form,
         'user': get_current_user(),
     }
     return render_html(HttpRequest(), 'submissions/diff/document.html',
                        data)
Exemplo n.º 7
0
def external_review_payment(request):
    submissions = Submission.objects.filter(external_reviewer=True, external_reviewer_billed_at=None, external_reviewer_name__isnull=False)
    price = Price.objects.get_review_price()

    if request.method == 'POST':
        selected_for_payment = []
        for submission in submissions:
            if request.POST.get('pay_%s' % submission.pk, False):
                selected_for_payment.append(submission)
        reviewers = User.objects.filter(reviewed_submissions__in=selected_for_payment).distinct()
        
        xls = SimpleXLS()
        xls.write_row(0, (_(u'amt.'), _(u'reviewer'), _(u'EC-Nr.'), _(u'sum')))
        for i, reviewer in enumerate(reviewers):
            submissions = reviewer.reviewed_submissions.filter(pk__in=[s.pk for s in selected_for_payment])
            xls.write_row(i + 1, [
                len(submissions),
                reviewer.get_full_name(),
                ", ".join(s.get_ec_number_display() for s in submissions),
                len(submissions) * price.price,
            ])
        r = len(reviewers) + 1
        xls.write_row(r, [
            xlwt.Formula('SUM(A2:A%s)' % r),
            "",
            "",
            xlwt.Formula('SUM(D2:D%s)' % r),
        ])
        
        xls_buf = StringIO()
        xls.save(xls_buf)
        now = datetime.datetime.now()
        doc = Document.objects.create_from_buffer(xls_buf.getvalue(), mimetype='application/vnd.ms-excel', date=now)
        
        Submission.objects.filter(pk__in=[s.pk for s in selected_for_payment]).update(external_reviewer_billed_at=now)
        
        htmlmail = unicode(render_html(request, 'billing/email/external_review.html', {}))
        plainmail = whitewash(htmlmail)
        
        deliver(subject=_(u'Payment request'), 
            message=plainmail,
            message_html=htmlmail,
            attachments=[('externalreview-%s.xls' % now.strftime('%Y%m%d-%H%I%S'), xls_buf.getvalue(), 'application/vnd.ms-excel'),],
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=settings.BILLING_RECIPIENT_LIST, 
        )
        
        return render(request, 'billing/external_review_summary.html', {
            'reviewers': reviewers,
            'xls_doc': doc,
        })

    return render(request, 'billing/external_review.html', {
        'submissions': submissions,
        'price': price,
    })
Exemplo n.º 8
0
def register(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        token = _registration_token_factory.generate_token(form.cleaned_data)
        activation_url = request.build_absolute_uri(reverse('ecs.users.views.activate', kwargs={'token': token}))        
        htmlmail = unicode(render_html(request, 'users/registration/activation_email.html', {
            'activation_url': activation_url,
            'form': form,
        }))
        deliver(subject=_(u'ECS - Registration'), message=None, message_html=htmlmail,
            from_email= settings.DEFAULT_FROM_EMAIL, recipient_list=form.cleaned_data['email'])
        return render(request, 'users/registration/registration_complete.html', {})
        
    return render(request, 'users/registration/registration_form.html', {
        'form': form,
    })
Exemplo n.º 9
0
def request_password_reset(request):
    form = RequestPasswordResetForm(request.POST or None)
    if form.is_valid():
        token = _password_reset_token_factory.generate_token(form.cleaned_data['email'])
        reset_url = request.build_absolute_uri(reverse('ecs.users.views.do_password_reset', kwargs={'token': token}))
        htmlmail = unicode(render_html(request, 'users/password_reset/reset_email.html', {
            'reset_url': reset_url,
        }))
        deliver(subject=_(u'ECS - Password Reset'), message=None, message_html=htmlmail,
            from_email= settings.DEFAULT_FROM_EMAIL, recipient_list=form.cleaned_data['email'])
        return render(request, 'users/password_reset/request_complete.html', {
            'email': form.cleaned_data['email'],
        })
    return render(request, 'users/password_reset/request_form.html', {
        'form': form,
    })
Exemplo n.º 10
0
Arquivo: views.py Projeto: wuxxin/ecs
def get_notification_answer_sign_data(request, task):
    notification = task.data
    answer = notification.answer
    html_template = notification.type.get_template('notifications/answers/pdf/%s.html')
    context = answer.get_render_context()
    return {
        'success_func': sign_success,
        'parent_pk': answer.pk,
        'parent_type': NotificationAnswer,
        'document_uuid': uuid4().hex,
        'document_name': notification.get_filename('-answer'),
        'document_type': "notification_answer",
        'document_version': 'signed-at',
        'document_filename': notification.get_filename('-answer.pdf'),
        'document_barcodestamp': True,
        'html_preview': render_html(request, html_template, context),
        'pdf_data': answer.render_pdf(),
    }
Exemplo n.º 11
0
Arquivo: views.py Projeto: wuxxin/ecs
def send_protocol(request, meeting_pk=None):
    meeting = get_object_or_404(Meeting, ended__isnull=False,
        protocol_sent_at=None, pk=meeting_pk)

    meeting.protocol_sent_at = timezone.now()
    meeting.save()

    protocol_pdf = meeting.protocol.retrieve_raw().read()
    attachments = (
        (meeting.protocol.original_file_name, protocol_pdf, 'application/pdf'),
    )

    for user in User.objects.filter(Q(meeting_participations__entry__meeting=meeting) | Q(groups__name__in=settings.ECS_MEETING_PROTOCOL_RECEIVER_GROUPS)).distinct():
        htmlmail = str(render_html(request, 'meetings/messages/protocol.html', {'meeting': meeting, 'recipient': user}))
        deliver(user.email, subject=_('Meeting Protocol'), message=None,
            message_html=htmlmail, from_email=settings.DEFAULT_FROM_EMAIL,
            attachments=attachments)

    return redirect('ecs.meetings.views.meeting_details', meeting_pk=meeting.pk)
Exemplo n.º 12
0
Arquivo: views.py Projeto: wuxxin/ecs
def open_tasks(request, meeting=None):
    tops = list(meeting.timetable_entries.filter(submission__isnull=False).select_related('submission', 'submission__current_submission_form'))
    tops.sort(key=lambda e: e.agenda_index)

    open_tasks = OrderedDict()
    for top in tops:
        ts = list(
            Task.unfiltered.for_submission(top.submission).open()
                .select_related('task_type', 'task_type__group', 'assigned_to',
                    'assigned_to__profile', 'medical_category')
                .order_by('created_at')
        )
        if len(ts):
            open_tasks[top] = ts
    
    return render_html(request, 'meetings/tabs/open_tasks.html', {
        'meeting': meeting,
        'open_tasks': open_tasks,
    })
Exemplo n.º 13
0
def agenda_htmlemail(request, meeting_pk=None):
    meeting = get_object_or_404(Meeting, pk=meeting_pk)
    filename = '%s-%s-%s.pdf' % (
        meeting.title, meeting.start.strftime('%d-%m-%Y'), _('agenda')
    )
    pdf = render_pdf(request, 'db/meetings/xhtml2pdf/agenda.html', {
        'meeting': meeting,
    })

    for recipient in settings.AGENDA_RECIPIENT_LIST:        
        htmlmail = unicode(render_html(request, 'meetings/email/invitation-with-agenda.html', {
            'meeting': meeting,
            'recipient': recipient,
        }))
        plainmail = whitewash(htmlmail)

        deliver(subject=_('Invitation to meeting'), 
            message=plainmail,
            message_html=htmlmail,
            attachments=[(filename, pdf,'application/pdf'),],
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=settings.AGENDA_RECIPIENT_LIST)

    return HttpResponseRedirect(reverse('ecs.meetings.views.upcoming_meetings'))
Exemplo n.º 14
0
Arquivo: diff.py Projeto: emulbreh/ecs
    def render(self, instance, plain=False):
        if not plain:
            raise NotImplementedError

        return render_html(HttpRequest(), 'submissions/diff/document.inc', {'doc': instance})