Example #1
0
    def payment_reminders_sent_at(self):
        from workbench.tools.history import changes  # Avoid a circular import

        actions = LoggedAction.objects.for_model(self).with_data(id=self.id)
        return [
            day for day in [
                change.values["last_reminded_on"]
                for change in changes(self, {"last_reminded_on"}, actions)
            ] if day
        ]
Example #2
0
def history(request, db_table, attribute, id):
    try:
        model = DB_TABLE_TO_MODEL[db_table]
        cfg = HISTORY[model]
    except KeyError:
        raise Http404

    if callable(cfg):
        cfg = cfg(request.user)
    fields = cfg.get("fields", set())

    instance = None
    title = None
    related = []

    if attribute == "id":
        try:
            instance = model._base_manager.get(**{attribute: id})
        except Exception:
            instance = None
            title = model._meta.verbose_name

        related = [
            (
                capfirst(model._meta.verbose_name_plural),
                reverse("history", args=(model._meta.db_table, attribute, id)),
            )
            for model, attribute in cfg.get("related", [])
        ]
    else:
        title = _("%(model)s with %(attribute)s=%(id)s") % {
            "model": capfirst(model._meta.verbose_name_plural),
            "attribute": attribute,
            "id": id,
        }

    actions = LoggedAction.objects.for_model(model).with_data(**{attribute: id})

    return render(
        request,
        "history_modal.html",
        {
            "instance": instance,
            "title": title,
            "changes": changes(model, fields, actions),
            "related": related,
        },
    )
Example #3
0
def deal_history(date_range, *, users=None):
    actions = LoggedAction.objects.for_model(Deal).filter(created_at__range=[
        timezone.make_aware(dt.datetime.combine(day, time))
        for day, time in zip(date_range, [dt.time.min, dt.time.max])
    ])
    fields = {
        "id",
        "title",
        "value",
        "probability",
        "decision_expected_on",
        "status",
        "closing_type",
        "closing_notice",
    }
    user_ids = EVERYTHING if users is None else {user.id
                                                 for user in users} | {None}
    return [
        change for change in changes(Deal, fields, actions)
        if change.version.user_id in user_ids
    ]