def download(request, data_file=None): user = request.user try: profile = Profile.objects.get(user=user) except Profile.DoesNotExist: profile = Profile(user=request.user) profile.save() if not profile.data_agreement: # request.notifications.add("Please agree to the following licence before downloading the data") return HttpResponseRedirect(reverse('data_agreement_form')) if data_file: download_file = get_object_or_404(models.DataDownload, pk=data_file) f = open(download_file.file_path) file_mimetype = mimetypes.guess_type(download_file.file_path) response = HttpResponse(FileWrapper(f), content_type=file_mimetype[0]) response['Content-Disposition'] = 'attachment; filename="%s"' % \ download_file.file_path.split('/')[-1] return response files = models.DataDownload.objects.filter(public=True) return render_to_response('downloads.html', {'files': files}, context_instance=RequestContext(request) )
def get_org_bookmarks(self, **options): if options['recipient_email'] and (options['ccg'] or options['practice']): dummy_user = User(email=options['recipient_email'], id='dummyid') dummy_user.profile = Profile(key='dummykey') bookmarks = [ OrgBookmark(user=dummy_user, pct_id=options['ccg'], practice_id=options['practice']) ] logger.info("Created a single test org bookmark") elif options['recipient_email'] or options['recipient_email_file']: recipients = [] if options['recipient_email_file']: with open(options['recipient_email_file'], 'r') as f: recipients = [x.strip() for x in f] else: recipients = [options['recipient_email']] bookmarks = OrgBookmark.objects.filter(approved=True, user__is_active=True, user__email__in=recipients) logger.info("Found %s matching org bookmarks" % bookmarks.count()) else: bookmarks = OrgBookmark.objects.filter(approved=True, user__is_active=True) if options['skip_email_file']: with open(options['skip_email_file'], 'r') as f: skip = [x.strip() for x in f] bookmarks = bookmarks.exclude(user__email__in=skip) logger.info("Found %s matching org bookmarks" % bookmarks.count()) return bookmarks
def make_dummy_bookmark(email_address): """Make a dummy bookmark with this email address for testing purposes""" dummy_user = User(email=email_address, id="dummyid") dummy_user.profile = Profile(key="dummykey") return OrgBookmark(user=dummy_user, pct_id=None, practice_id=None, pcn_id=None)
def data_agreement_form(request): try: profile = Profile.objects.get(user=request.user) if profile.data_agreement: return HttpResponseRedirect(reverse('download')) except Profile.DoesNotExist: p = Profile(user=request.user) p.save() if request.POST: form = DataAgreementForm(request.POST, instance=profile) if form.is_valid(): form.save() else: form = DataAgreementForm(instance=profile) return render_to_response('data_agreement_form.html', {'form': form}, context_instance=RequestContext(request) )
def preview_bookmark(request, practice=None, pct=None, url=None, name=None): user = User(email='*****@*****.**') user.profile = Profile() if pct or practice: context = bookmark_utils.InterestingMeasureFinder( practice=practice, pct=pct).context_for_org_email() bookmark = OrgBookmark(practice=practice, pct=pct, user=user) msg = bookmark_utils.make_org_email(bookmark, context) else: bookmark = SearchBookmark(url=url, user=user, name=name) msg = bookmark_utils.make_search_email(bookmark) html = msg.alternatives[0][0] images = msg.attachments return HttpResponse(_convert_images_to_data_uris(html, images))
def get_search_bookmarks(self, **options): if options['recipient_email'] and options['url']: dummy_user = User(email=options['recipient_email'], id='dummyid') dummy_user.profile = Profile(key='dummykey') bookmarks = [ SearchBookmark(user=dummy_user, url=options['url'], name=options['search_name']) ] elif not options['recipient_email']: bookmarks = SearchBookmark.objects.filter(approved=True, user__is_active=True) else: bookmarks = [] return bookmarks
def get_org_bookmarks(self, now_month, **options): """Get all OrgBookmarks for active users who have not been sent a message tagged with `now_month` """ query = ( Q(user__is_active=True) & ~Q(user__emailmessage__tags__contains=["measures", now_month]) & # Only include bookmarks for either a practice or pct or PCN: when all # are NULL this indicates an All England bookmark (Q(practice__isnull=False) | Q(pct__isnull=False) | Q(pcn__isnull=False))) if options["recipient_email"] and (options["ccg"] or options["practice"] or options["pcn"]): dummy_user = User(email=options["recipient_email"], id="dummyid") dummy_user.profile = Profile(key="dummykey") bookmarks = [ OrgBookmark( user=dummy_user, pct_id=options["ccg"], practice_id=options["practice"], pcn_id=options["pcn"], ) ] logger.info("Created a single test org bookmark") elif options["recipient_email"] or options["recipient_email_file"]: recipients = [] if options["recipient_email_file"]: with open(options["recipient_email_file"], "r") as f: recipients = [x.strip() for x in f] else: recipients = [options["recipient_email"]] query = query & Q(user__email__in=recipients) bookmarks = OrgBookmark.objects.filter(query) logger.info("Found %s matching org bookmarks" % bookmarks.count()) else: bookmarks = OrgBookmark.objects.filter(query) if options["skip_email_file"]: with open(options["skip_email_file"], "r") as f: skip = [x.strip() for x in f] bookmarks = bookmarks.exclude(user__email__in=skip) logger.info("Found %s matching org bookmarks" % bookmarks.count()) return bookmarks
def get_org_bookmarks(self, **options): if options['recipient_email'] and (options['ccg'] or options['practice']): dummy_user = User(email=options['recipient_email'], id='dummyid') dummy_user.profile = Profile(key='dummykey') bookmarks = [ OrgBookmark(user=dummy_user, pct_id=options['ccg'], practice_id=options['practice']) ] elif not options['recipient_email']: # Perhaps add a constraint here to ensure we don't send two # emails for one month? bookmarks = OrgBookmark.objects.filter(approved=True, user__is_active=True) else: bookmarks = [] return bookmarks
def get_org_bookmarks(self, now_month, **options): """Get approved OrgBookmarks for active users who have not been sent a message tagged with `now_month` """ query = ( Q(approved=True, user__is_active=True) & ~Q(user__emailmessage__tags__contains=['measures', now_month]) & # Only include bookmarks for either a practice or pct: when both # are NULL this indicates an All England bookmark (Q(practice__isnull=False) | Q(pct__isnull=False)) ) if options['recipient_email'] and ( options['ccg'] or options['practice']): dummy_user = User(email=options['recipient_email'], id='dummyid') dummy_user.profile = Profile(key='dummykey') bookmarks = [OrgBookmark( user=dummy_user, pct_id=options['ccg'], practice_id=options['practice'] )] logger.info("Created a single test org bookmark") elif options['recipient_email'] or options['recipient_email_file']: recipients = [] if options['recipient_email_file']: with open(options['recipient_email_file'], 'r') as f: recipients = [x.strip() for x in f] else: recipients = [options['recipient_email']] query = query & Q(user__email__in=recipients) bookmarks = OrgBookmark.objects.filter(query) logger.info("Found %s matching org bookmarks" % bookmarks.count()) else: bookmarks = OrgBookmark.objects.filter(query) if options['skip_email_file']: with open(options['skip_email_file'], 'r') as f: skip = [x.strip() for x in f] bookmarks = bookmarks.exclude(user__email__in=skip) logger.info("Found %s matching org bookmarks" % bookmarks.count()) return bookmarks
def get_search_bookmarks(self, now_month, **options): query = Q(approved=True, user__is_active=True) & ~Q( user__emailmessage__tags__contains=["analyse", now_month]) if options["recipient_email"] and options["url"]: dummy_user = User(email=options["recipient_email"], id="dummyid") dummy_user.profile = Profile(key="dummykey") bookmarks = [ SearchBookmark(user=dummy_user, url=options["url"], name=options["search_name"]) ] logger.info("Created a single test search bookmark") elif not options["recipient_email"]: bookmarks = SearchBookmark.objects.filter(query) logger.info("Found %s matching search bookmarks" % bookmarks.count()) else: query = query & Q(user__email=options["recipient_email"]) bookmarks = SearchBookmark.objects.filter(query) logger.info("Found %s matching search bookmarks" % bookmarks.count()) return bookmarks
def get_search_bookmarks(self, **options): if options['recipient_email'] and options['url']: dummy_user = User(email=options['recipient_email'], id='dummyid') dummy_user.profile = Profile(key='dummykey') bookmarks = [ SearchBookmark(user=dummy_user, url=options['url'], name=options['search_name']) ] logger.info("Created a single test search bookmark") elif not options['recipient_email']: bookmarks = SearchBookmark.objects.filter(approved=True, user__is_active=True) logger.info("Found %s matching search bookmarks" % bookmarks.count()) else: bookmarks = SearchBookmark.objects.filter( approved=True, user__is_active=True, user__email=options['recipient_email']) logger.info("Found %s matching search bookmarks" % bookmarks.count()) return bookmarks
def make_dummy_bookmark(email_address): '''Make a dummy bookmark with this email address for testing purposes''' dummy_user = User(email=email_address, id='dummyid') dummy_user.profile = Profile(key='dummykey') return OrgBookmark(user=dummy_user, pct_id=None, practice_id=None)