def send_digest(): digestables = Group.Group().get_digestables() for groupid in digestables: group = Group.Group(groupid) user = User.User(group.userID) digestable = group.get_digestable() if not digestable: continue feeds = {} for feedid, entryid in digestable: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) html = render_template("email.html", feeds=feeds.values(), group=group) # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Email digest: %s (issue: %s)" % (group.description, group.issue) msg['From'] = '*****@*****.**' msg['To'] = user.email text = 'switch to html' msg.attach(MIMEText(text, 'plain')) msg.attach(MIMEText(html, 'html')) s = smtplib.SMTP('localhost') s.sendmail(msg['From'], msg['To'], msg.as_string()) s.quit() group.update_sent() print('sent digest to: %s. %s' % (user.email, group.description)) return ('', 204)
def feedlist(): groupid = request.args.get('groupid', None) if groupid: group = Group.Group(int(groupid)) feedids = [feed.ID for feed in group.feeds] else: group = Group.Group(description='Unknonw group') feedids = [] f_ids = Feed.Feed().get_all() feeds = [Feed.Feed(id) for id in f_ids] return render_template('widget/feedlist.html', feeds=feeds, group=group, feedids=feedids), 200, { 'Cache-Control': 's-maxage=0' }
def instantiate_from(self, filename): datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or \ os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'fhir-parser', 'downloads')) with io.open(os.path.join(datadir, filename), 'r', encoding='utf-8') as handle: js = json.load(handle) self.assertEqual("Group", js["resourceType"]) return group.Group(js)
def testGroup3(self): inst = self.instantiate_from("group-example-patientlist.json") self.assertIsNotNone(inst, "Must have instantiated a Group instance") self.implGroup3(inst) js = inst.as_json() self.assertEqual("Group", js["resourceType"]) inst2 = group.Group(js) self.implGroup3(inst2)
def create_group(): user = User.User() if user.verify(session.get('das_hash', None)): aggregation = 'email' if request.form.get( 'aggregation') == 'true' else '' group = Group.Group(description=request.form.get('description'), aggregation=aggregation, frequency=request.form.get('frequency'), userID=user.ID)
def userpage(): user = User.User() if not user.verify(session.get('das_hash', None)): return render_template("login.html") group = Group.Group() groups = group.get_groups(userID=user.ID) return render_template("userpage.html", user=user, groups=groups, menu=usermenu())
def usermenu(): user = User.User() payload = '' if user.verify(session.get('das_hash', None)): groups = Group.Group().get_groups(userID=user.ID) if not groups: groups = [] payload = render_template('menu/usermenu.html', user=user, groups=groups) return "%s %s" % (payload, all_feeds())
def show_group(groupid): if not groupid: return redirect('/recent', 302) group = Group.Group(ID=int(groupid)) if not group.ID: return redirect('/recent', 302) amount, start = amountstart() recents = group.get_recents(amount=amount, start=start) feeds = {} for feedid, entryid in recents: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) return render_template("recent.html", feeds=feeds.values(), amount=amount, menu=usermenu(), title='Grouped feeds: %s' % group.description, nextstart=int(start) + int(amount), path='/group/%s' % groupid, prevstart=max(int(start) - int(amount), -1)), 200, { 'Cache-Control': 's-maxage=30' }
def remove_group(): groupid = int(request.form.get('groupid')) if Group.Group(groupid).delete(): return '', 204 return 'error', 503
def test_feeds(self): g = group.Group(2) self.assertGreater(len(g.feeds), 1)
def test_init_with_id(self): g = group.Group(1) self.assertEqual(g.description, 'Comics')
def test_init(self): g = group.Group() self.assertEqual(g.ID, None)