Exemplo n.º 1
0
    def clean_file(self):
        file = self.cleaned_data['file']
        schedule_code = file.read()
        file.seek(0)
        parser = ScheduleParser()

        schedule = []
        try:
            schedule = parser.parse(schedule_code)
        except SyntaxError, e:
            raise forms.ValidationError('File %s contains syntax errors (line %s, col %s): %s' % (file.name, e.lineno, e.offset, e.text))
Exemplo n.º 2
0
    def save(self):
        schedule_code = self.cleaned_data['file'].read()
        parser = ScheduleParser()

        schedule = parser.parse(schedule_code)

        with transaction.commit_on_success():
            t = Trigger.objects.get(method__name=schedule['trigger_method'], method__interface__name=schedule['trigger_interface'])

            s = Schedule(trigger=t, name=schedule['schedule_name'], schedule_file=self.cleaned_data['file'])
            s.save()

            for action in schedule['actions']:
                a = Action.objects.get(name=action['action_name'])
                sa = ScheduleAction(schedule=s, action=a)

                if action['trigger_from'] != None:
                    ad = ActionDevice.objects.get(action=a, parameter_position=action['trigger_from'])
                    sa.trigger_device = ad
                sa.save()