Esempio n. 1
0
    def test_put_updates(self):
        source = FakeSource.new()
        source.put()
        updates = source.updates = {'status': 'disabled'}

        Source.put_updates(source)
        self.assertEqual('disabled', source.key.get().status)
Esempio n. 2
0
    def test_form_template(self):
        template_params =  {
                'name' : 'page12.html',
                'content' : 'test'
            }

        template = Template(**template_params)
        template.save()

        source_params = {
                'source' : 'test-source',
                'slug' : 'test-source'
                }

        source = Source(**source_params)
        source.save()

        form_params = {
            'name' : 'test',
            'slug' : 'test',
            'template' : template,
            'form_type' : source,
            'height' : '100',
            'width' : '200'
            }

        form = ContactForm(**form_params)

        embed_code = """<iframe style="border: none; 
        overflow: hidden;" src="page12.html" frameborder="0" 
        scrolling="no" width="200" height="100"></iframe>"""

        assert form.embed_code == embed_code, True
Esempio n. 3
0
def record_source_interaction(source: Source) -> None:
    """
    Updates the source's interaction count, pending status, and timestamp.
    """
    source.interaction_count += 1
    source.pending = False
    source.last_updated = datetime.datetime.utcnow()
    db.session.flush()
Esempio n. 4
0
  def test_get_post(self):
    post = {'verb': 'post', 'object': {'objectType': 'note', 'content': 'asdf'}}
    source = Source(id='x')
    self.mox.StubOutWithMock(source, 'get_activities')
    source.get_activities(activity_id='123', user_id='x').AndReturn([post])

    self.mox.ReplayAll()
    self.assert_equals(post, source.get_post('123'))
Esempio n. 5
0
def create_source_and_submissions(
        source_index,
        source_count,
        num_submissions=2,
        num_replies=2,
        journalist_who_replied=None  # noqa: W605, E501
):
    # Store source in database
    codename = current_app.crypto_util.genrandomid()
    filesystem_id = current_app.crypto_util.hash_codename(codename)
    journalist_designation = current_app.crypto_util.display_id()
    source = Source(filesystem_id, journalist_designation)
    source.pending = False
    db.session.add(source)
    db.session.commit()

    # Generate submissions directory and generate source key
    os.mkdir(current_app.storage.path(source.filesystem_id))
    current_app.crypto_util.genkeypair(source.filesystem_id, codename)

    # Generate some test submissions
    for _ in range(num_submissions):
        source.interaction_count += 1
        submission_text = next(submissions)
        fpath = current_app.storage.save_message_submission(
            source.filesystem_id, source.interaction_count,
            source.journalist_filename, submission_text)
        source.last_updated = datetime.datetime.utcnow()
        submission = Submission(source, fpath)
        db.session.add(submission)

    # Generate some test replies
    for _ in range(num_replies):
        source.interaction_count += 1
        fname = "{}-{}-reply.gpg".format(source.interaction_count,
                                         source.journalist_filename)
        current_app.crypto_util.encrypt(
            next(replies), [
                current_app.crypto_util.get_fingerprint(source.filesystem_id),
                config.JOURNALIST_KEY
            ], current_app.storage.path(source.filesystem_id, fname))

        if not journalist_who_replied:
            journalist = Journalist.query.first()
        else:
            journalist = journalist_who_replied
        reply = Reply(journalist, source, fname)
        db.session.add(reply)
        db.session.flush()
        seen_reply = SeenReply(reply_id=reply.id, journalist_id=journalist.id)
        db.session.add(seen_reply)

    db.session.commit()

    print("Test source {}/{} (codename: '{}', journalist designation '{}') "
          "added with {} submissions and {} replies".format(
              source_index, source_count, codename, journalist_designation,
              num_submissions, num_replies))
Esempio n. 6
0
  def test_is_beta_user(self):
    source = Source(id='x')
    self.assertFalse(source.is_beta_user())

    self.mox.stubs.Set(util, 'BETA_USER_PATHS', set())
    self.assertFalse(source.is_beta_user())

    self.mox.stubs.Set(util, 'BETA_USER_PATHS', set([source.bridgy_path()]))
    self.assertTrue(source.is_beta_user())
Esempio n. 7
0
  def test_get_event(self):
    event = {'verb': 'post', 'object': {
      'objectType': 'event', 'content': 'asdf'}}
    source = Source(id='x')
    source.gr_source = self.mox.CreateMock(gr_source.Source)
    self.mox.StubOutWithMock(source.gr_source, 'get_event')
    source.gr_source.get_event('123').AndReturn(event)

    self.mox.ReplayAll()
    self.assert_equals(event, source.get_event('123'))
Esempio n. 8
0
    def post(self):
        name = self.request.get('name')
        url = self.request.get('url')

        s = Source(
            name=name,
            url=url,
            id=name
        )
        s.put()
        self.redirect('/addsource')
Esempio n. 9
0
  def test_put_updates(self):
    source = FakeSource.new(None)
    source.put()
    updates = source.updates = {'status': 'disabled'}

    try:
      # check that source.updates is preserved through pre-put hook since some
      # Source subclasses (e.g. FacebookPage) use it.
      FakeSource._pre_put_hook = lambda fake: self.assertEquals(updates, fake.updates)
      Source.put_updates(source)
      self.assertEquals('disabled', source.key.get().status)
    finally:
      del FakeSource._pre_put_hook
Esempio n. 10
0
    def enterRole(self, ctx):
        title = self.__strToken(ctx.QUOTE())

        inputstream = ctx.start.getInputStream()
        start = ctx.getChild(3).start.start
        stop = ctx.getChild(3).stop.stop
        text = inputstream.getText(start, stop)
        
        src = Source(title=title, text=text, 
                    owner=self.user.first_name + ' ' + self.user.last_name,
                    ) 
        src.save()
        self.context.append(src)
Esempio n. 11
0
  def test_put_updates(self):
    source = FakeSource.new(None)
    source.put()
    updates = source.updates = {'status': 'disabled'}

    try:
      # check that source.updates is preserved through pre-put hook since some
      # Source subclasses (e.g. FacebookPage) use it.
      FakeSource._pre_put_hook = lambda fake: self.assertEquals(updates, fake.updates)
      Source.put_updates(source)
      self.assertEquals('disabled', source.key.get().status)
    finally:
      del FakeSource._pre_put_hook
Esempio n. 12
0
    def new_source(self):
        fid_len = random.randint(4, 32)
        designation_len = random.randint(4, 32)
        source = Source(
            random_chars(fid_len, nullable=False,
                         chars=string.ascii_lowercase),
            random_chars(designation_len, nullable=False))
        source.flagged = bool_or_none()
        source.last_updated = random_datetime(nullable=False)
        source.pending = False

        db.session.add(source)
        db.session.flush()
        self.sources.append(source.id)
Esempio n. 13
0
    def enterRole(self, ctx):
        title = self.__strToken(ctx.QUOTE())

        inputstream = ctx.start.getInputStream()
        start = ctx.getChild(3).start.start
        stop = ctx.getChild(3).stop.stop
        text = inputstream.getText(start, stop)

        src = Source(
            title=title,
            text=text,
            owner=self.user.first_name + ' ' + self.user.last_name,
        )
        src.save()
        self.context.append(src)
Esempio n. 14
0
 def register( cls, name, email, uid=None ):
     """
     Register a new account.
     """
     if uid==None:
         _uid = mk_id()
     else:
         _uid = uid
     log.warn( "New registration: Name=%s, email=%s, uid=%s" % ( name, email, uid ) )
     newAccount = Source( uid=_uid,
                          name=name,
                          email=email )
     
     newAccount.put()
     return newAccount.uid
Esempio n. 15
0
 def getSource(cls, uid):
     assert isinstance( uid, str )
     s = Source.all()
     s.filter( "uid =", uid )
     results = [a for a in s.fetch( limit=1 ) ]
     assert len(results) > 0, "Could not find source record."
     return results[0]
Esempio n. 16
0
    def create():
        filesystem_id = current_app.crypto_util.hash_codename(
            session['codename'])

        source = Source(filesystem_id, current_app.crypto_util.display_id())
        db.session.add(source)
        try:
            db.session.commit()
        except IntegrityError as e:
            db.session.rollback()
            current_app.logger.error(
                "Attempt to create a source with duplicate codename: %s" %
                (e, ))

            # Issue 2386: don't log in on duplicates
            del session['codename']

            # Issue 4361: Delete 'logged_in' if it's in the session
            try:
                del session['logged_in']
            except KeyError:
                pass

            abort(500)
        else:
            os.mkdir(current_app.storage.path(filesystem_id))

        session['logged_in'] = True
        return redirect(url_for('.lookup'))
Esempio n. 17
0
    def test_source_insert_3(self):
        s = Source(id_num='102', id_name='test-src3', language='English', \
            description='Guaranteed best source for accuracy and truthiness', smallLogoURL='http://assets3.onionstatic.com/onionstatic/onion/static/images/onion_fb_placeholder.png', mediumLogoURL='the_onion.gif', \
            largeLogoURL='the_onion2.img', category='The Truth', external_link='http://www.theonion.com/',name='The Onion',\
            region='United States', country='United States')
        db.session.add(s)
        db.session.commit()

        r = db.session.query(Source).filter(Source.id_num == '102').first()
        self.assertEqual(r.id_num, '102')
        self.assertEqual(r.id_name, 'test-src3')
        self.assertEqual(r.language, 'English')
        self.assertEqual(r.description,
                         'Guaranteed best source for accuracy and truthiness')
        self.assertEqual(
            r.smallLogoURL,
            'http://assets3.onionstatic.com/onionstatic/onion/static/images/onion_fb_placeholder.png'
        )
        self.assertEqual(r.mediumLogoURL, 'the_onion.gif')
        self.assertEqual(r.largeLogoURL, 'the_onion2.img')
        self.assertEqual(r.category, 'The Truth')
        self.assertEqual(r.external_link, 'http://www.theonion.com/')
        self.assertEqual(r.name, 'The Onion')
        self.assertEqual(r.region, 'United States')
        self.assertEqual(r.country, 'United States')

        db.session.query(Source).filter(Source.id_num == '102').delete()
        db.session.commit()
Esempio n. 18
0
    def test_source_insert_2(self):
        s = Source(id_num='101', id_name='test-src2', language='latin', \
            description='official news source of the roman empire', smallLogoURL='small_logo.jpg', mediumLogoURL='medium_logo.jpg', \
            largeLogoURL='large_logo.jpg', category='history', external_link='barbarians-are-invading.com',name='Roma News',\
            region='Mediterranean Sea', country='Italia')
        db.session.add(s)
        db.session.commit()

        r = db.session.query(Source).filter(
            Source.external_link == 'barbarians-are-invading.com').first()
        self.assertEqual(r.id_num, '101')
        self.assertEqual(r.id_name, 'test-src2')
        self.assertEqual(r.language, 'latin')
        self.assertEqual(r.description,
                         'official news source of the roman empire')
        self.assertEqual(r.smallLogoURL, 'small_logo.jpg')
        self.assertEqual(r.mediumLogoURL, 'medium_logo.jpg')
        self.assertEqual(r.largeLogoURL, 'large_logo.jpg')
        self.assertEqual(r.category, 'history')
        self.assertEqual(r.external_link, 'barbarians-are-invading.com')
        self.assertEqual(r.name, 'Roma News')
        self.assertEqual(r.region, 'Mediterranean Sea')
        self.assertEqual(r.country, 'Italia')

        db.session.query(Source).filter(
            Source.external_link == 'barbarians-are-invading.com').delete()
        db.session.commit()
Esempio n. 19
0
    def ready(self):
        """
            Находит все источники брокера и
            в соответствии с полученным списком обновляет таблицу бд
        """
        from models import Source
        # Получаем данные по всем источникам в модуле
        module_sources = get_data_sources()
        if not module_sources:
            raise ModuleSourcesExceptions('Sources in module were not found')
        module_sources_names = set(module_sources.keys())
        try:
            # Выбираем источники, которые уже есть в бд
            db_sources_names = set(Source.objects.all().values_list('source',
                                                                    flat=True))

            # Удаляем источники, которых нет в модуле
            Source.objects.filter(source__in=(db_sources_names -
                                              module_sources_names)).delete()

            # Добавляем источники, которых нет в бд
            Source.objects.bulk_create([
                Source(source=source_name,
                       type_source=module_sources[source_name]['type'])
                for source_name in (module_sources_names - db_sources_names)
            ])
        except ProgrammingError:
            warnings.warn('Only if deployed')
 def setup(self):
     """
     Set up method that will run before every Test
     """
     self.new_source = Source("nana", "igihe",
                              "Test to see if sources is being known",
                              "TestUrl", "sport")
Esempio n. 21
0
    def test_source_insert_1(self):
        s = Source(id_num='100', id_name='test-src1', language='elvish', \
            description='official news source of middle-earth', smallLogoURL='small.png', mediumLogoURL='medium.png', \
            largeLogoURL='large.png', category='general', external_link='some-link.com',name='Middle-Earth News',\
            region='fantasy', country='Mordor')
        db.session.add(s)
        db.session.commit()

        r = db.session.query(Source).filter(
            Source.name == 'Middle-Earth News').first()
        self.assertEqual(r.id_num, '100')
        self.assertEqual(r.id_name, 'test-src1')
        self.assertEqual(r.language, 'elvish')
        self.assertEqual(r.description, 'official news source of middle-earth')
        self.assertEqual(r.smallLogoURL, 'small.png')
        self.assertEqual(r.mediumLogoURL, 'medium.png')
        self.assertEqual(r.largeLogoURL, 'large.png')
        self.assertEqual(r.category, 'general')
        self.assertEqual(r.external_link, 'some-link.com')
        self.assertEqual(r.name, 'Middle-Earth News')
        self.assertEqual(r.region, 'fantasy')
        self.assertEqual(r.country, 'Mordor')

        db.session.query(Source).filter(
            Source.name == 'Middle-Earth News').delete()
        db.session.commit()
Esempio n. 22
0
def clone_cohort(request, cohort_id):
    if debug: print >> sys.stderr,'Called '+sys._getframe().f_code.co_name
    redirect_url = 'cohort_details'
    parent_cohort = Cohort.objects.get(id=cohort_id)
    new_name = 'Copy of %s' % parent_cohort.name
    cohort = Cohort.objects.create(name=new_name)
    cohort.save()

    # If there are sample ids
    samples = Samples.objects.filter(cohort=parent_cohort).values_list('sample_id', 'study_id')
    sample_list = []
    for sample in samples:
        sample_list.append(Samples(cohort=cohort, sample_id=sample[0], study_id=sample[1]))
    Samples.objects.bulk_create(sample_list)

    # TODO Some cohorts won't have them at the moment. That isn't a big deal in this function
    # If there are patient ids
    patients = Patients.objects.filter(cohort=parent_cohort).values_list('patient_id', flat=True)
    patient_list = []
    for patient_code in patients:
        patient_list.append(Patients(cohort=cohort, patient_id=patient_code))
    Patients.objects.bulk_create(patient_list)

    # Clone the filters
    filters = Filters.objects.filter(resulting_cohort=parent_cohort).values_list('name', 'value')
    # ...but only if there are any (there may not be)
    if filters.__len__() > 0:
        filters_list = []
        for filter_pair in filters:
            filters_list.append(Filters(name=filter_pair[0], value=filter_pair[1], resulting_cohort=cohort))
        Filters.objects.bulk_create(filters_list)

    # Set source
    source = Source(parent=parent_cohort, cohort=cohort, type=Source.CLONE)
    source.save()

    # Set permissions
    perm = Cohort_Perms(cohort=cohort, user=request.user, perm=Cohort_Perms.OWNER)
    perm.save()

    # Store cohort to BigQuery
    project_id = settings.BQ_PROJECT_ID
    cohort_settings = settings.GET_BQ_COHORT_SETTINGS()
    bcs = BigQueryCohortSupport(project_id, cohort_settings.dataset_id, cohort_settings.table_id)
    bcs.add_cohort_with_sample_barcodes(cohort.id, samples)

    return redirect(reverse(redirect_url,args=[cohort.id]))
Esempio n. 23
0
    def setUp(self):
        '''
			Inbuilt function that runs before each test is executed
			'''
        self.new_source = Source(
            "abc-news", "ABC News",
            "Your trusted source for breaking news, analysis, exclusive interviews, headlines, and videos at ABCNews.com.",
            "https://abcnews.go.com", "general", "en", "us")
Esempio n. 24
0
  def test_is_blocked(self):
    source = Source(id='x')
    self.assertFalse(source.is_blocked({'author': {'numeric_id': '1'}}))

    source = Source(id='x', blocked_ids = ['1', '2'])
    self.assertTrue(source.is_blocked({'author': {'numeric_id': '1'}}))
    self.assertFalse(source.is_blocked({'object': {'actor': {'numeric_id': '3'}}}))
Esempio n. 25
0
def source_create(request, template_name='source/source_form.html'):
    if request.method == 'POST':
        form = SkipperForm(request.POST)
        if form.is_valid():
            source = Source()
            source.text = form.cleaned_data['text']
            source.title = form.cleaned_data['title']
            source.owner = request.user.first_name + ' ' + request.user.last_name
            source.save()

            # Now build it.
            build(user=request.user, sourceobj=source)

            cache.clear()
            return redirect('source_list')
        else:
            return render(request, template_name, {'form': form})
    else:
        default = '''
coordinator "Name" "Email" "Url"
contact "Email"
description {
}
    '''
        form = SkipperForm({'text': default, 'title': 'New Role'})
        return render(request, template_name, {'form': form})
Esempio n. 26
0
def upload():
    uf = request.files['input-b1']
    savepath, new_filename = uploadfile(uf, 'index')
    source = Source(path=savepath,filename=new_filename)
    user_id = session.get('user_id')
    user = User.query.filter(User.id == user_id).first()
    source.owner = user
    try:
        db.session.add(source)
        db.session.commit()
    except Exception as reason:
        s=str(reason)
        list = re.split(r'[()]+', s)
        flash(u'Upload Failed:(%s)(%%s)'%list[1]%list[3])
        return redirect(url_for('index'))
    else:
        flash(u'Upload Succ')
        return redirect(url_for('index'))
Esempio n. 27
0
def create_source_and_submissions(num_submissions=2, num_replies=2):
    # Store source in database
    codename = current_app.crypto_util.genrandomid()
    filesystem_id = current_app.crypto_util.hash_codename(codename)
    journalist_designation = current_app.crypto_util.display_id()
    source = Source(filesystem_id, journalist_designation)
    source.pending = False
    db.session.add(source)
    db.session.commit()

    # Generate submissions directory and generate source key
    os.mkdir(current_app.storage.path(source.filesystem_id))
    current_app.crypto_util.genkeypair(source.filesystem_id, codename)

    # Generate some test submissions
    for _ in range(num_submissions):
        source.interaction_count += 1
        fpath = current_app.storage.save_message_submission(
            source.filesystem_id, source.interaction_count,
            source.journalist_filename, 'test submission!')
        source.last_updated = datetime.datetime.utcnow()
        submission = Submission(source, fpath)
        db.session.add(submission)

    # Generate some test replies
    for _ in range(num_replies):
        source.interaction_count += 1
        fname = "{}-{}-reply.gpg".format(source.interaction_count,
                                         source.journalist_filename)
        current_app.crypto_util.encrypt(
            'this is a test reply!', [
                current_app.crypto_util.getkey(source.filesystem_id),
                config.JOURNALIST_KEY
            ], current_app.storage.path(source.filesystem_id, fname))

        journalist = Journalist.query.first()
        reply = Reply(journalist, source, fname)
        db.session.add(reply)

    db.session.commit()

    print("Test source (codename: '{}', journalist designation '{}') "
          "added with {} submissions and {} replies".format(
              codename, journalist_designation, num_submissions, num_replies))
Esempio n. 28
0
def getOrAddSource(name, session):
    srcs = session.query(Source).filter(Source.name == name).all()
    if (len(srcs) != 0):
        assert len(srcs) == 1
        return srcs[0]

    s = Source(name=name)
    session.add(s)
    session.commit()
    return s
Esempio n. 29
0
    def provide_list(cls, model):
        assert model == cls.model

        source_id = request.values.get('source')

        if source_id:
            source = Source.get(source_id)
            return model.references_to(source)
        else:
            return super().provide_list(model)
Esempio n. 30
0
def add_source() -> Tuple[Source, str]:
    """
    Adds a single source.
    """
    codename = PassphraseGenerator.get_default().generate_passphrase()
    filesystem_id = current_app.crypto_util.hash_codename(codename)
    journalist_designation = current_app.crypto_util.display_id()
    source = Source(filesystem_id, journalist_designation)
    source.pending = False
    db.session.add(source)
    db.session.commit()

    # Create source directory in store
    os.mkdir(current_app.storage.path(source.filesystem_id))

    # Generate source key
    current_app.crypto_util.genkeypair(source.filesystem_id, codename)

    return source, codename
Esempio n. 31
0
def get_source_from_rss(rss_url):
    """
    Given an rss url, returns a dictionary with rss_url, homepage_url and name. Note: If these are not defined in RSS,
    it is possible to raise an AttributeError.
    :param rss_url: the url for the rss to parse
    :return: A database Source object with information from the rss.
    """
    feed = feedparser.parse(rss_url)
    homepage_url = feed['feed']['link']
    name = feed['feed']['title']
    return Source(rss_url=rss_url, homepage_url=homepage_url, name=name)
Esempio n. 32
0
    def get(self):
#        self.addcourses()
        s = Source.query()

        if s.count(limit=1) == 0:
            self.redirect('/addsource')
        else:
            c = Course.query()

            context = {'courses': c, 'sources': s}
            self.render('classes.html', context)
 def setUp(self):
   """
   set up method that runs before test
   """
   self.new_source = Source("", "", "", "")
   
   def test_instance(self) :
   '''
   Test if the self.new_source object is an instance of the Source class
   '''
   self.assertTrue(isinstance(self.new_source,Source))
Esempio n. 34
0
def upload():
    uf = request.files['input-b1']
    file_dir=os.path.join(basedir,app.config['UPLOAD_FOLDER'])
    if not os.path.exists(file_dir):
        os.makedirs(file_dir)
    if uf and allowed_file(uf.filename):                       
        # size = len(uf.read())
        size = 1                               
        if size<51200000:          
            filename = secure_filename(uf.filename)
            # currentpath = os.path.abspath(os.path.dirname(__file__))
            # ossep = os.path.sep
            ext = filename.rsplit('.',1)[1]
            name = filename.rsplit('.',1)[0]
            unix_time = int(time.time())
            new_filename=name + '_' + str(unix_time)+'.'+ext
            # savepath = currentpath + ossep+'uploadfolder'+ ossep + filename
            savepath = os.path.join(file_dir,new_filename)
            # uf.save(savepath)
            uf.save(savepath)
            source = Source(path=savepath,filename=new_filename)
            user_id = session.get('user_id')
            user = User.query.filter(User.id == user_id).first()
            source.owner = user
            try:                                                
                db.session.add(source)
                db.session.commit()
            except Exception as reason:
                s=str(reason)                                    
                list = re.split(r'[()]+', s)                    
                flash(u'Upload Failed:(%s)(%%s)'%list[1]%list[3])
                return redirect(url_for('index'))
            else:
                flash(u'Upload Succ')
                return redirect(url_for('index'))
        else:
            flash(u'error:File size should less than 50M')
            return redirect(url_for('index'))
    else:
        flash(u'error:File type should be xls or xlsx')
        return redirect(url_for('index'))
Esempio n. 35
0
def callback():
    print(request.is_json)
    content = request.get_json()
    print content['src'], content['dst'], content['text']
    src = content['src']
    dst = content['dst']
    text = content['text']
    src_data = Source(src, dst, text)
    db.session.add(src_data)
    db.session.commit()

    return ' The JSON posted successfully '
Esempio n. 36
0
def sources_post():
    feed_url = request.form['feed']
    # create new Feed object from feed_url
    try:
        feed_obj = Feed(feed_url)
        source = Source.insert_from_feed(feed_url, feed_obj.get_source())
        # retrieve articles from the rss feed added by the form
        feed_articles = feed_obj.get_articles()
        Article.insert_from_feed(source.id, feed_articles)
    except:
        flash("Invalid Feed")
    return redirect('/sources')
Esempio n. 37
0
def source_create(request, template_name='source/source_form.html'):
    if request.method == 'POST' :
        form = SkipperForm(request.POST)
        if form.is_valid():
            source = Source()
            source.text = form.cleaned_data['text']
            source.title = form.cleaned_data['title']
            source.owner = request.user.first_name + ' ' + request.user.last_name
            source.save()
        
            # Now build it.
            build(user=request.user, sourceobj=source)

            cache.clear()
            return redirect('source_list')
        else:
            return render(request, template_name, {'form':form})            
    else:
        default = '''
coordinator "Name" "Email" "Url"
contact "Email"
description {
}
    ''' 
        form = SkipperForm( {'text': default, 'title': 'New Role'} )    
        return render(request, template_name, {'form':form})
Esempio n. 38
0
def _get_or_create_lamoda_source():
    source = Source.query.filter_by(name='lamoda.ru').first()

    if source is None:
        source = Source(name='lamoda.ru',
                        site_url='http://www.lamoda.ru/',
                        logo_url='http://www.lamoda.ru/social-logo.jpg',
                        is_active=True)

        db.session.add(source)
        db.session.commit()

    return source
Esempio n. 39
0
    def new_source(self) -> None:
        codename = current_app.crypto_util.genrandomid()
        filesystem_id = current_app.crypto_util.hash_codename(codename)
        journalist_designation = current_app.crypto_util.display_id()
        source = Source(filesystem_id, journalist_designation)
        db.session.add(source)
        db.session.flush()

        # Generate submissions directory and generate source key
        os.mkdir(current_app.storage.path(source.filesystem_id))
        current_app.crypto_util.genkeypair(source.filesystem_id, codename)

        self.sources.append(source.id)
Esempio n. 40
0
    def create() -> werkzeug.Response:
        if session.get('logged_in', False):
            flash(
                gettext(
                    "You are already logged in. Please verify your codename above as it "
                    +
                    "may differ from the one displayed on the previous page."),
                'notification')
        else:
            tab_id = request.form['tab_id']
            codename = session['codenames'][tab_id]
            session['codename'] = codename

            del session['codenames']

            filesystem_id = current_app.crypto_util.hash_codename(codename)
            try:
                source = Source(filesystem_id,
                                current_app.crypto_util.display_id())
            except ValueError as e:
                current_app.logger.error(e)
                flash(
                    gettext(
                        "There was a temporary problem creating your account. "
                        "Please try again."), 'error')
                return redirect(url_for('.index'))

            db.session.add(source)
            try:
                db.session.commit()
            except IntegrityError as e:
                db.session.rollback()
                current_app.logger.error(
                    "Attempt to create a source with duplicate codename: %s" %
                    (e, ))

                # Issue 2386: don't log in on duplicates
                del session['codename']

                # Issue 4361: Delete 'logged_in' if it's in the session
                try:
                    del session['logged_in']
                except KeyError:
                    pass

                abort(500)
            else:
                os.mkdir(current_app.storage.path(filesystem_id))

            session['logged_in'] = True
        return redirect(url_for('.lookup'))
Esempio n. 41
0
    def post(self):
        fields = ['source', 'number', 'dept', 'name', 'level', 'description']
        p = self.get_params_dict(fields)
        s = Source.query()
        c = Course.query()

        errors, p, kn = self.prepare_course(p, fields)
        context = {'errors': errors, 'sources': s, 'courses': c}

        if not errors:
            Course.get_or_insert(kn, **p)
            self.redirect('/')
        else:
            self.render('classes.html', context)
Esempio n. 42
0
  def test_is_beta_user(self):
    source = Source(id='x')
    self.assertFalse(source.is_beta_user())

    self.mox.stubs.Set(util, 'BETA_USER_PATHS', set())
    self.assertFalse(source.is_beta_user())

    self.mox.stubs.Set(util, 'BETA_USER_PATHS', set([source.bridgy_path()]))
    self.assertTrue(source.is_beta_user())
Esempio n. 43
0
def install():
    print("installing templates...")
    for template_data in templates:
        print("\t{}".format(template_data['name']))
        t = Template(template_data)
        t.save()

    print("installing source texts...")
    for source_filename in source_filenames:
        source_path = path.join(path.dirname(__file__), 'static/txt', source_filename)
        print("\treading {}".format(source_path))
        text = open(source_path).read()
        s = Source({'name':source_filename,
                    'text':text,
                    'uploader': cfg.SYSTEM_USER})
        print("\tprocessing {}".format(source_path))
        s.process()
        print("\tsaving {}".format(source_path))
        s.save()

    print('adding system user')
    u = User({'name':cfg.SYSTEM_USER,
              'password': ''})
    u.save()
Esempio n. 44
0
def save_idea(form):
    # process data in form.cleaned_data
    title = form.cleaned_data['title']
    title_nospaces = str(title.replace(' ', '_').lower())
    status = form.cleaned_data['status']
    short_desc = form.cleaned_data['short_desc']
    long_desc = form.cleaned_data['long_desc']
    date_formed = form.cleaned_data['date_formed']
    links_strings = form.cleaned_data['links'].split(',')
    tags_strings = form.cleaned_data['tags'].split(',')
    sources_strings = form.cleaned_data['sources'].split(',')
    images_strings = form.cleaned_data['images'].split(',')
    # save new idea with cleaned form data
    new_idea = Idea(title=title,status=status,short_desc=short_desc,
		    long_desc=long_desc,date_formed=date_formed)
    new_idea.save()
    # add links, tags, sources, and images
    for link in links_strings:
	new_link = Link(url=link)
	new_link.save()
	new_idea.links.add(new_link)
    for tag in tags_strings:
	new_tag = Tag(tag=tag)
	new_tag.save()
	new_idea.tags.add(new_tag)
    for source in sources_strings:
	new_source = Source(source=source)
	new_source.save()
	new_idea.sources.add(new_source)
    for image in images_strings:
	new_image = Image(url=image)
	new_image.save()
	new_idea.images.add(new_image)
    # save after adding data
    new_idea.save()
    return title
Esempio n. 45
0
    def post(self):
        source = self.load_source()
        redirect_url = '%s?%s' % (self.request.path,
                                  urllib.parse.urlencode({
                                      'source_key':
                                      source.key.urlsafe().decode(),
                                  }))

        add = self.request.get('add')
        delete = self.request.get('delete')
        if (add and delete) or (not add and not delete):
            self.abort(400,
                       'Either add or delete param (but not both) required')

        link = util.pretty_link(add or delete)

        if add:
            resolved = Source.resolve_profile_url(add)
            if resolved:
                if resolved in source.domain_urls:
                    self.messages.add('%s already exists.' % link)
                else:
                    source.domain_urls.append(resolved)
                    domain = util.domain_from_link(resolved)
                    source.domains.append(domain)
                    source.put()
                    self.messages.add('Added %s.' % link)
            else:
                self.messages.add(
                    "%s doesn't look like your web site. Try again?" % link)

        else:
            assert delete
            try:
                source.domain_urls.remove(delete)
            except ValueError:
                self.abort(
                    400, "%s not found in %s's current web sites" %
                    (delete, source.label()))
            domain = util.domain_from_link(delete)
            if domain not in set(
                    util.domain_from_link(url) for url in source.domain_urls):
                source.domains.remove(domain)
            source.put()
            self.messages.add('Removed %s.' % link)

        self.redirect(redirect_url)
Esempio n. 46
0
def add_source():
    if request.is_json:
        try:
            content = request.get_json()
            to_add = Source(content['short_hand'], content['rss'])
            try:
                db.session.add(to_add)
                db.session.commit()
                return flask.Response(status=201)
            except:
                return flask.Response(status=409)

        except:
            return flask.Response(status=401)

    else:
        return flask.Response(status=400)
Esempio n. 47
0
  def post(self):
    source = self.load_source()
    redirect_url = '%s?%s' % (self.request.path, urllib.urlencode({
      'source_key': source.key.urlsafe(),
    }))

    add = self.request.get('add')
    delete = self.request.get('delete')
    if (add and delete) or (not add and not delete):
      self.abort(400, 'Either add or delete param (but not both) required')

    link = util.pretty_link(add or delete)

    if add:
      resolved = Source.resolve_profile_url(add)
      if resolved:
        if resolved in source.domain_urls:
          self.messages.add('%s already exists.' % link)
        else:
          source.domain_urls.append(resolved)
          domain = util.domain_from_link(resolved)
          source.domains.append(domain)
          source.put()
          self.messages.add('Added %s.' % link)
      else:
        self.messages.add("%s doesn't look like your web site. Try again?" % link)

    else:
      assert delete
      try:
        source.domain_urls.remove(delete)
      except ValueError:
        self.abort(400, "%s not found in %s's current web sites" % (
                          delete, source.label()))
      domain = util.domain_from_link(delete)
      if domain not in set(util.domain_from_link(url) for url in source.domain_urls):
        source.domains.remove(domain)
      source.put()
      self.messages.add('Removed %s.' % link)

    self.redirect(redirect_url)
Esempio n. 48
0
def source_update(request, pk, template_name='source/source_form.html'):    

    next_page = request.GET.get('next', None)
    source = Source.objects.get(title=pk)
    if source == None :
        raise Http404("Source does not exist")

    if request.method=='POST':
        form = SkipperForm(request.POST)
        if form.is_valid():
        
            try: 
                with transaction.atomic() :
                    # There is no update, sources must be deleted and remade.
                    # on_delete=CASCADE is emulated, but it works when my objects don't suck. 
                    source.delete()

                    # Create a new one 
                    source = Source()
                    source.title = pk
                    source.text = form.cleaned_data['text']
                    source.owner = request.user.first_name + ' ' + request.user.last_name
                    source.save()
        
                    # Now build it.
                    build(user=request.user, sourceobj=source)
            except IntegrityError as e:
                print "Transaction error:", e
        
            cache.clear()
            if form.cleaned_data['next'] != "" : 
                return redirect('jobs', form.cleaned_data['next'])
            else:
                return redirect('source_list')
        else:
            return render(request, template_name, {'title': pk, 'form':form, 'next': next_page})

    else:
        form = SkipperForm({'text': source.text, 'title': source.title})
        return render(request, template_name, {'title': pk, 'form': form, 'next': next_page})
Esempio n. 49
0
def source_list():
    object_list = Source.find()
    return render_template('source_list.html', object_list=object_list)
Esempio n. 50
0
    try:
        source_method = SourceMethod.objects.get(method_name=s_method)
    except SourceMethod.DoesNotExist:
        print 'bad method:', s_method
        sys.exit(1)
except SourceMethod.DoesNotExist:
    print 'bad method id:', s_method
    sys.exit(1)

try:
    ref = Ref.objects.get(refID=refID)
except Ref.DoesNotExist:
    print refID,'does not exist in Ref table!'
    sys.exit(1)
print ref.refID, ref.title

try:
    source_type = SourceType.objects.get(source_type=ref.ref_type)
except SourceType.DoesNotExist:
    print ref.ref_type,'does not exist in SourceType table!'
    sys.exit(1)

source = Source(refID=refID, source_type=source_type, authors=ref.authors,
                title=ref.title, title_html=ref.title_html, journal=ref.journal,
                volume=ref.volume, page_start=ref.page_start,
                page_end=ref.page_end, year=ref.year, institution=ref.institution,
                note=ref.note, note_html=ref.note_html, doi=ref.doi,
                cited_as_html=ref.cited_as_html, url=ref.url,
                method=source_method)
source.save()
Esempio n. 51
0
def upload_opml_file(request):
    if request.method == 'POST':
        form = UploadOpmlFileForm(request.POST, request.FILES)
        if form.is_valid():
        	#opml_file = request.FILES['file'].read()
        	#tree = ET.parse(opml_file)
        	#root = tree.getroot()
        	#for outline in root.iter('outline'):
			#	source = Source(user=request.user, xml_url=outline.get('xmlUrl'))
			#	source.save()

			Source.objects.all().delete()
			Group.objects.all().delete()

			group = None
			for event, elem in ET.iterparse(request.FILES['file']):
				#import pdb; pdb.set_trace()
				if elem.tag == 'body':
					outlines = list(elem)

					for outline in outlines:
						if 'xmlUrl' not in outline.attrib:
							group = Group(user=request.user, name=outline.attrib['title']) 
							group.save()

							children = list(outline)
							for child in children:
								source = Source()
								source.text = child.attrib['text']
								source.title = child.attrib['title']
								source.feed_type = child.attrib['type'] 
								source.xml_url = child.attrib['xmlUrl']
								source.html_url = child.attrib['htmlUrl']
								source.save()

								user_source = UserSource(user=request.user, source=source, group=group)
								user_source.save()		
						elif 'xmlUrl' in outline.attrib:
							print outline.attrib
							source = Source()
							source.text = outline.attrib['text']
							source.title = outline.attrib['title']
							source.feed_type = outline.attrib['type'] 
							source.xml_url = outline.attrib['xmlUrl']
							source.html_url = outline.attrib['htmlUrl']
							source.save()	

							user_source = UserSource(user=request.user, source=source)
							user_source.save()		

			return HttpResponseRedirect( reverse('entries') )
    else:
        form = UploadOpmlFileForm()

    return render_to_response('feeds/upload_opml.html', {'form': form}, context_instance=RequestContext(request)) 
Esempio n. 52
0
def source_detail(obj_id):
    obj = Source.get(obj_id)
    if not obj:
        abort(404)
    return render_template('source_detail.html', obj=obj)
Esempio n. 53
0
 def get(self):
     s = Source.query()
     context = {'sources': s}
     self.render('sourceedit.html', context)