def create_feedbackdrafts(self, groups, points, feedbacktext_raw, feedbacktext_html, publish=False):
     draft_ids = []
     for group in groups:
         delivery_id = group.last_delivery_id
         draft = FeedbackDraft(
             delivery_id=delivery_id,
             points=points,
             feedbacktext_raw=feedbacktext_raw,
             feedbacktext_html=feedbacktext_html,
             saved_by=self.request.user
         )
         if publish:
             draft.published = True
             draft.staticfeedback = draft.to_staticfeedback()
             draft.staticfeedback.full_clean()
             draft.staticfeedback.save()
         draft.save()
         draft_ids.append(draft.id)
     return draft_ids
Esempio n. 2
0
    def create_feedbackdraft(self,
                             points,
                             feedbacktext_raw,
                             feedbacktext_html,
                             feedbackfile_uploadedfile,
                             feedbackfile_has_changed,
                             publish=False):
        draft = FeedbackDraft(delivery=self.delivery,
                              points=points,
                              feedbacktext_raw=feedbacktext_raw,
                              feedbacktext_html=feedbacktext_html,
                              saved_by=self.request.user)

        if feedbackfile_has_changed:
            if self.last_feedbackdraftfile:
                self.last_feedbackdraftfile.file.delete()
                self.last_feedbackdraftfile.delete()
            if feedbackfile_uploadedfile:
                feedbackdraftfile = FeedbackDraftFile(
                    delivery=self.delivery,
                    saved_by=self.request.user,
                    filename=feedbackfile_uploadedfile.name)
                feedbackdraftfile.file.save(feedbackfile_uploadedfile.name,
                                            feedbackfile_uploadedfile)
                self.last_feedbackdraftfile = feedbackdraftfile

        if publish:
            draft.published = True
            staticfeedback = draft.to_staticfeedback()
            staticfeedback.full_clean()
            staticfeedback.save()
            draft.staticfeedback = staticfeedback
            if self.last_feedbackdraftfile:
                self.last_feedbackdraftfile.to_staticfeedbackfileattachment(
                    staticfeedback=draft.staticfeedback)
        draft.save()
        return draft