Esempio n. 1
0
def feedback(request, template_name='feedback.html'):

    if request.method == 'POST':  # If the form has been submitted...
        form = ContactForm(request.POST)
        if form.is_valid():  # All validation rules pass

            subject = request.POST.get('topic', '').encode('ascii', 'ignore')
            name = request.POST.get('name', '').encode('ascii', 'ignore')
            message = request.POST.get('message', '').encode('ascii', 'ignore')
            from_email = request.POST.get('email', '')

            emails_to_feedback = []
            for k, v in settings.ADMINS:
                emails_to_feedback.append(v)

            try:
                message_admin = "Name: " + str(name) + "\nEmail: " + from_email + "\n\nMessage:\n" + str(message)
                message = "Dear " + name + ",\n\nThank you for giving us your feedback.\n\nYour message will be analyzed by EMIF Catalogue team.\n\nMessage sent:\n" + str(message) + "\n\nSincerely,\nEMIF Catalogue"
                # Send email to admins
                send_custom_mail(subject, message_admin, settings.DEFAULT_FROM_EMAIL, emails_to_feedback)
                # Send email to user with the copy of feedback message
                send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [from_email])

            except BadHeaderError:
                return HttpResponse('Invalid header found.')

            return feedback_thankyou(request)

    else:
        form = ContactForm()  # An unbound form
        if request.user.is_authenticated():
            form=ContactForm(initial={'name': request.user.get_full_name(),'email':request.user.email})

    return render(request, template_name, {'form': form, 'request': request, 'breadcrumb': True})
    def close(issue_number, send_mail=False):
        try:
            bugreport = BugReport.open.get(issue=issue_number)

            bugreport.closed = True
            bugreport.close_date = timezone.now()

            if send_mail:
                send_custom_mail(
                    'EMIF Catalogue: Bug Report #%d solved' % (issue_number),
                    """ Dear %s,\n\n
                    The following bug report:\n
                    <blockquote>
                    %s\n
                    </blockquote>
                    has been solved by our development team, and will be incorporated in our next scheduled system update.
                    \n\n
                    Sincerely,\n
                    EMIF Catalogue
                """ % (bugreport.requester.get_full_name(), bugreport.report),
                    settings.DEFAULT_FROM_EMAIL, [bugreport.requester.email])

            bugreport.save()

        except BugReport.DoesNotExist:
            pass
Esempio n. 3
0
def sendCommitEmails(p, pv):
    emails = [p.owner.email]
    adict = dict(settings.ADMINS)
    for admin in adict:
        emails.append(adict[admin])

    desc = ""
    if pv.submitted_desc:
        desc = """
            The following description was added:\n
                "
                %s
                " """ % (pv.submitted_desc)
    # sent email to admin and developer about plugin
    try:
        send_custom_mail(
            'EMIF Catalogue: Plugin %s v.%s submitted for approval' %
            (p.name, pv.version), """Dear Colleague,\n
                    A new plugin version %s for plugin %s has been submitted for approval on the platform <a href="http://bioinformatics.ua.pt/emif">EMIF Catalogue</a>.

                    %s

                    The system administrators will review and approve it as soon as possible.\n
                    \n\n
                    \n\nSincerely,\nEMIF Catalogue
            """ % (pv.version, p.name, desc), settings.DEFAULT_FROM_EMAIL,
            emails)
    except:
        print "Couldn't send email for commit approval"
Esempio n. 4
0
def report_bug(request):

    if request.method == 'POST':  # If the form has been submitted...
        form = BugReportForm(request.POST)
        if form.is_valid():  # All validation rules pass

            title = request.POST.get('title', '').encode('ascii', 'ignore')
            name = request.user.get_full_name()

            description = "<strong>Description: </strong>" + request.POST.get(
                'description', '').encode('ascii', 'ignore')
            description += "\n<strong>Steps to reproduce: </strong>" + request.POST.get(
                'steps', '').encode('ascii', 'ignore')
            description += "\n<strong>Expected result: </strong>" + request.POST.get(
                'expected', '').encode('ascii', 'ignore')
            description += "\n<strong>Priority: </strong>" + request.POST.get(
                'priority', '').encode('ascii', 'ignore')

            from_email = request.user.email
            issue = IssueManager(settings.GITHUB_USERNAME,
                                 settings.GITHUB_PASSWD)
            browser = ''
            try:
                browser = request.META['HTTP_USER_AGENT']
            except:
                pass

            description = description + "\n\nReported by %s, email: %s with: %s" % (
                name, from_email, browser)
            newissue = issue.create(title, description)

            if newissue.number != None:
                br = BugReport(issue=newissue.number,
                               requester=request.user,
                               report=description)

                br.save()

            emails_to_feedback = [from_email]
            for k, v in settings.ADMINS:
                emails_to_feedback.append(v)

            try:
                send_custom_mail(title, description,
                                 settings.DEFAULT_FROM_EMAIL,
                                 emails_to_feedback)
            except:
                pass
            return feedback_thankyou(request)

    else:
        form = BugReportForm()  # An unbound form
    return render(request, 'bugreport.html', {
        'form': form,
        'request': request,
        'breadcrumb': True
    })
Esempio n. 5
0
def sendNotification(timeframe,
                     destiny,
                     origin,
                     href,
                     message,
                     custom_mail_message=None):

    notification = None

    timeout = timezone.now() - timeframe

    existing_notifications = Notification.objects.filter(
        destiny=destiny,
        origin=origin,
        href=href,
        notification=message,
        created_date__gt=timeout).order_by("-created_date")

    # if theres notifications inside the time frame, just update it
    if len(existing_notifications) >= 1:
        notification = existing_notifications[0]
        notification.created_date = timezone.now()
        notification.removed = False
        notification.read = False
        notification.read_date = None
        notification.save()
    else:
        # if theres no notification inside the time frame create a new one
        notification = Notification(destiny=destiny,
                                    origin=origin,
                                    href=href,
                                    notification=message)
        notification.save()

    if notification != None and notification.destiny.emif_profile.mail_not == True:
        subject = None
        message = None
        if custom_mail_message != None:
            (subject, message) = custom_mail_message
        else:
            subject = "EMIF Catalogue: Notification"
            message = """Dear %s,\n\n
                    \n\n
                    %s\n\n
                    You can see it <a href="%s%s">here</a>.
                    \n\nSincerely,\nEMIF Catalogue
                """ % (notification.destiny.get_full_name(),
                       notification.notification, settings.BASE_URL,
                       notification.href)

        send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                         [notification.destiny.email])
Esempio n. 6
0
def invitedb(request, db_id, template_name="sharedb.html"):

    email = request.POST.get('email', '')
    message_write = request.POST.get('message', '')
    if (email == None or email == ''):
        return HttpResponse('Invalid email address.')

    fingerprint = None
    try:
        fingerprint = Fingerprint.objects.get(fingerprint_hash=db_id)
    except Fingerprint.DoesNotExist:
        print "Fingerprint with id " + db_id + " does not exist."
        return HttpResponse("Service Unavailable")

    subject = "EMIF Catalogue: A new database is trying to be shared with you."
    link_invite = settings.BASE_URL + "accounts/signup/"

    #message = """Dear %s,\n\n
    #        \n
    #        %s is sharing a new database with you on Emif Catalogue.
    #        First you must register on the EMIF Catalogue. Please follow the link below: \n\n
    #        %s
    #        \n\nSincerely,\nEMIF Catalogue
    #""" % (email,request.user.get_full_name(), link_invite)

    message = """%s\n
            To have full access to this fingerprint, please register in the EMIF Catalogue following the link below: \n\n
            %s
            \n\nSincerely,\nEMIF Catalogue
    """ % (message_write, link_invite)

    send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])

    pend = None

    try:
        pend = InvitePending.objects.get(fingerprint=fingerprint, email=email)
        return HttpResponse("User already has been invited to join catalogue")
    except:
        pass

    pend = InvitePending(fingerprint=fingerprint, email=email)
    pend.save()

    return HttpResponse(
        "An invitation has been sent to the user email so he can signup on catalogue"
    )
Esempio n. 7
0
def feedback(request, template_name='feedback.html'):

    if request.method == 'POST':  # If the form has been submitted...
        form = ContactForm(request.POST)
        if form.is_valid():  # All validation rules pass

            subject = request.POST.get('topic', '').encode('ascii', 'ignore')
            name = request.POST.get('name', '').encode('ascii', 'ignore')
            message = request.POST.get('message', '').encode('ascii', 'ignore')
            from_email = request.POST.get('email', '')

            emails_to_feedback = []
            for k, v in settings.ADMINS:
                emails_to_feedback.append(v)

            try:
                message_admin = "Name: " + str(
                    name) + "\nEmail: " + from_email + "\n\nMessage:\n" + str(
                        message)
                message = "Dear " + name + ",\n\nThank you for giving us your feedback.\n\nYour message will be analyzed by EMIF Catalogue team.\n\nMessage sent:\n" + str(
                    message) + "\n\nSincerely,\nEMIF Catalogue"
                # Send email to admins
                send_custom_mail(subject, message_admin,
                                 settings.DEFAULT_FROM_EMAIL,
                                 emails_to_feedback)
                # Send email to user with the copy of feedback message
                send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                                 [from_email])

            except BadHeaderError:
                return HttpResponse('Invalid header found.')

            return feedback_thankyou(request)

    else:
        form = ContactForm()  # An unbound form
        if request.user.is_authenticated():
            form = ContactForm(initial={
                'name': request.user.get_full_name(),
                'email': request.user.email
            })

    return render(request, template_name, {
        'form': form,
        'request': request,
        'breadcrumb': True
    })
Esempio n. 8
0
def invitedb(request, db_id, template_name="sharedb.html"):

    email = request.POST.get('email', '')
    message_write = request.POST.get('message', '')
    if (email == None or email==''):
        return HttpResponse('Invalid email address.')

    fingerprint = None
    try:
        fingerprint = Fingerprint.objects.get(fingerprint_hash=db_id)
    except Fingerprint.DoesNotExist:
        print "Fingerprint with id "+db_id+" does not exist."
        return HttpResponse("Service Unavailable")

    subject = "EMIF Catalogue: A new database is trying to be shared with you."
    link_invite = settings.BASE_URL + "accounts/signup/"

    #message = """Dear %s,\n\n
    #        \n
    #        %s is sharing a new database with you on Emif Catalogue.
    #        First you must register on the EMIF Catalogue. Please follow the link below: \n\n
    #        %s
    #        \n\nSincerely,\nEMIF Catalogue
    #""" % (email,request.user.get_full_name(), link_invite)

    message = """%s\n
            To have full access to this fingerprint, please register in the EMIF Catalogue following the link below: \n\n
            %s
            \n\nSincerely,\nEMIF Catalogue
    """ % (message_write, link_invite)


    send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])

    pend = None

    try:
        pend = InvitePending.objects.get(fingerprint=fingerprint, email=email)
        return HttpResponse("User already has been invited to join catalogue")
    except:
        pass

    pend = InvitePending(fingerprint=fingerprint, email=email)
    pend.save()

    return HttpResponse("An invitation has been sent to the user email so he can signup on catalogue")
Esempio n. 9
0
def sendNotification(timeframe, destiny, origin, href, message, custom_mail_message=None):

        notification = None

        timeout = timezone.now() - timeframe

        existing_notifications = Notification.objects.filter(destiny = destiny, origin = origin, href=href,
            notification=message, created_date__gt=timeout).order_by("-created_date")

        # if theres notifications inside the time frame, just update it
        if len(existing_notifications) >= 1:
            notification = existing_notifications[0]
            notification.created_date = timezone.now()
            notification.removed = False
            notification.read = False
            notification.read_date = None
            notification.save()
        else:
            # if theres no notification inside the time frame create a new one
            notification = Notification(destiny = destiny, origin = origin, href=href,
            notification=message)
            notification.save()

        if notification != None and notification.destiny.emif_profile.mail_not == True:
            subject = None
            message = None
            if custom_mail_message != None:
                (subject, message) = custom_mail_message
            else:
                subject = "EMIF Catalogue: Notification"
                message = """Dear %s,\n\n
                    \n\n
                    %s\n\n
                    You can see it <a href="%s%s">here</a>.
                    \n\nSincerely,\nEMIF Catalogue
                """ % (notification.destiny.get_full_name(), notification.notification, settings.BASE_URL
                    ,notification.href)

            send_custom_mail(subject,
                message, settings.DEFAULT_FROM_EMAIL,
                [notification.destiny.email])
Esempio n. 10
0
    def post(self, request, *args, **kw):

        if request.user.is_authenticated():
            success = False

            private_link = request.POST.get('plid', -1)
            emails = request.POST.getlist('emails[]', [])

            try:
                plink = PublicFingerprintShare.objects.get(id=private_link)

                if len(emails) > 0:
                    fname = plink.fingerprint.findName()

                    message = """Dear Colleague,\n
                            %s shared with you a private link to their database "%s" on the platform <a href="http://bioinformatics.ua.pt/emif">EMIF Catalogue</a>. \n\n
                            The database can be visualised in the link below:\n
                            <a href="%s">%s</a>\n\n
                            \n\nSincerely,\nEMIF Catalogue
                    """ % (request.user.get_full_name(), fname,
                           settings.BASE_URL + 'public/fingerprint/' +
                           plink.hash, fname)

                    try:
                        send_custom_mail(
                            "EMIF Catalogue: A private link for a database is being shared with you.",
                            message, settings.DEFAULT_FROM_EMAIL, emails)

                        success = True
                    except:
                        print "-- Error: Couldn't send the email for private link sharing"

            except PublicFingerprintShare.DoesNotExist:
                print "-- Error: Retrieving public fingerprint share"

            response = Response({'success': success},
                                status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)
        return response
Esempio n. 11
0
    def post(self, request, *args, **kw):

        if request.user.is_authenticated():
            success=False

            private_link = request.POST.get('plid', -1)
            emails = request.POST.getlist('emails[]', [])

            try:
                plink  = PublicFingerprintShare.objects.get(id=private_link)

                if len(emails)>0:
                    fname = plink.fingerprint.findName()

                    message = """Dear Colleague,\n
                            %s shared with you a private link to their database "%s" on the platform <a href="http://bioinformatics.ua.pt/emif">EMIF Catalogue</a>. \n\n
                            The database can be visualised in the link below:\n
                            <a href="%s">%s</a>\n\n
                            \n\nSincerely,\nEMIF Catalogue
                    """ % (request.user.get_full_name(), fname, settings.BASE_URL+'public/fingerprint/'+plink.hash, fname)

                    try:
                        send_custom_mail("EMIF Catalogue: A private link for a database is being shared with you.",
                            message, settings.DEFAULT_FROM_EMAIL, emails)

                        success=True
                    except:
                        print "-- Error: Couldn't send the email for private link sharing"


            except PublicFingerprintShare.DoesNotExist:
                print "-- Error: Retrieving public fingerprint share"

            response = Response({'success': success}, status=status.HTTP_200_OK)

        else:
            response = Response({}, status=status.HTTP_403_FORBIDDEN)
        return response
Esempio n. 12
0
def report_bug(request):

    if request.method == 'POST':  # If the form has been submitted...
        form = BugReportForm(request.POST)
        if form.is_valid():  # All validation rules pass

            title = request.POST.get('title', '').encode('ascii', 'ignore')
            name = request.user.get_full_name()

            description = "<strong>Description: </strong>"+request.POST.get('description', '').encode('ascii', 'ignore')
            description += "\n<strong>Steps to reproduce: </strong>"+request.POST.get('steps', '').encode('ascii', 'ignore')
            description += "\n<strong>Expected result: </strong>"+request.POST.get('expected', '').encode('ascii', 'ignore')
            description += "\n<strong>Priority: </strong>"+request.POST.get('priority', '').encode('ascii', 'ignore')

            from_email = request.user.email
            issue = IssueManager(settings.GITHUB_USERNAME, settings.GITHUB_PASSWD)
            browser = ''
            try:
                browser = request.META['HTTP_USER_AGENT']
            except:
                pass

            description = description + "\n\nReported by %s, email: %s with: %s" % (name, from_email, browser)
            issue.create(title, description)

            emails_to_feedback = [from_email]
            for k, v in settings.ADMINS:
                emails_to_feedback.append(v)

            try:
                send_custom_mail(title, description, settings.DEFAULT_FROM_EMAIL, emails_to_feedback)
            except:
                pass
            return feedback_thankyou(request)

    else:
        form = BugReportForm()  # An unbound form
    return render(request, 'bugreport.html', {'form': form, 'request': request, 'breadcrumb': True})
Esempio n. 13
0
    for k, v in settings.ADMINS:
        emails_to_feedback.append(v)

    try:

        message = """%s

            Now you're able to edit and manage the database. \n\n
            To activate the database in your account, please open this link:
            %s
            \n\nSincerely,\nEMIF Catalogue
        """ % (message, link_activation)
        # Send email to admins
        #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, emails_to_feedback)
        # Send email to user with the copy of feedback message
        send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                         [from_email])

    except BadHeaderError:
        return HttpResponse('Service Unavailable')

    return HttpResponse(success_msg)


def sharedb_activation(request,
                       activation_code,
                       template_name="sharedb_invited.html"):

    return activate_user(activation_code,
                         request.user,
                         context=request,
                         template_name=template_name)
Esempio n. 14
0
    for k, v in settings.ADMINS:
        emails_to_feedback.append(v)

    try:

        message = """%s

            Now you're able to edit and manage the database. \n\n
            To activate the database in your account, please open this link:
            %s
            \n\nSincerely,\nEMIF Catalogue
        """ % (message,link_activation)
        # Send email to admins
        #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, emails_to_feedback)
        # Send email to user with the copy of feedback message
        send_custom_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [from_email])

    except BadHeaderError:
        return HttpResponse('Service Unavailable')

    return HttpResponse(success_msg)

def sharedb_activation(request, activation_code, template_name="sharedb_invited.html"):

    return activate_user(activation_code, request.user, context = request, template_name=template_name)


def export_all_answers(request):
    """
    Method to export all databases answers to a csv file
    """