コード例 #1
0
def source_suggest():
    user_mc = user_admin_mediacloud_client()
    url = request.form['url']
    feed_url = request.form['feedurl'] if 'feedurl' in request.form else None
    name = request.form['name'] if 'name' in request.form else None
    reason = request.form['reason'] if 'reason' in request.form else None
    tag_ids_to_add = tag_ids_from_collections_param()
    new_suggestion = user_mc.mediaSuggest(url=url,
                                          name=name,
                                          feed_url=feed_url,
                                          reason=reason,
                                          collections=tag_ids_to_add)
    # send an email confirmation
    email_title = "Thanks for Suggesting " + url
    send_html_email(
        email_title, [user_name(), '*****@*****.**'],
        render_template("emails/source_suggestion_ack.txt",
                        username=user_name(),
                        name=name,
                        url=url,
                        feed_url=feed_url,
                        reason=reason),
        render_template("emails/source_suggestion_ack.html",
                        username=user_name(),
                        name=name,
                        url=url,
                        feed_url=feed_url,
                        reason=reason))
    # and return that it worked
    return jsonify(new_suggestion)
コード例 #2
0
def _email_batch_source_update_results(audit_feedback):
    email_title = "Source Batch Updates"
    content_title = "You just uploaded {} sources to a collection.".format(
        len(audit_feedback))
    updated_sources = []
    for updated in audit_feedback:
        updated_sources.append(updated)

    content_body = updated_sources
    action_text = "Login to Media Cloud"
    action_url = "https://sources.mediacloud.org/#/login"
    # send an email confirmation
    send_html_email(
        email_title, [user_name(), '*****@*****.**'],
        render_template("emails/source_batch_upload_ack.txt",
                        content_title=content_title,
                        content_body=content_body,
                        action_text=action_text,
                        action_url=action_url),
        render_template("emails/source_batch_upload_ack.html",
                        email_title=email_title,
                        content_title=content_title,
                        content_body=content_body,
                        action_text=action_text,
                        action_url=action_url))
コード例 #3
0
def source_suggestion_update(suggestion_id):
    user_mc = user_admin_mediacloud_client()
    suggestion = _media_suggestion(user_mc, suggestion_id)
    if suggestion is None:
        return json_error_response("Unknown suggestion id {}".format(suggestion_id))
    status = request.form['status']
    reason = request.form['reason']
    results = None
    email_note = ""
    if status == "approved":
        # if approved, we have to create it
        flattend_tags = [t['tags_id'] for t in suggestion['tags_ids']]

        media_source_to_create = {
            'url': suggestion['url'],
            'name': suggestion['name'],
            'feeds': [suggestion['feed_url']],
            'tags_ids': flattend_tags,
            'editor_notes': 'Suggested approved by {} on because {}.  Suggested by {} on {} because {}'
                            '(id #{}).'.format(user_name(),  datetime.now().strftime("%I:%M%p on %B %d, %Y"), reason,
                                               suggestion['email'], suggestion['date_submitted'], suggestion['reason'],
                                               suggestion['media_suggestions_id']
                                               )
        }
        creation_results = user_mc.mediaCreate([media_source_to_create])[0]
        if creation_results['status'] == 'error':
            status = "pending"  # so the email update looks good.
            email_note = creation_results['error']+".  "
        else:
            email_note = "This source is "+str(creation_results['status'])+". "
            results = user_mc.mediaSuggestionsMark(suggestion_id, status, reason, creation_results['media_id'])
    else:
        # if rejected just mark it as such
        results = user_mc.mediaSuggestionsMark(suggestion_id, status, reason)
    # send an email to the person that suggested it
    url = suggestion['url']
    email_title = "Source Suggestion {}: {}".format(status, url)
    content_title = "We {} {}".format(status, url)
    content_body = "Thanks for the suggestion. {}{}".format(email_note, reason)
    action_text = "Login to Media Cloud"
    action_url = "https://sources.mediacloud.org/#/login"
    # send an email confirmation
    send_html_email(email_title,
                    [user_name(), '*****@*****.**'],
                    render_template("emails/generic.txt", content_title=content_title, content_body=content_body,
                                    action_text=action_text, action_url=action_url),
                    render_template("emails/generic.html", email_title=email_title, content_title=content_title,
                                    content_body=content_body, action_text=action_text, action_url=action_url)
                    )
    # and return that it worked or not
    if status == "pending":
        return json_error_response(email_note)
    return jsonify(results)
コード例 #4
0
def source_suggestion_update(suggestion_id):
    user_mc = user_admin_mediacloud_client()
    suggestion = _media_suggestion(user_mc, suggestion_id)
    if suggestion is None:
        return json_error_response("Unknown suggestion id {}".format(suggestion_id))
    status = request.form['status']
    reason = request.form['reason']
    results = None
    email_note = ""
    if status == "approved":
        # if approved, we have to create it
        flattend_tags = [t['tags_id'] for t in suggestion['tags_ids']]

        media_source_to_create = { 'url': suggestion['url'],
              'name': suggestion['name'],
              'feeds': [suggestion['feed_url']],
              'tags_ids': flattend_tags,
              'editor_notes': 'Suggested approved by {} on because {}.  Suggested by {} on {} because {} (id #{}).'.format(
                  user_name(),  datetime.now().strftime("%I:%M%p on %B %d, %Y"), reason,
                  suggestion['email'], suggestion['date_submitted'], suggestion['reason'], suggestion['media_suggestions_id']
              )
            }
        creation_results = user_mc.mediaCreate([media_source_to_create])[0]
        if creation_results['status'] == 'error':
            status = "pending"  # so the email update looks good.
            email_note = creation_results['error']+".  "
        else:
            email_note = "This source is "+str(creation_results['status'])+". "
            results = user_mc.mediaSuggestionsMark(suggestion_id, status, reason, creation_results['media_id'])
    else:
        # if rejected just mark it as such
        results = user_mc.mediaSuggestionsMark(suggestion_id, status, reason)
    # send an email to the person that suggested it
    url = suggestion['url']
    email_title = "Source Suggestion {}: {}".format(status, url)
    content_title = "We {} {}".format(status, url)
    content_body = "Thanks for the suggestion. {}{}".format(email_note, reason)
    action_text = "Login to Media Cloud"
    action_url = "https://sources.mediacloud.org/#/login"
    # send an email confirmation
    send_html_email(email_title,
                    [user_name(), '*****@*****.**'],
                    render_template("emails/generic.txt",
                                    content_title=content_title, content_body=content_body, action_text=action_text, action_url=action_url),
                    render_template("emails/generic.html",
                                    email_title=email_title, content_title=content_title, content_body=content_body, action_text=action_text, action_url=action_url)
                    )
    # and return that it worked or not
    if status == "pending":
        return json_error_response(email_note)
    return jsonify(results)
コード例 #5
0
def source_suggest():
    user_mc = user_admin_mediacloud_client()
    url = request.form['url']
    feed_url = request.form['feedurl'] if 'feedurl' in request.form else None
    name = request.form['name'] if 'name' in request.form else None
    reason = request.form['reason'] if 'reason' in request.form else None
    tag_ids_to_add = tag_ids_from_collections_param()
    new_suggestion = user_mc.mediaSuggest(url=url, name=name, feed_url=feed_url, reason=reason,
                                          tags_ids=tag_ids_to_add)
    # send an email confirmation
    email_title = "Thanks for Suggesting " + url
    send_html_email(email_title,
                    [user_name(), '*****@*****.**'],
                    render_template("emails/source_suggestion_ack.txt", username=user_name(), name=name, url=url,
                                    feed_url=feed_url, reason=reason),
                    render_template("emails/source_suggestion_ack.html", username=user_name(), name=name, url=url,
                                    feed_url=feed_url, reason=reason)
                    )
    # and return that it worked
    return jsonify(new_suggestion)
コード例 #6
0
def _email_batch_source_update_results(audit_feedback):
    email_title = "Source Batch Updates"
    content_title = "You just uploaded {} sources to a collection.".format(len(audit_feedback))
    updated_sources = []
    for updated in audit_feedback:
        updated_sources.append(updated)

    content_body = updated_sources
    action_text = "Login to Media Cloud"
    action_url = "https://sources.mediacloud.org/#/login"
    # send an email confirmation
    send_html_email(email_title,
                    [user_name(), '*****@*****.**'],
                    render_template("emails/source_batch_upload_ack.txt",
                                    content_title=content_title, content_body=content_body, action_text=action_text,
                                    action_url=action_url),
                    render_template("emails/source_batch_upload_ack.html",
                                    email_title=email_title, content_title=content_title, content_body=content_body,
                                    action_text=action_text, action_url=action_url)
                    )