コード例 #1
0
class ComplaintController(object):
    """A controller to register complaints against objects."""
    def register(self, license_pool, raw_data):

        if license_pool is None:
            return problem(None, 400, _("No license pool specified"))

        _db = Session.object_session(license_pool)
        try:
            data = json.loads(raw_data)
        except ValueError, e:
            return problem(None, 400, _("Invalid problem detail document"))

        type = data.get('type')
        source = data.get('source')
        detail = data.get('detail')
        if not type:
            return problem(None, 400, _("No problem type specified."))
        if type not in Complaint.VALID_TYPES:
            return problem(None, 400,
                           _("Unrecognized problem type: %(type)s", type=type))

        complaint = None
        try:
            complaint = Complaint.register(license_pool, type, source, detail)
            _db.commit()
        except ValueError, e:
            return problem(
                None, 400,
                _("Error registering complaint: %(error)s", error=str(e)))
コード例 #2
0
 def _complaint(self, license_pool, type, source, detail, resolved=None):
     complaint, is_new = Complaint.register(
         license_pool,
         type,
         source,
         detail,
         resolved
     )
     return complaint
コード例 #3
0
 def _complaint(self, license_pool, type, source, detail, resolved=None):
     complaint, is_new = Complaint.register(
         license_pool,
         type,
         source,
         detail,
         resolved
     )
     return complaint
コード例 #4
0
    async def complain(self, conversation_id: int, complainer: User) -> bool:
        log.info(f'complaint about conversation {conversation_id}')
        self._validate_conversation_and_peer(conversation_id, complainer)
        conversation = self._active_dialogs[conversation_id]

        if len(conversation.messages) == 0:
            return False

        complain_to = [x.peer for x in conversation.participants if x.peer != complainer][0]

        complaint = Complaint(complainer=complainer,
                              complain_to=complain_to,
                              conversation=conversation)

        def save_complaint_and_dialog():
            conversation.save()
            complaint.save()

        await run_sync_in_executor(save_complaint_and_dialog)
        return True
コード例 #5
0
 def complaint(self):
     return Complaint(complainer=self.user,
                      complain_to=self.bot,
                      conversation=self.conversation,
                      processed=True)