def post(self, participant_id, field_slug):
        participant = self.get_object(participant_id)
        cf = self.get_custom_field(participant, field_slug, field_type='image')
        cfv = self.get_custom_field_value(cf, participant)

        form = request.form
        x1 = int(form.get('x1', 0, type=float))
        y1 = int(form.get('y1', 0, type=float))
        x2 = int(form.get('x2', 0, type=float))
        y2 = int(form.get('y2', 0, type=float))

        unlink_uploaded_file(cfv.value,
                             'crop',
                             dir_name=app.config['PATH_CUSTOM_KEY'])
        unlink_thumbnail_file(cfv.value, dir_name='crops')

        valid_crop = x2 > 0 and y2 > 0
        if valid_crop:
            crop_file(cfv.value, 'custom', (x1, y1, x2, y2))
        if participant.participant_type == Participant.PARTICIPANT:
            url = url_for('.participant_detail', participant_id=participant_id)
        else:
            url = url_for('.media_participant_detail',
                          participant_id=participant_id)
        return redirect(url)
    def post(self, participant_id, field_slug):
        participant = self.get_object(participant_id)
        cf = self.get_custom_field(participant, field_slug,
                                   field_type='image')
        cfv = self.get_custom_field_value(cf, participant)

        form = request.form
        x1 = int(form.get('x1', 0, type=float))
        y1 = int(form.get('y1', 0, type=float))
        x2 = int(form.get('x2', 0, type=float))
        y2 = int(form.get('y2', 0, type=float))

        unlink_uploaded_file(cfv.value, 'crop',
                             dir_name=app.config['PATH_CUSTOM_KEY'])
        unlink_thumbnail_file(cfv.value, dir_name='crops')

        valid_crop = x2 > 0 and y2 > 0
        if valid_crop:
            crop_file(cfv.value, 'custom', (x1, y1, x2, y2))
        if participant.participant_type == Participant.PARTICIPANT:
            url = url_for('.participant_detail', participant_id=participant_id)
        else:
            url = url_for('.media_participant_detail',
                          participant_id=participant_id)
        return redirect(url)
 def delete(self, category_id):
     category = CategoryDefault.query.get_or_404(category_id)
     db.session.delete(category)
     db.session.commit()
     unlink_uploaded_file(category.background, 'backgrounds')
     flash('Category successfully deleted', 'warning')
     return jsonify(status="success", url=url_for('.categories'))
 def delete(self, category_id):
     category = CategoryDefault.query.get_or_404(category_id)
     db.session.delete(category)
     db.session.commit()
     unlink_uploaded_file(category.background, 'backgrounds')
     flash('Category successfully deleted', 'warning')
     return jsonify(status="success", url=url_for('.categories'))
Example #5
0
 def delete(self, category_id):
     category = Category.query.filter_by(
         id=category_id,
         meeting_id=g.meeting.id).first_or_404()
     count = (
         Participant.query.current_meeting()
         .filter_by(category=category)
         .count())
     if count:
         msg = ("Unable to remove the category. There are %s participants "
                "in this category. Please assign them to another category "
                "before removing this one.") % count
         return jsonify(status="error", message=msg)
     db.session.delete(category)
     db.session.commit()
     unlink_uploaded_file(category.background, 'backgrounds')
     flash('Category successfully deleted', 'warning')
     return jsonify(status="success", url=url_for('.categories'))
 def delete(self, category_id):
     category = Category.query.filter_by(
         id=category_id,
         meeting_id=g.meeting.id).first_or_404()
     count = (
         Participant.query.current_meeting()
         .filter_by(category=category)
         .count())
     if count:
         msg = ("Unable to remove the category. There are %s participants "
                "in this category. Please assign them to another category "
                "before removing this one.") % count
         return jsonify(status="error", message=msg)
     db.session.delete(category)
     db.session.commit()
     unlink_uploaded_file(category.background, 'backgrounds')
     flash('Category successfully deleted', 'warning')
     return jsonify(status="success", url=url_for('.categories'))
    def crop_image(self, field_slug, field_value):
        # XXX We need to check if the ratio is respected, and enforce it
        #  here.
        try:
            x1 = int(float(getattr(self, '%s_x1_' % field_slug).data))
            y1 = int(float(getattr(self, '%s_y1_' % field_slug).data))
            x2 = int(float(getattr(self, '%s_x2_' % field_slug).data))
            y2 = int(float(getattr(self, '%s_y2_' % field_slug).data))
        except (AttributeError, ValueError, TypeError, OverflowError):
            return

        unlink_uploaded_file(field_value,
                             'crop',
                             dir_name=app.config['PATH_CUSTOM_KEY'])
        unlink_thumbnail_file(field_value, dir_name='crops')

        valid_crop = x2 > 0 and y2 > 0
        if valid_crop:
            crop_file(field_value, 'custom', (x1, y1, x2, y2))
    def save(self):
        category = self.obj or self.meta.model()
        background = category.background
        self.populate_obj(category)
        category.background = background

        if self.background.data:
            unlink_uploaded_file(background, 'backgrounds')
            category.background = backgrounds.save(
                self.background.data,
                name=str(uuid4()) + '.')
        elif self.background_delete.data:
            unlink_uploaded_file(background, 'backgrounds')
            category.background = None

        if category.id is None:
            db.session.add(category)
        db.session.commit()

        return category
    def save(self):
        category = self.obj or self.meta.model()
        background = category.background
        self.populate_obj(category)
        category.background = background

        if self.background.data:
            unlink_uploaded_file(background, 'backgrounds')
            category.background = backgrounds.save(self.background.data,
                                                   name=str(uuid4()) + '.')
        elif self.background_delete.data:
            unlink_uploaded_file(background, 'backgrounds')
            category.background = None

        category.tags = CategoryTag.query.filter(
            CategoryTag.id.in_(self.category_tags.data)).all()
        if category.id is None:
            db.session.add(category)
        db.session.commit()

        return category