def create_community(community_name, community_description): """Create and return new community""" community = Community(community_name=community_name, community_description=community_description) db.session.add(community) db.session.commit() return community
def load_communities(): """ Load communities into our database """ a = Community(user_id=1, community_name="guitar") b = Community(user_id=2, community_name="nintendo") c = Community(user_id=3, community_name="gameofthrones") d = Community(user_id=4, community_name="starwars") e = Community(user_id=5, community_name="python") f = Community(user_id=1, community_name="cplusplus") g = Community(user_id=1, community_name="marvel") h = Community(user_id=1, community_name="sanfrancisco") db.session.add_all([a, b, c, d, e, f, g, h]) db.session.commit() print("Communities 😚")
def question(): """发帖页面:说出你的想法""" if request.method == 'GET': return render_template('question.html') else: title = request.form.get('title') context = request.form.get('context') community = Community(title=title, context=context) user_name = session.get('user_name') user = User.query.filter(User.username == user_name).first() community.author = user db.session.add(community) db.session.commit() return redirect(url_for('index'))
def new_community(): form = CommunityForm() if form.validate_on_submit(): name = (form.community_name.data).lower() name = name.replace(" ", "") # Check if Commmunity name exists. Redirect if it does. Otherwise, process. if Community.query.filter_by(community_name=name).first(): flash('Community name taken. Please try again.', 'danger') redirect('/community/new') else: community = Community(user_id=current_user.id, community_name=name) db.session.add(community) db.session.commit() flash('Your community has been created!', 'success') return redirect(url_for('community_list')) return render_template('create_community.html', form=form)
] # input some meanings and forms into the languages for eachlanguage in languageList: eachlanguage.formMeaningDict = {} language1.add_meaning("Lizard", ([("wiri-wiri", 75, 0), ("mirdi", 10, 0)])) language2.add_meaning("Lizard", ([("wiri-wiri", 15, 0)])) language3.add_meaning("Lizard", ([("wiri-wiri", 50, 0), ("mirdi", 10, 0)])) language4.add_meaning("Lizard", ([("julirri", 80, 0), ("jindararda", 40, 0)])) language5.add_meaning("Lizard", ([("jindararda", 70, 0), ("wiri-wiri", 50, 0)])) language6.add_meaning("Lizard", ([("mirdi", 60, 0), ("jindararda", 60, 0)])) # define the communities which community1 = Community("Com1", language1, 10) community2 = Community("Com2", language2, 10) community3 = Community("Com3", language3, 10) community4 = Community("Com4", language4, 10) community5 = Community("Com5", language5, 10) community6 = Community("Com6", language6, 10) communityList = [ community1, community2, community3, community4, community5, community6 ] # create network socialNet = nx.Graph() # create nodes from list of community objects # community objects ARE the nodes in this model socialNet.add_nodes_from(communityList) # add weighted connections between the nodes.