Пример #1
0
def generate_comment_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = Comment
    type_ = "comment"
    if option == "jtlist":
        # Sets display url
        details_url = ''
        details_url_key = "id"
        fields = [
            "obj_type", "comment", "url_key", "created", "analyst", "source",
            "id"
        ]
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type, request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title':
        "Comments",
        'default_sort':
        "date DESC",
        'listurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_),
                args=('jtlist', )),
        'deleteurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_),
                args=('jtdelete', )),
        'searchurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_)),
        'fields':
        ["details", "obj_type", "comment", "date", "analyst", "source", "id"],
        'hidden_fields': [
            "id",
        ],
        'linked_fields': [
            "analyst",
        ],
        'details_link':
        'details',
        'no_sort': [
            'details',
        ],
    }
    jtable = build_jtable(jtopts, request)
    if option == "inline":
        return render_to_response(
            "jtable.html", {
                'jtable': jtable,
                'jtid': '%s_listing' % type_,
                'button': '%ss_tab' % type_
            }, RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_, {
            'jtable': jtable,
            'jtid': '%s_listing' % type_
        }, RequestContext(request))
Пример #2
0
def generate_dataset_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.
    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = Dataset
    type_ = "dataset"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type,request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title': "Datasets",
        'default_sort': mapper['default_sort'],
        'listurl': reverse('cripts.%ss.views.%ss_listing' %
                           (type_, type_), args=('jtlist',)),
        'deleteurl': reverse('cripts.%ss.views.%ss_listing' %
                             (type_, type_), args=('jtdelete',)),
        'searchurl': reverse(mapper['searchurl']),
        'fields': mapper['jtopts_fields'],
        'hidden_fields': mapper['hidden_fields'],
        'linked_fields': mapper['linked_fields'],
        'details_link': mapper['details_link'],
        'no_sort': mapper['no_sort']
    }
    jtable = build_jtable(jtopts,request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Datasets'",
            'text': "'All'",
            'click': "function () {$('#dataset_listing').jtable('load', {'refresh': 'yes','status': 'All'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Datasets'",
            'text': "'New'",
            'click': "function () {$('#dataset_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'In Progress Datasets'",
            'text': "'In Progress'",
            'click': "function () {$('#dataset_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Analyzed Datasets'",
            'text': "'Analyzed'",
            'click': "function () {$('#dataset_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Deprecated Datasets'",
            'text': "'Deprecated'",
            'click': "function () {$('#dataset_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Add Dataset'",
            'text': "'Add Dataset'",
            'click': "function () {$('#new-dataset').click()}",
        },
    ]
    if option == "inline":
        return render_to_response("jtable.html",
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_,
                                   'button' : '%ss_tab' % type_},
                                  RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_,
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_},
                                  RequestContext(request))
Пример #3
0
def generate_analysis_results_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = AnalysisResult
    type_ = "analysis_result"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type,request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title': "Analysis Results",
        'default_sort': mapper['default_sort'],
        'listurl': reverse('cripts.services.views.%ss_listing' % type_,
                           args=('jtlist',)),
        'deleteurl': reverse('cripts.services.views.%ss_listing' % type_,
                             args=('jtdelete',)),
        'searchurl': reverse(mapper['searchurl']),
        'fields': mapper['jtopts_fields'],
        'hidden_fields': mapper['hidden_fields'],
        'linked_fields': mapper['linked_fields'],
        'details_link': mapper['details_link'],
        'no_sort': mapper['no_sort']
    }
    jtable = build_jtable(jtopts,request)
    jtable['toolbar'] = [
    ]
    if option == "inline":
        return render_to_response("jtable.html",
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_,
                                   'button' : '%ss_tab' % type_},
                                  RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_,
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_},
                                  RequestContext(request))
Пример #4
0
def generate_email_address_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.
    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = EmailAddress
    type_ = "email_address"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type,request):
            
            # Update the email stats
            counts = mongo_connector(settings.COL_COUNTS)
            count_stats = counts.find_one({'name': 'counts'})
            if not count_stats or ('counts' not in count_stats):
                count_stats = {'counts':{}}
            if 'Email Addresses' not in count_stats['counts']:
                count_stats['counts']['Email Addresses'] = 0
            else:
                count_stats['counts']['Email Addresses'] = count_stats['counts']['Email Addresses'] - 1                                
            counts.update({'name': "counts"}, {'$set': {'counts': count_stats['counts']}}, upsert=True) 
            
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title': "Email Addresses",
        'default_sort': mapper['default_sort'],
        'listurl': reverse('cripts.%ses.views.%ses_listing' %
                           (type_, type_), args=('jtlist',)),
        'deleteurl': reverse('cripts.%ses.views.%ses_listing' %
                             (type_, type_), args=('jtdelete',)),
        'searchurl': reverse(mapper['searchurl']),
        'fields': mapper['jtopts_fields'],
        'hidden_fields': mapper['hidden_fields'],
        'linked_fields': mapper['linked_fields'],
        'details_link': mapper['details_link'],
        'no_sort': mapper['no_sort']
    }
    jtable = build_jtable(jtopts,request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Email Addresses'",
            'text': "'All'",
            'click': "function () {$('#email_address_listing').jtable('load', {'refresh': 'yes'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Email Addresses'",
            'text': "'New'",
            'click': "function () {$('#email_address_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Add Email Address'",
            'text': "'Add Email Address'",
            'click': "function () {$('#new-email_address').click()}",
        },
    ]
    if option == "inline":
        return render_to_response("jtable.html",
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_,
                                   'button' : '%ses_tab' % type_},
                                  RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_,
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_},
                                  RequestContext(request))
Пример #5
0
def generate_event_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = Event
    type_ = "event"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']

        # filter list on relationship to given ObjectId
        query = {}
        if 'related' in request.GET:
            try:
                oid = ObjectId(request.GET.get('related'))
                query = {'relationships.value': oid}
            except:
                pass

        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields,
                                    query=query)
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type, request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title':
        "Events",
        'default_sort':
        mapper['default_sort'],
        'listurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_),
                args=('jtlist', )),
        'deleteurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_),
                args=('jtdelete', )),
        'searchurl':
        reverse('cripts.%ss.views.%ss_listing' % (type_, type_)),
        'fields':
        mapper['jtopts_fields'],
        'hidden_fields':
        mapper['hidden_fields'],
        'linked_fields':
        mapper['linked_fields'],
        'details_link':
        mapper['details_link'],
        'no_sort':
        mapper['no_sort']
    }
    jtable = build_jtable(jtopts, request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Events'",
            'text': "'All'",
            'click':
            "function () {$('#event_listing').jtable('load', {'refresh': 'yes','status': 'All'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Events'",
            'text': "'New'",
            'click':
            "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'In Progress Events'",
            'text': "'In Progress'",
            'click':
            "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Analyzed Events'",
            'text': "'Analyzed'",
            'click':
            "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Deprecated Events'",
            'text': "'Deprecated'",
            'click':
            "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Add Event'",
            'text': "'Add Event'",
            'click': "function () {$('#new-event').click()}",
        },
    ]
    if option == "inline":
        return render_to_response(
            "jtable.html", {
                'jtable': jtable,
                'jtid': '%s_listing' % type_,
                'button': '%ss_tab' % type_
            }, RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_, {
            'jtable': jtable,
            'jtid': '%s_listing' % type_
        }, RequestContext(request))
Пример #6
0
def generate_comment_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = Comment
    type_ = "comment"
    if option == "jtlist":
        # Sets display url
        details_url = ''
        details_url_key = "id"
        fields = ["obj_type", "comment", "url_key", "created",
                   "analyst", "source", "id"]
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type,request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title': "Comments",
        'default_sort': "date DESC",
        'listurl': reverse('cripts.%ss.views.%ss_listing' % (type_,
                                                            type_),
                           args=('jtlist',)),
        'deleteurl': reverse('cripts.%ss.views.%ss_listing' % (type_,
                                                              type_),
                             args=('jtdelete',)),
        'searchurl': reverse('cripts.%ss.views.%ss_listing' % (type_,type_)),
        'fields': ["details",
                   "obj_type",
                   "comment",
                   "date",
                   "analyst",
                   "source",
                   "id"],
        'hidden_fields': ["id", ],
        'linked_fields': ["analyst", ],
        'details_link': 'details',
        'no_sort': ['details', ],
    }
    jtable = build_jtable(jtopts,request)
    if option == "inline":
        return render_to_response("jtable.html",
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_,
                                   'button' : '%ss_tab' % type_},
                                  RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_,
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_},
                                  RequestContext(request))
Пример #7
0
def generate_email_address_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.
    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    obj_type = EmailAddress
    type_ = "email_address"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields)
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type, request):

            # Update the email stats
            counts = mongo_connector(settings.COL_COUNTS)
            count_stats = counts.find_one({'name': 'counts'})
            if not count_stats or ('counts' not in count_stats):
                count_stats = {'counts': {}}
            if 'Email Addresses' not in count_stats['counts']:
                count_stats['counts']['Email Addresses'] = 0
            else:
                count_stats['counts']['Email Addresses'] = count_stats[
                    'counts']['Email Addresses'] - 1
            counts.update({'name': "counts"},
                          {'$set': {
                              'counts': count_stats['counts']
                          }},
                          upsert=True)

            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title':
        "Email Addresses",
        'default_sort':
        mapper['default_sort'],
        'listurl':
        reverse('cripts.%ses.views.%ses_listing' % (type_, type_),
                args=('jtlist', )),
        'deleteurl':
        reverse('cripts.%ses.views.%ses_listing' % (type_, type_),
                args=('jtdelete', )),
        'searchurl':
        reverse(mapper['searchurl']),
        'fields':
        mapper['jtopts_fields'],
        'hidden_fields':
        mapper['hidden_fields'],
        'linked_fields':
        mapper['linked_fields'],
        'details_link':
        mapper['details_link'],
        'no_sort':
        mapper['no_sort']
    }
    jtable = build_jtable(jtopts, request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Email Addresses'",
            'text': "'All'",
            'click':
            "function () {$('#email_address_listing').jtable('load', {'refresh': 'yes'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Email Addresses'",
            'text': "'New'",
            'click':
            "function () {$('#email_address_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Add Email Address'",
            'text': "'Add Email Address'",
            'click': "function () {$('#new-email_address').click()}",
        },
    ]
    if option == "inline":
        return render_to_response(
            "jtable.html", {
                'jtable': jtable,
                'jtid': '%s_listing' % type_,
                'button': '%ses_tab' % type_
            }, RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_, {
            'jtable': jtable,
            'jtid': '%s_listing' % type_
        }, RequestContext(request))