Beispiel #1
0
    def _get_date_range_filter_args(self, start, end):
        date_format = "%b. %d, %Y, %I:%M %p"
        start_local_date_time_str = convert_local_to_utc(
            start, self.local_time_delta, date_format).strftime(date_format)
        end_local_date_time_str = convert_local_to_utc(
            end, self.local_time_delta, date_format).strftime(date_format)

        return super(SubmissionDateRangeFilter,
                     self)._get_date_range_filter_args(
                         start_local_date_time_str, end_local_date_time_str)
Beispiel #2
0
def show_log(request):
    organization = get_organization(request)
    org_id = organization.org_id
    args = dict(organization=org_id)
    time_delta = get_country_time_delta(organization.country)
    if request.method == 'GET':
        form = LogFilterForm(request=request)
    else:
        form = LogFilterForm(request.POST, request=request)
        filter = form.data.copy()
        filter.pop("csrfmiddlewaretoken")
        for key, value in filter.items():
            if value != "":
                if key == "daterange":
                    dates = value.split(" %s " % ugettext("to"))
                    # args["log_date__gte"] = convert_dmy_to_ymd(dates[0])
                    args["log_date__gte"] = convert_local_to_utc(
                        dates[0] + " 00:00:00", time_delta,
                        "%d-%m-%Y %H:%M:%S")
                    try:
                        end_date = date.today()
                        if len(dates) > 1:
                            # end_date = convert_dmy_to_ymd(dates[1])
                            end_date = convert_local_to_utc(
                                dates[1] + " 23:59:59", time_delta,
                                "%d-%m-%Y %H:%M:%S")
                        else:
                            end_date = convert_local_to_utc(
                                dates[0] + " 23:59:59", time_delta,
                                "%d-%m-%Y %H:%M:%S")
                    except KeyError:
                        pass
                    args["log_date__lte"] = "%s" % end_date
                    continue
                args[key] = value
    log_data = UserActivityLog.objects.select_related().filter(
        **args).order_by("-log_date")
    for entry in log_data:
        entry.log_date = convert_utc_to_localized(time_delta, entry.log_date)
    return render_to_response(
        "activitylog/activitylog.html", {
            'form': form,
            'is_pro_sms': organization.is_pro_sms,
            'log_data': repr(encode_json([log.to_render()
                                          for log in log_data]))
        },
        context_instance=RequestContext(request))
Beispiel #3
0
def show_log(request):
    organization = get_organization(request)
    org_id = organization.org_id
    args = dict(organization=org_id)
    time_delta = get_country_time_delta(organization.country)
    if request.method == 'GET':
        form = LogFilterForm(request=request)
    else:
        form = LogFilterForm(request.POST, request=request)
        filter = form.data.copy()
        filter.pop("csrfmiddlewaretoken")
        for key, value in filter.items():
            if value != "":
                if key == "daterange":
                    dates = value.split(" %s " % _("to"))
                    # args["log_date__gte"] = convert_dmy_to_ymd(dates[0])
                    args["log_date__gte"] = convert_local_to_utc(
                        dates[0] + " 00:00:00", time_delta,
                        "%d-%m-%Y %H:%M:%S")
                    try:
                        end_date = date.today()
                        if len(dates) > 1:
                            # end_date = convert_dmy_to_ymd(dates[1])
                            end_date = convert_local_to_utc(
                                dates[1] + " 23:59:59", time_delta,
                                "%d-%m-%Y %H:%M:%S")
                        else:
                            end_date = convert_local_to_utc(
                                dates[0] + " 23:59:59", time_delta,
                                "%d-%m-%Y %H:%M:%S")
                    except KeyError:
                        pass
                    args["log_date__lte"] = "%s" % end_date
                    continue
                args[key] = value
    log_data = UserActivityLog.objects.select_related().filter(
        **args).order_by("-log_date")
    for entry in log_data:
        entry.log_date = convert_utc_to_localized(time_delta, entry.log_date)
        action = entry.action
        if action == "Updated reminders":
            try:
                current_lang = get_language()
                activate(current_lang)
                details = json.loads(entry.detail)
                text_details = ""
                text_details += "<ul class='bulleted'>"
                for key, value in details.iteritems():
                    if value != "":
                        text_details += "<li>" + _(key) % value + "</li>"
                    else:
                        text_details += "<li>" + _(key) + "</li>"
                text_details += "</ul>"
                entry.detail = text_details
            except ValueError:
                entry.detail = _(entry.detail)

        if action == "Set Deadline":
            try:
                current_lang = get_language()
                activate(current_lang)
                entry.detail = _(entry.detail)

            except ValueError:
                entry.detail = _(entry.detail)

        if action == "Edited Data Submission(s) for advanced questionnaire":
            try:
                current_lang = get_language()
                activate(current_lang)
                details = json.loads(entry.detail)
                text_details = ""
                text_details += _("Changed Answers:")
                text_details += "<ul class='bulleted'>"
                for key, value in details.iteritems():
                    question = unicode(value['question'])
                    #if value['old'] and value['new']:
                    try:
                        old_data_value = str(value['old'].encode('UTF-8'))
                        new_data_value = str(value['new'].encode('UTF-8'))
                        text_details += '<li>' + question + ': "' + old_data_value.decode(
                            'UTF-8') + '" ' + _(
                                "to") + ' "' + new_data_value.decode(
                                    'UTF-8') + '"</li>'
                    #except :
                    #new_data_value = str(value['new'])
                    #text_details += '<li>'+ _("New node: ") + '</br>' + question + ':' + new_data_value +'"</li>'
                    #else :
                    #old_data_value = str(value['old'])
                    #text_details += '<li>'+ _("Delete node: ") + '</br>' + question + ':' + old_data_value +'"</li>'
                    except (ValueError, IndexError):
                        entry.detail = _(entry.detail)
                text_details += "</ul>"
                entry.detail = text_details

            except:
                entry.detail = _(entry.detail)
    return render_to_response(
        "activitylog/activitylog.html", {
            'form': form,
            'is_pro_sms': organization.is_pro_sms,
            'log_data': repr(encode_json([log.to_render()
                                          for log in log_data]))
        },
        context_instance=RequestContext(request))