Exemplo n.º 1
0
    def post(self, request, **kwargs):
        self.object = self.get_object()
        context = self.get_context_data(**kwargs)
        version = context["this_version"]
        object = context["current_version"]

        for name, value in version.field_dict.items():
            if value == "[deleted]":
                setattr(object, name, None)
            else:
                setattr(object, name, value)

        object.save()
        if version.field_dict.get("devicetype") is not None:
            TypeAttributeValue.objects.filter(
                device=version.object_id).delete()
        reversion.set_comment("Reverted to version from {0}".format(
            version.revision.date_created))
        reversion.set_ignore_duplicates(True)

        messages.success(
            self.request,
            _('Successfully reverted Device to revision {0}').format(
                version.revision.id))

        return HttpResponseRedirect(object.get_absolute_url())
Exemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     if "room" in request.POST:
         if request.POST["room"] != "" and request.POST["room"] != 0:
             roomid = request.POST["room"][0]
             room = get_object_or_404(Room, pk=roomid)
         else:
             room = None
     else:
         room = None
     response = super(DeviceApiLend, self).post(request)
     if request.POST["device"] != "" and response.status_code == 201:
         device = Device.objects.get(pk=request.POST["device"])
         device.currentlending = self.object
         if room:
             device.room = room
             reversion.set_user(request.user)
             reversion.set_comment("Device marked as lend")
             try:
                 template = MailTemplate.objects.get(usage="room")
             except:
                 template = None
             if not template == None:
                 recipients = []
                 for recipient in template.default_recipients.all():
                     recipient = recipient.content_object
                     if isinstance(recipient, Group):
                         recipients += recipient.lageruser_set.all().values_list("email")[0]
                     else:
                         recipients.append(recipient.email)
                 template.send(self.request, recipients, {"device": device, "user": self.request.user})
         reversion.set_ignore_duplicates(True)
         device.save()
     return response
Exemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     if "room" in request.POST:
         if request.POST["room"] != "" and request.POST["room"] != 0:
             roomid = request.POST["room"][0]
             room = get_object_or_404(Room, pk=roomid)
         else:
             room = None
     else:
         room = None
     response = super(DeviceApiLend, self).post(request)
     if request.POST["device"] != "" and response.status_code == 201:
         device = Device.objects.get(pk=request.POST["device"])
         device.currentlending = self.object
         if room:
             device.room = room
             reversion.set_user(request.user)
             reversion.set_comment("Device marked as lend")
             try:
                 template = MailTemplate.objects.get(usage="room")
             except:
                 template = None
                 messages.error(self.request, _('MAIL NOT SENT - Template for room change does not exist'))
             if template is not None:
                 recipients = []
                 for recipient in template.default_recipients.all():
                     recipient = recipient.content_object
                     if isinstance(recipient, Group):
                         recipients += recipient.lageruser_set.all().values_list("email")[0]
                     else:
                         recipients.append(recipient.email)
                 template.send(self.request, recipients, {"device": device, "user": self.request.user})
         reversion.set_ignore_duplicates(True)
         device.save()
     return response
Exemplo n.º 4
0
 def testCanSaveIgnoringDuplicates(self):
     with create_revision():
         self.test11.save()
         self.test12.save()
         self.test21.save()
         self.test22.save()
         self.assertFalse(get_ignore_duplicates())
         set_ignore_duplicates(True)
         self.assertTrue(get_ignore_duplicates())
     self.assertEqual(get_for_object(self.test11).count(), 2)
     # Save a non-duplicate revision.
     with create_revision():
         self.test11.save()
         self.assertFalse(get_ignore_duplicates())
         set_ignore_duplicates(True)
     self.assertEqual(get_for_object(self.test11).count(), 3)
Exemplo n.º 5
0
 def testCanSaveIgnoringDuplicates(self):
     with create_revision():
         self.test11.save()
         self.test12.save()
         self.test21.save()
         self.test22.save()
         self.assertFalse(get_ignore_duplicates())
         set_ignore_duplicates(True)
         self.assertTrue(get_ignore_duplicates())
     self.assertEqual(get_for_object(self.test11).count(), 2)
     # Save a non-duplicate revision.
     with create_revision():
         self.test11.save()
         self.assertFalse(get_ignore_duplicates())
         set_ignore_duplicates(True)
     self.assertEqual(get_for_object(self.test11).count(), 3)
Exemplo n.º 6
0
    def post(self, request, **kwargs):
        self.object = self.get_object()
        context = self.get_context_data(**kwargs)
        version = context["this_version"]
        object = context["current_version"]

        for name, value in version.field_dict.items():
            if value == "[deleted]":
                setattr(object,name, None)
            else:
                setattr(object,name, value)

        object.save()
        if version.field_dict.get("devicetype") != None:
            TypeAttributeValue.objects.filter(device=version.object_id).delete()
        reversion.set_comment("Reverted to version from {0}".format(version.revision.date_created))
        reversion.set_ignore_duplicates(True)

        messages.success(self.request,
                        _('Successfully reverted Device to revision {0}').format(version.revision.id))


        return HttpResponseRedirect(object.get_absolute_url())
Exemplo n.º 7
0
 def save(self, *args, **kwargs):
     reversion.set_ignore_duplicates(True)
     overriding_skip_cdms = kwargs.pop('skip_cdms', self._cdms_skip)
     with override_skip_cdms(self, overriding_skip_cdms):
         return super(CDMSModel, self).save(*args, **kwargs)