示例#1
0
def pages():
    """Displays Character sheets"""
    form = SheetForm()
    if form.validate_on_submit():
        sheet = Sheet(body=form.body.data,
                      author=current_user,
                      character_name=form.character_name.data,
                      level=form.level.data,
                      race=form.race.data,
                      job=form.job.data)
        db.session.add(sheet)
        db.session.commit()
        flash('Your Character lives!')
        return redirect(url_for('main.pages'))
    sheets = current_user.followed_sheets().all()
    return render_template("sheets.html",
                           title='Sheets',
                           sheets=sheets,
                           form=form)
    page = request.args.get('page', 1, type=int)
    sheets = current_user.followed_sheets().paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('sheets', page=sheets.next_num) \
        if sheets.has_next else None
    prev_url = url_for('sheets', page=sheets.prev_num) \
        if sheets.has_prev else None
    return render_template('sheets.html',
                           title='Sheets',
                           form=form,
                           sheets=sheets.items,
                           next_url=next_url,
                           prev_url=prev_url)
示例#2
0
文件: views.py 项目: kleshklya/lists
def addsheet(request):
    logger.info('nya')
    if request.method == 'POST':
        logger.info("post yes")
        name = request.POST['name'] if 'name' in request.POST else None
        logger.info(name)
        date = request.POST['date'] if 'date' in request.POST else datetime.utcnow()
        date = datetime.strptime(date, '%m/%d/%Y %I:%M %p')
        logger.info(date)
        sheet = Sheet()
        sheet.name = name
        sheet.date = date
        sheet.save()
        logger.info('Sheet created: id is %s and name is "%s".' % (sheet.id, sheet.name))
        sheet_created = True
        return render_and_respond(request, 'app/addsheet.html', {'sheet_created': sheet_created})
    return render_and_respond(request, 'app/addsheet.html', {})
示例#3
0
    def test_create_simple_sheet(self):
        test_file = self.add_file("file.pdf")
        db.session.commit()
        data = {"author_name": u"Bach", "arranger_name": u"Bream", "files": [test_file], "instrument_name": u"guitar"}
        with self.assertRaises(TypeError):
            Sheet.create_sheet(**data)

        data = {"author_name": u"Bach", "arranger_name": u"Bream", "files": [test_file], "name": "BWV 1001"}
        with self.assertRaises(TypeError):
            Sheet.create_sheet(**data)

        data = {
            "author_name": u"Bach",
            "arranger_name": u"Bream",
            "files": [test_file],
            "instrument_name": u"guitar",
            "name": "BWV 1001",
        }
        Sheet.create_sheet(**data)
        self.assertEqual(len(Sheet.query.all()), 1)
        test_sheet = Sheet.query.get(1)
        self.assertEqual(test_sheet.author.name, "Bach")
        self.assertEqual(test_sheet.arranger.name, "Bream")
        self.assertIn(test_file, test_sheet.files)
        guitar = Instrument.query.filter_by(name="guitar").first()
        self.assertIn(guitar, test_sheet.instruments)
        names = [i.name for i in test_sheet.names]
        self.assertIn("BWV 1001", names)
示例#4
0
    def test_create_sheet(self):
        #        author_name, arranger_name - string parameters,
        #        files - list of file objects,
        #        instrument_names - list of names of instruments,
        #        names - list of sheet names,
        #        parent - sheet object
        test_file = self.add_file("file.pdf")
        db.session.commit()
        data = {
            "author_name": u"Bach",
            "arranger_name": u"Bream",
            "files": [test_file],
            "instrument_names": [u"guitar"],
            "names": ["BWV 1001"],
        }
        Sheet.create_sheet(**data)
        self.assertEqual(len(Sheet.query.all()), 1)
        test_sheet = Sheet.query.get(1)
        self.assertEqual(test_sheet.author.name, "Bach")
        self.assertEqual(test_sheet.arranger.name, "Bream")
        self.assertIn(test_file, test_sheet.files)
        guitar = Instrument.query.filter_by(name="guitar").first()
        self.assertIn(guitar, test_sheet.instruments)
        names = [i.name for i in test_sheet.names]
        self.assertIn("BWV 1001", names)

        test_file2 = self.add_file("file.pdf")
        db.session.commit()
        data2 = {
            "author_name": u"Bach",
            "arranger_name": u"Bream",
            "files": [test_file2],
            "instrument_names": [u"guitar"],
            "names": ["Allegro"],
            "parent": test_sheet,
        }
        test_sheet2 = Sheet.create_sheet(**data2)
        self.assertEqual(test_sheet2.parent, test_sheet)
        self.assertIn(test_sheet2, test_sheet.childrens)
示例#5
0
    def test_follow_sheets(self):
        # create four users
        u1 = User(username='******', email='*****@*****.**', id=1)
        u2 = User(username='******', email='*****@*****.**', id=2)
        u3 = User(username='******', email='*****@*****.**', id=3)
        u4 = User(username='******', email='*****@*****.**', id=4)
        db.session.add_all([u1, u2, u3, u4])

        # create four sheets
        now = datetime.utcnow()
        p1 = Sheet(character_name="Jon", level=7, race="Orc", body="made by john", author=u1,
                   timestamp=now + timedelta(seconds=1), user_id=1)
        p2 = Sheet(character_name="Sue", level=8, race="Half-Orc", body="made by susan", author=u2,
                   timestamp=now + timedelta(seconds=4), user_id=2)
        p3 = Sheet(character_name="Mar", level=6, race="Minotaur", body="made by mary", author=u3,
                   timestamp=now + timedelta(seconds=3), user_id=3)
        p4 = Sheet(character_name="Dave", level=5, race="Giant", body="made by david", author=u4,
                   timestamp=now + timedelta(seconds=2), user_id=4)
        db.session.add_all([p1, p2, p3, p4])
        db.session.commit()

        # setup the followers
        u1.follow(u2)  # john follows susan
        u1.follow(u4)  # john follows david
        u2.follow(u3)  # susan follows mary
        u3.follow(u4)  # mary follows david
        db.session.commit()

        # check the followed sheets of each user
        f1 = u1.followed_sheets().all()
        f2 = u2.followed_sheets().all()
        f3 = u3.followed_sheets().all()
        f4 = u4.followed_sheets().all()
        self.assertEqual(f1, [p2, p4, p1])
        self.assertEqual(f2, [p2, p3])
        self.assertEqual(f3, [p3, p4])
        self.assertEqual(f4, [p4])
示例#6
0
 def test_create_without_arranger(self):
     test_file = self.add_file("file.pdf")
     db.session.commit()
     data = {"author_name": u"Bach", "files": [test_file], "instrument_name": u"guitar", "name": "BWV 1001"}
     Sheet.create_sheet(**data)
     self.assertEqual(len(Sheet.query.all()), 1)
示例#7
0
def edit_policy_target(article_id):
    article_db = Article.query.get_or_404(article_id)
    result_list = ListResultForm()
    result_subform = ResultForm(prefix='list-_-')
    if result_list.validate_on_submit():
        results_form = result_list.list.data
        results_db = article_db.result
        # Adding new policy-target result
        # Loading the list of policy-targets in the form
        attributes_forms = [[result['policy'], result['policyUnit'],
                             result['target'], result['targetUnit'],
                             result['method'], result['country'],
                             result['year'], result['estimate'],
                             result['standardError'], result['sampleSize']] for result in results_form]
        # Loading the list of policy-targets in the DATABASE for this article
        attributes_db = [[resultdb.policy, resultdb.policyUnit,
                          resultdb.target, resultdb.targetUnit,
                          resultdb.method, resultdb.country,
                          resultdb.yearPolicy, resultdb.estimate,
                          resultdb.standardError, resultdb.sampleSize] for resultdb in results_db]

        for attribute in attributes_forms:
            if attribute not in attributes_db:
                # Checking if the sheet for this policy-target exists
                sheet_name = attribute[0].lower(
                ) + ' on ' + attribute[2].lower()
                sheet = Sheet.query.filter_by(title=sheet_name).first()
                if not sheet:
                    # If it doesn't exist I create it
                    new_sheet = Sheet(
                        creation=date.today(),
                        update=date.today(),
                        title=sheet_name.lower(),
                        policy=attribute[0].lower(),
                        target=attribute[2].lower(),
                        submit=0,
                        publish=0
                    )
                    db.session.add(new_sheet)
                    new_sheet.contributor.append(current_user)
                    db.session.commit()
                    sheet_id = Sheet.query.filter_by(
                        title=sheet_name).first().id
                else:
                    sheet_id = sheet.id

                # Now that I have the sheet id I can create the result entry in db
                new_result = Result(
                    creation=date.today(),
                    update=date.today(),
                    sheet_id=sheet_id,
                    article_id=article_db.id,
                    # Content specific entries
                    policy=attribute[0].lower(),  # policy name
                    policyUnit=attribute[1].upper(),  # policy name
                    target=attribute[2].lower(),  # target name
                    targetUnit=attribute[3].upper(),  # target unit
                    method=attribute[4].upper(),  # identification method
                    country=attribute[5].title(),  # country of study
                    yearPolicy=attribute[6],  # year of programm implementation
                    estimate=float(attribute[7]),  # Point estimate
                    standardError=float(attribute[8]),  # Standard error
                    sampleSize=attribute[9]  # Sample size
                )
                db.session.add(new_result)
        # Deleting removed Result
        for attribute in attributes_db:
            if attribute not in attributes_forms:
                delete_result = Result.query.filter_by(policy=attribute[0].lower(),
                                                       policyUnit=attribute[1].upper(
                ),
                    target=attribute[2].lower(
                ),
                    targetUnit=attribute[3].upper(
                ),
                    method=attribute[4].upper(
                ),
                    country=attribute[5].title(
                ),
                    yearPolicy=attribute[6],
                    estimate=attribute[7],
                    standardError=attribute[8],
                    sampleSize=attribute[9]).first()
                db.session.delete(delete_result)
        # Appending contributor
        article_db.contributor.append(current_user)
        db.session.commit()
        flash('You have succesfully added results to the article. Thank you!', 'success')
        # return redirect(url_for('contribution.contribute'))
    # Charge data to form if already existing
    elif request.method == 'GET':
        results = [{'policy': resultdb.policy.title(),
                    'policyUnit': resultdb.policyUnit.upper(),
                    'target': resultdb.target.title(),
                    'targetUnit': resultdb.targetUnit.upper(),
                    'method': resultdb.method.upper(),
                    'country': resultdb.country.title(),
                    'year': resultdb.yearPolicy,
                    'estimate': resultdb.estimate,
                    'standardError': resultdb.standardError,
                    'sampleSize': resultdb.sampleSize}
                   for resultdb in article_db.result]
        for result in results:
            result_list.list.append_entry(result)

    return render_template('/update_result.html',
                           form=result_list,
                           _template=result_subform,
                           article_id=article_id
                           )
surname="David",email="*****@*****.**",
password =  "******")


db.session.add(contributor2)

db.session.commit()

# Contributor.query.first().password
contributor1 = Contributor.query.first()


sheet1 = Sheet(creation = date.today(),
update = date.today(),title = "First Sheet",
abstract = "This is the very first sheet",
policy ="Carbon Tax",


sheet1.contributor.append(contributor1)
db.session.commit()

Sheet.query.first().contributor

author1=Author(creation = date.today(), # Date of entry creation in database
    update = date.today(), # Date of entry update in database
    # Content specific entries
    surname = "BigFlo", 
    name = "Esther",
    email = "*****@*****.**")

db.session.add(author1)