Example #1
0
File: logs.py Project: nirgal/ngw
    def get_context_data(self, **kwargs):
        context = {}
        context['title'] = _('Global log')
        context['objtype'] = Log
        context['nav'] = Navbar(Log.get_class_navcomponent())

        context.update(kwargs)
        return super().get_context_data(**context)
Example #2
0
    def delete(self, request, *args, **kwargs):
        obj = self.object = self.get_object()
        success_url = self.get_success_url()

        name = str(obj)
        log = Log()
        log.contact_id = self.request.user.id
        log.action = LOG_ACTION_DEL
        pk_names = (obj._meta.pk.attname,)  # default django pk name
        log.target = obj.__class__.__name__ + ' ' + ' '.join(
            [str(obj.__getattribute__(fieldname)) for fieldname in pk_names])
        log.target_repr = obj.get_class_verbose_name() + ' '+name
        log.save()

        self.object.delete()
        messages.add_message(request, messages.SUCCESS,
                             _('{} has been deleted.').format(name))
        return HttpResponseRedirect(success_url)