def follow(user_id): user_id = int(user_id) #save in Follower table Follower(target_user=user_id, follower_id=current_user.id).save() f = Follower.select().where( Follower.target_user == user_id, Follower.follower_id == current_user.id).first() #send email , rmb to include link with the target user's id # message = Mail( # from_email='*****@*****.**', # to_emails='*****@*****.**', # subject=f'{current_user.username} requested to follow you!', # html_content=f'<strong>Here are the links to view all your Fan requests <a href="http://localhost:5000/users/fan_request/{user_id}">http://localhost:5000/users/fan_request/{user_id}</a></strong>') # try: # sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) # response = sg.send(message) # print(response.status_code) # print(response.body) # print(response.headers) # except Exception as e: # print(e.message) bucket_name = os.environ.get('S3_BUCKET_NAME') return render_template('/users/user_profile.html', bucket_name=bucket_name, user=user_id, follow=f)
def generate_followers(): users = User.query.all() for user in users: general = Follower(UserID=user.UserID, Type="Forums", ParentID=1) wish_list = Follower(UserID=user.UserID, Type="Forums", ParentID=2) db.session.add(general) db.session.add(wish_list) db.session.commit()
def follow(molecule_id): userid = session['userid'] follower = Follower.query.filter(and_(Follower.ParentID == molecule_id, Follower.UserID == userid, Follower.Type == 'Molecules')).first() if not follower: follower = Follower(Type='Molecules', ParentID=molecule_id, UserID=userid) follower.save() return "OK"
def test_sfdc_case_creation(self): forum = Forum(Type='Issue', UserID=self.customer.UserID, AccountID=self.customer.AccountID) forum.save() follow = Follower(Type="Forums", ParentID=forum.ForumID, UserID=self.customer.UserID) follow.save() print 'Sleeping to ensure time for SFDC to respond or not' time.sleep(20) db.session.delete(forum) db.session.commit() # Assert SOFIE_ISSUE_EMAIL_USERS is emailed the error # Assert Customer is emailed b/c they are a follower print 'ok'
def setUp(self): generate_db.drop_database() generate_db.generate_database() self.generate_roles() #Turn off for sending emails email_sender.send_emails(False) self.act = Account(name='The Sofie Account') self.act.save() self.field_service_guy = User(Email='*****@*****.**', FirstName='Field_First_Name', LastName='Service_Last_Name', username='******', password='******', AccountID=self.act.id, RoleID=self.super_admin.RoleID) self.field_service_guy.save() os.environ['SOFIE_AUTO_FOLLOWING_USERS'] = str( self.field_service_guy.UserID) self.customer_act = Account(name='The Customer') self.customer_act.save() self.customer = User(Email='*****@*****.**', FirstName='Customer_First_Name', LastName='Customer_Last_Name', username='******', password='******', AccountID=self.customer_act.id, RoleID=self.chemist.RoleID) self.customer.save() self.forum = Forum(Subject='To Approve Molecules') self.forum.save() follower = Follower(Type='Forums', ParentID=self.forum.ForumID, EmailSubscribed=True, UserID=self.field_service_guy.UserID) follower.save() del emails_skipped[:]
def user_profile(id): #current profile user_id user = User.get_by_id(id) bucket_name = os.environ.get('S3_BUCKET_NAME') if current_user.is_authenticated: if int(id) != current_user.id: follow = Follower.select().where( Follower.target_user == user, Follower.follower_id == current_user.id).first() # followers followers = Follower.select().join( User, on=(Follower.target_user == User.id)).where( Follower.target_user == id).count() # following following = Follower.select().join( User, on=(Follower.follower_id == User.id)).where( Follower.follower_id == id).count() return render_template('users/user_profile.html', bucket_name=bucket_name, user=user, follow=follow, followingNo=following, followersNo=followers) else: return render_template('users/user_profile.html', bucket_name=bucket_name, user=user) else: return render_template('users/user_profile.html', bucket_name=bucket_name, user=user, follow='', followingNo='', followersNo='')
def generate_followings(user_ids, following_types_to_key): res = requests.get('http://www.sofienetwork.com/admin/Followers/records', headers={'Accept': 'application/json', 'Authorization': authorization}) followings = res.json() for follower in followings: follower_id = follower['FollowerID'] del follower['FollowerID'] f = Follower(**follower) if f.UserID in user_ids: f.UserID = user_ids[f.UserID] else: f.UserID = None if f.Type in following_types_to_key: keys = following_types_to_key[f.Type] if f.ParentID in keys: f.ParentID = keys[f.ParentID] else: f.ParentID = None else: f.ParentID = None f.save()
def accept_request(id): id = int(id) # ar = Follower.select().where(Follower.target_user == id and Follower.follower_id = cur_user_id) user = User.get_by_id(id) fan_list = user.followers.where(Follower.approve_sts == False, Follower.target_user == id) # update Follower table f = Follower.update(approve_sts=True).where( Follower.approve_sts == False, Follower.target_user == id, Follower.follower_id == current_user.id) f.execute() # breakpoint() bucket_name = os.environ.get('S3_BUCKET_NAME') return render_template('users/fan_request.html', bucket_name=bucket_name, user=user, fan_request_list=fan_list)
def reject_request(id): id = int(id) current_user.id = 39 user = User.get_by_id(id) fan_list = user.followers.where(Follower.approve_sts == False, Follower.target_user == id) #delete record in Follower table f = Follower.delete().where(Follower.approve_sts == False, Follower.target_user == current_user.id, Follower.follower_id == id) f.execute() # breakpoint() bucket_name = os.environ.get('S3_BUCKET_NAME') return render_template('users/fan_request.html', bucket_name=bucket_name, user=user, fan_request_list=fan_list)
def create_approval_following(): to_be_followers = [user for user in User.query.filter(or_(User.username=='fieldservice', User.username=='cdrake')).all()] newMoleculeForum = Forum.query.filter_by(Subject='To Approve Molecules').first() if not newMoleculeForum: newMoleculeForum = Forum() newMoleculeForum.Color = '#cf79f2' if to_be_followers: newMoleculeForum.AccountID = to_be_followers[0].AccountID newMoleculeForum.Subject = "To Approve Molecules" db.session.add(newMoleculeForum) db.session.commit() for user in to_be_followers: follower = Follower.query.filter(and_(Follower.Type=='Forums', Follower.ParentID==newMoleculeForum.ForumID, Follower.UserID==user.UserID)).first() if not follower: follower = Follower(UserID=user.UserID, Type='Forums', ParentID=newMoleculeForum.ForumID) db.session.add(follower) db.session.commit()
from chat_server import db from models.forum import Forum from models.user import User from models.follower import Follower faqs = Forum() faqs.Subject = "FAQ" faqs.Subtitle = "Frequently Asked Questions" faqs.AccountID = 1 faqs.save() users = User.query.all() for user in users: follower = Follower(UserID=user.UserID, Type="Forums", ParentID=faqs.ForumID) db.session.add(follower) db.session.commit()
def seed_data(): molecule = Molecule(CID=3232583, DisplayFormat="<p>[<sup>18</sup>F]-<sub>D</sub>-FEAU</p>", \ Description="FEAU is an nucleoside analog and a highly specific substrate for herpes simplex " \ "virus 1 thymidine kinase (HSV1-tk). FEAU is phosphorylated by HSV1-tk " \ "and subsequently retained intracellularly; hence it can annotate HSV1-tk " \ "expression in vivo. The gene encoding HSV1-tk is a commonly used reporter gene " \ "in cell-based therapy studies.", Name="<p>[<sup>18</sup>F]-<sub>D</sub>-FEAU</p>") molecule.save() molecule1 = Molecule(CID=3232584, DisplayFormat="<p>[<sup>18</sup>F]-<sub>D</sub>-FEAU</p>", \ Description="FEAU is an nucleoside analog and a highly specific substrate for herpes simplex " \ "virus 1 thymidine kinase (HSV1-tk). FEAU is phosphorylated by HSV1-tk " \ "and subsequently retained intracellularly; hence it can annotate HSV1-tk " \ "expression in vivo. The gene encoding HSV1-tk is a commonly used reporter gene " \ "in cell-based therapy studies.", Name="FEAU") molecule1.save() molecule2 = Molecule(CID=3232585, DisplayFormat="<p>[<sup>18</sup>F]-<sub>D</sub>-FEAU</p>", \ Description="FEAU is an nucleoside analog and a highly specific substrate for herpes simplex " \ "virus 1 thymidine kinase (HSV1-tk). FEAU is phosphorylated by HSV1-tk " \ "and subsequently retained intracellularly; hence it can annotate HSV1-tk " \ "expression in vivo. The gene encoding HSV1-tk is a commonly used reporter gene " \ "in cell-based therapy studies.", Name="FEAU") molecule2.save() molecule3 = Molecule(CID=3232586, DisplayFormat="<p>[<sup>18</sup>F]-<sub>D</sub>-FEAU</p>", \ Description="FEAU is an nucleoside analog and a highly specific substrate for herpes simplex " \ "virus 1 thymidine kinase (HSV1-tk). FEAU is phosphorylated by HSV1-tk " \ "and subsequently retained intracellularly; hence it can annotate HSV1-tk " \ "expression in vivo. The gene encoding HSV1-tk is a commonly used reporter gene " \ "in cell-based therapy studies.", Name="FEAU") molecule3.save() molecule.save_synonyms_from_pubchem() accounts = generate_accounts() main_account = accounts[0] generate_forums(main_account.id) alternative_account = accounts[1] chemist, admin, super_admin = generate_roles() main_user = generate_user(main_account.id, "test", super_admin.RoleID) create_approval_following() main_account_users = generate_users(main_account.id, 5, chemist.RoleID) alternative_account_users = generate_users(alternative_account.id, 5, chemist.RoleID) competitor_user = alternative_account_users[0] sequence_id = generate_zipped_sequence(main_user, molecule.ID) data = open(os.path.join("seeds", "molecule.jpeg"), 'r') data = data.read() reaction_scheme = SequenceAttachment(SequenceID=sequence_id, FileName='molecules.jpg', Type="ReactionScheme", Attachment=data) reaction_scheme.save() competitor_sequence = generate_zipped_sequence(competitor_user, molecule.ID) follow = Follower(UserID=main_user, Type="Sequences", ParentID=competitor_sequence) follow.save() follow = Follower(UserID=main_user, Type="Molecules", ParentID=molecule.ID) follow.save() generate_comment(main_user, sequence_id) generate_comment(competitor_user, sequence_id, "My #sequence produces a better yield") generate_private_sequence(main_user, molecule.ID) generate_private_sequence(main_user, molecule.ID, False) for x in xrange(PAGINATION_SIZE+2): sequence_id = generate_sequence(main_user, molecule.ID) sequence = Sequence.query.filter_by(SequenceID=sequence_id).first() sequence.StartingActivity = 21.33 sequence.Yield = 12.55 sequence.SpecificActivity = 20.3 sequence.NumberOfSteps = 20 sequence.SynthesisTime = 400 sequence.save() generate_comment(main_user, competitor_sequence, "Testing Pagination size %i" % x) image_comment = Comment(ParentID=1,Type='Sequences',RenderType='image',Message='',UserID=main_user) image_comment.save() data = open(os.path.join("seeds", "molecule.jpeg"), 'r') data = data.read() image = SequenceAttachment(ParentID=image_comment.CommentID,Type='comments',Attachment=data) image.save() generate_unique_downloads() generate_issues() time.sleep(15) generate_issues()
def unfollow(user_id): Follower.delete().where(Follower.target_user == user_id, ).execute() pass
def generate_issue(user, subject, subtitle, message, num_images, num_attachments, color, sfdc_data=None): forum = Forum(Subject=subject, AccountID=user.AccountID, UserID=user.UserID, Color=color, Subtitle=subtitle, Type='Issue') forum.save(sfdc_data) for image_id in xrange(num_images): img = request.files['image%s' % image_id] image = img.read() file_name = str(img.filename) comment = Comment(ParentID=forum.ForumID, Type='Forums', Message="", RenderType='image', UserID=user.UserID) comment.save() attachment = SequenceAttachment(Attachment=image, ParentID=comment.CommentID, Type='comments', FileName=file_name) attachment.save() for image_id in xrange(num_attachments): img = request.files['attachment%s' % image_id] image = img.read() file_name = str(img.filename) comment = Comment(ParentID=forum.ForumID, Type='Forums', Message="", RenderType='attachment', UserID=user.UserID) comment.save() attachment = SequenceAttachment(Attachment=image, ParentID=comment.CommentID, Type='comments', FileName=file_name) attachment.save() comment.Message = json.dumps({ "url": "/comment/%s/attachment/%s" % (comment.CommentID, attachment.SequenceAttachmentID), "name": file_name }) comment.save() print forum.ForumID team_members = user.account.users # Make all team members follow the issue for member in team_members: if user.UserID != member.UserID and str( member.UserID) not in SOFIE_AUTO_FOLLOWING_USER_IDS( ) and user.Active is True: team_follow = Follower(Type="Forums", ParentID=forum.ForumID, UserID=member.UserID, EmailSubscribed=False) team_follow.save() # Make the creator of the issue follow the case follow = Follower(Type="Forums", ParentID=forum.ForumID, UserID=user.UserID) follow.save() print follow.FollowerID sofie_users = User.query.filter( and_(User.UserID.in_(SOFIE_AUTO_FOLLOWING_USER_IDS()), User.Active == True)) # Make all SOFIE members aware of the issue for sofie_user in sofie_users: sofie_userid = sofie_user.UserID if sofie_userid and user.UserID != sofie_userid: auto_follow = Follower(Type="Forums", ParentID=forum.ForumID, UserID=sofie_userid) auto_follow.save() Comment.make_comments(user.UserID, "Forums", forum.ForumID, message) return forum, follow