Trying to implement a points-system in my gamified web appPerforming a Stress Test on Web Application?iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari?Web app implementation questionWhat's the difference between a web site and a web application?How to check if an app is installed from a web-page on an iPhone?Deploying structured Flask app on EB - View function mapping errorHow to upload and display an image in Flaskblueprint template folder flask not workingPython POST function returns 200 But does not POST anything to POSTGRESWhy can't I get the alert to show?

Can an alphabet for a Turing machine contain subsets of other alphabets?

Could flaps be raised upward to serve as spoilers / lift dumpers?

What is the difference between 2/4 and 4/4 when it comes the accented beats?

Why do we need a voltage divider when we get the same voltage at the output as the input?

How can a class have multiple methods without breaking the single responsibility principle

Define tcolorbox in math mode

How does Rust's 128-bit integer `i128` work on a 64-bit system?

Selecting rows conflicting values in WHERE clause

δόλος = deceit in John 1:47

When did J.K. Rowling decide to make Ron and Hermione a couple?

Need help identifying how to open this bolt/screw

Export economy of Mars

Can't understand an ACT practice problem: Triangle appears to be isosceles, why isn't the answer 7.3~ here?

Who's behind community AMIs on Amazon EC2?

Is this popular optical illusion made of a grey-scale image with coloured lines?

Can it be useful for a player block with a hanging piece in a back rank mate situation?

Can I shorten this filter, that finds disk sizes over 100G?

Why interlaced CRT scanning wasn't done back and forth?

How is Sword Coast North governed?

UX writing: When to use "we"?

speaker impedence

Is there a general term for the items in a directory?

Backpacking with incontinence

Move label of an angle in Tikz



Trying to implement a points-system in my gamified web app


Performing a Stress Test on Web Application?iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari?Web app implementation questionWhat's the difference between a web site and a web application?How to check if an app is installed from a web-page on an iPhone?Deploying structured Flask app on EB - View function mapping errorHow to upload and display an image in Flaskblueprint template folder flask not workingPython POST function returns 200 But does not POST anything to POSTGRESWhy can't I get the alert to show?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















So I have an exercises page in my flask web app. Each exercise will have a "finish" button. On clicking the finish button, I want to give points to the user currently logged in. The points will then be added to user's progress bar for level-up. I just want a general idea of how to go about it.



This is my user model in database



class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
points = db.Column(db.Integer)


This is the html file where a button click is going to get points



<a data-toggle="collapse" class="w3-large" href="#tip4" onclick="getPoints()">...</a>


This is the get points function



<script>
function getPoints()
points += 20; #How do i access the database.points in this case?

</script>


@bp.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data, email=form.email.data)
user.set_password(form.password.data)
user.points = 0
db.session.add(user)
db.session.commit()
flash('Congratulations, you are now a registered user!')
return redirect(url_for('auth.login'))
return render_template('auth/register.html', title='Register', form=form)


@bp.route('/activity1')
@login_required
def activity1():
return render_template('activity1.html', title='Activity 1')


That's mostly what I have for python. Activity1.html is where I want to be able to get points.










share|improve this question


























  • How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

    – gittert
    Mar 27 at 12:03











  • @gittert I have added some code above. How do I increment the points in database.

    – Asif Hasan
    Mar 29 at 3:48











  • Can you show the python code?

    – gittert
    Mar 29 at 8:35











  • @gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

    – Asif Hasan
    Mar 30 at 0:08


















-1















So I have an exercises page in my flask web app. Each exercise will have a "finish" button. On clicking the finish button, I want to give points to the user currently logged in. The points will then be added to user's progress bar for level-up. I just want a general idea of how to go about it.



This is my user model in database



class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
points = db.Column(db.Integer)


This is the html file where a button click is going to get points



<a data-toggle="collapse" class="w3-large" href="#tip4" onclick="getPoints()">...</a>


This is the get points function



<script>
function getPoints()
points += 20; #How do i access the database.points in this case?

</script>


@bp.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data, email=form.email.data)
user.set_password(form.password.data)
user.points = 0
db.session.add(user)
db.session.commit()
flash('Congratulations, you are now a registered user!')
return redirect(url_for('auth.login'))
return render_template('auth/register.html', title='Register', form=form)


@bp.route('/activity1')
@login_required
def activity1():
return render_template('activity1.html', title='Activity 1')


That's mostly what I have for python. Activity1.html is where I want to be able to get points.










share|improve this question


























  • How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

    – gittert
    Mar 27 at 12:03











  • @gittert I have added some code above. How do I increment the points in database.

    – Asif Hasan
    Mar 29 at 3:48











  • Can you show the python code?

    – gittert
    Mar 29 at 8:35











  • @gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

    – Asif Hasan
    Mar 30 at 0:08














-1












-1








-1








So I have an exercises page in my flask web app. Each exercise will have a "finish" button. On clicking the finish button, I want to give points to the user currently logged in. The points will then be added to user's progress bar for level-up. I just want a general idea of how to go about it.



This is my user model in database



class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
points = db.Column(db.Integer)


This is the html file where a button click is going to get points



<a data-toggle="collapse" class="w3-large" href="#tip4" onclick="getPoints()">...</a>


This is the get points function



<script>
function getPoints()
points += 20; #How do i access the database.points in this case?

</script>


@bp.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data, email=form.email.data)
user.set_password(form.password.data)
user.points = 0
db.session.add(user)
db.session.commit()
flash('Congratulations, you are now a registered user!')
return redirect(url_for('auth.login'))
return render_template('auth/register.html', title='Register', form=form)


@bp.route('/activity1')
@login_required
def activity1():
return render_template('activity1.html', title='Activity 1')


That's mostly what I have for python. Activity1.html is where I want to be able to get points.










share|improve this question
















So I have an exercises page in my flask web app. Each exercise will have a "finish" button. On clicking the finish button, I want to give points to the user currently logged in. The points will then be added to user's progress bar for level-up. I just want a general idea of how to go about it.



This is my user model in database



class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
points = db.Column(db.Integer)


This is the html file where a button click is going to get points



<a data-toggle="collapse" class="w3-large" href="#tip4" onclick="getPoints()">...</a>


This is the get points function



<script>
function getPoints()
points += 20; #How do i access the database.points in this case?

</script>


@bp.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data, email=form.email.data)
user.set_password(form.password.data)
user.points = 0
db.session.add(user)
db.session.commit()
flash('Congratulations, you are now a registered user!')
return redirect(url_for('auth.login'))
return render_template('auth/register.html', title='Register', form=form)


@bp.route('/activity1')
@login_required
def activity1():
return render_template('activity1.html', title='Activity 1')


That's mostly what I have for python. Activity1.html is where I want to be able to get points.







flask web-applications






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 30 at 0:06







Asif Hasan

















asked Mar 27 at 0:13









Asif HasanAsif Hasan

11 bronze badge




11 bronze badge















  • How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

    – gittert
    Mar 27 at 12:03











  • @gittert I have added some code above. How do I increment the points in database.

    – Asif Hasan
    Mar 29 at 3:48











  • Can you show the python code?

    – gittert
    Mar 29 at 8:35











  • @gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

    – Asif Hasan
    Mar 30 at 0:08


















  • How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

    – gittert
    Mar 27 at 12:03











  • @gittert I have added some code above. How do I increment the points in database.

    – Asif Hasan
    Mar 29 at 3:48











  • Can you show the python code?

    – gittert
    Mar 29 at 8:35











  • @gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

    – Asif Hasan
    Mar 30 at 0:08

















How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

– gittert
Mar 27 at 12:03





How about calling a function on button press and add points to a counter and have it saved/updated in a database? Do you have any code already to show, any specific difficulties you need help with?

– gittert
Mar 27 at 12:03













@gittert I have added some code above. How do I increment the points in database.

– Asif Hasan
Mar 29 at 3:48





@gittert I have added some code above. How do I increment the points in database.

– Asif Hasan
Mar 29 at 3:48













Can you show the python code?

– gittert
Mar 29 at 8:35





Can you show the python code?

– gittert
Mar 29 at 8:35













@gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

– Asif Hasan
Mar 30 at 0:08






@gittert I have added some python code above. It mostly consists of the basic flask login/registration setup and the routing. Otherwise, I have not done much there.

– Asif Hasan
Mar 30 at 0:08













1 Answer
1






active

oldest

votes


















0














Have a look at this code. It is untested, but I'm sure you get the point (pun intended ;)). Don't forget to change the activity1 template and add points variable there. If you use this code, I would suggest removing the javascript getpoints script there.



@bp.route('/activity1', methods=['GET', 'POST'])
@login_required
def activity1():
user = User.query.filter_by(username = username).first()
points = user.points

if request.method == 'POST':
user = User.query.filter_by(username = username).first()
points = user.points + 20
user.points = points
db.session.commit()
flash('Congratulations, you have earned 20 points!')

return render_template('activity1.html',
title = 'Activity 1',
points = points,
)





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367969%2ftrying-to-implement-a-points-system-in-my-gamified-web-app%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Have a look at this code. It is untested, but I'm sure you get the point (pun intended ;)). Don't forget to change the activity1 template and add points variable there. If you use this code, I would suggest removing the javascript getpoints script there.



    @bp.route('/activity1', methods=['GET', 'POST'])
    @login_required
    def activity1():
    user = User.query.filter_by(username = username).first()
    points = user.points

    if request.method == 'POST':
    user = User.query.filter_by(username = username).first()
    points = user.points + 20
    user.points = points
    db.session.commit()
    flash('Congratulations, you have earned 20 points!')

    return render_template('activity1.html',
    title = 'Activity 1',
    points = points,
    )





    share|improve this answer





























      0














      Have a look at this code. It is untested, but I'm sure you get the point (pun intended ;)). Don't forget to change the activity1 template and add points variable there. If you use this code, I would suggest removing the javascript getpoints script there.



      @bp.route('/activity1', methods=['GET', 'POST'])
      @login_required
      def activity1():
      user = User.query.filter_by(username = username).first()
      points = user.points

      if request.method == 'POST':
      user = User.query.filter_by(username = username).first()
      points = user.points + 20
      user.points = points
      db.session.commit()
      flash('Congratulations, you have earned 20 points!')

      return render_template('activity1.html',
      title = 'Activity 1',
      points = points,
      )





      share|improve this answer



























        0












        0








        0







        Have a look at this code. It is untested, but I'm sure you get the point (pun intended ;)). Don't forget to change the activity1 template and add points variable there. If you use this code, I would suggest removing the javascript getpoints script there.



        @bp.route('/activity1', methods=['GET', 'POST'])
        @login_required
        def activity1():
        user = User.query.filter_by(username = username).first()
        points = user.points

        if request.method == 'POST':
        user = User.query.filter_by(username = username).first()
        points = user.points + 20
        user.points = points
        db.session.commit()
        flash('Congratulations, you have earned 20 points!')

        return render_template('activity1.html',
        title = 'Activity 1',
        points = points,
        )





        share|improve this answer













        Have a look at this code. It is untested, but I'm sure you get the point (pun intended ;)). Don't forget to change the activity1 template and add points variable there. If you use this code, I would suggest removing the javascript getpoints script there.



        @bp.route('/activity1', methods=['GET', 'POST'])
        @login_required
        def activity1():
        user = User.query.filter_by(username = username).first()
        points = user.points

        if request.method == 'POST':
        user = User.query.filter_by(username = username).first()
        points = user.points + 20
        user.points = points
        db.session.commit()
        flash('Congratulations, you have earned 20 points!')

        return render_template('activity1.html',
        title = 'Activity 1',
        points = points,
        )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 30 at 8:54









        gittertgittert

        5702 gold badges3 silver badges10 bronze badges




        5702 gold badges3 silver badges10 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367969%2ftrying-to-implement-a-points-system-in-my-gamified-web-app%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현