Beispiel #1
0
    def post(self, slug):
        proj = Project.get(slug)
        if proj is None:
            abort(404)

        data = json.loads(request.data)
        form = ProjectAddParticipationForm(MultiDict(data))
        if not form.validate():
            return Response(json.dumps({
                'errors': form.errors,
            }), 400)

        party = Participation()
        form.populate_obj(party)
        del party.maker
        party.add_link(proj, tag='project')

        maker = Maker.get(form.maker.data)
        if maker is None:
            return Response(json.dumps({
                'errors': {
                    'maker': ['Maker ID is invalid'],
                }
            }), 400)
        party.add_link(maker, tag='maker')
        party.save()

        maker.add_link(party, tag='participation')
        maker.save()
        proj.add_link(party, tag='participation')
        proj.save()
        return self.render(party)
Beispiel #2
0
    def post(self, slug):
        proj = Project.get(slug)
        if proj is None:
            return Response(json.dumps({}), 404)

        data = json.loads(request.data)
        form = ProjectAddParticipationForm(MultiDict(data))
        if not form.validate():
            return Response(json.dumps({
                'errors': form.errors,
            }), 400)

        party = Participation()
        form.populate_obj(party)
        del party.maker
        del party.reason
        party.add_link(proj, tag='project')

        maker = Maker.get(form.maker.data)
        if maker is None:
            return Response(json.dumps({
                'errors': {
                    'maker': ['Maker ID is invalid'],
                }
            }), 400)

        party.add_link(maker, tag='maker')
        party.save()

        history = History(
            action='addparty',
            reason=form.reason.data,
            when=datetime.utcnow().replace(microsecond=0).isoformat(),
            old_data={},  # addparties never have old data
            new_data=party.get_entity_data(),
        )
        history.add_link(current_user, tag='user')
        history.add_link(maker, tag='maker')
        history.add_link(proj, tag='project')
        history.add_link(party, tag='participation')
        history.save()

        party.add_link(history, tag='history')
        party.save()

        maker.add_link(party, tag='participation')
        maker.add_link(history, tag='history')
        maker.save()
        proj.add_link(party, tag='participation')
        proj.add_link(history, tag='history')
        proj.save()

        return self.render(party)