def group_test_feed_output(group_id): """ Run the feed script for the group and return the output or error message. """ error = None output = "" group = None try: group = Groups.Group(g_id=group_id) except KeyError: abort(401) if not group.source == "feed": abort(401) feed = Feeds.Feed(f_id=group.feed) period = Periods.Period(p_id=group.period) scriptrun = ' '.join([feed.script, group.feedargs, period.code]) try: output = External.feeds_run_group_script(feed.script, args=[group.feedargs, period.code]) except BaseException as err: error = err return render_template( "admin_test_group_feed.html", output=output, error=error, scriptrun=scriptrun )
def admin_periods(): """ Present page to administer time periods in the system """ periods = Periods.all_list() return render_template( "admin_periods.html", periods=periods )
def admin_add_group(): """ Present page to add a group to the system """ feeds = Feeds.all_list() periods = Periods.all_list() gtypes = Groups.all_gtypes() return render_template( "admin_editgroup.html", feeds=feeds, periods=periods, group=Groups.Group(gtype=1), gtypes=gtypes )
def admin_edit_period(p_id): """ Present page to edit a time period in the system """ try: period = Periods.Period(p_id=p_id) except KeyError: return abort(404) else: period.start_date = period.start.strftime("%a %d %b %Y") period.finish_date = period.finish.strftime("%a %d %b %Y") return render_template( "admin_editperiod.html", period=period )
def period_obj(self): """ Period object """ if not self._period_obj: self._period_obj = Periods.Period(self.period) return self._period_obj
def admin_edit_period_submit(p_id): """ Submit edit period form """ if "cancel" in request.form: flash("Edit cancelled!") return redirect(url_for("admin_periods")) try: start = datetime.strptime(request.form['start'], "%a %d %b %Y") start_date = start.strftime("%a %d %b %Y") except ValueError: start = None start_date = "" try: finish = datetime.strptime(request.form['finish'], "%a %d %b %Y") finish_date = finish.strftime("%a %d %b %Y") except ValueError: finish = None finish_date = "" name = request.form.get('name', None) title = request.form.get('title', None) code = request.form.get('code', None) if p_id == 0: # It's a new one being created period = Periods.Period( p_id=0, name=name, title=title, code=code, start=start, finish=finish ) else: try: period = Periods.Period(p_id=p_id) except KeyError: return abort(404) period.id = p_id period.start = start period.finish = finish period.name = request.form['name'] period.title = request.form['title'] period.code = request.form['code'] period.start_date = start_date period.finish_date = finish_date error = False if not start: error = "Can't Save: can't understand start date." if not finish: error = "Can't Save: can't understand finish date." if name == "": error = "Can't Save: Name must be supplied" if not period.editable(): error = "That time period is not editable!" try: period.save() except ValueError as err: # Probably a duplicate or something error = "Can't Save: %s" % err if error: flash(error) return render_template( "admin_editperiod.html", period=period ) flash("Changes saved", category='success') return redirect(url_for("admin_periods"))