Beispiel #1
0
    def post_new_endorsement(jwt):
        try:
            # Get request data
            req_data = request.get_json()
            giver_id = req_data.get('giver_id')
            receiver_id = req_data.get('receiver_id')
            skill_id = req_data.get('skill_id')
            
            # Create new Endorsement instance
            new_endorsement = Endorsement(
                giver_id = giver_id,
                receiver_id = receiver_id,
                skill_id = skill_id
            )

            # Create new entry in database
            new_endorsement.insert()

            return jsonify({
                'success':True,
                'endorsement': new_endorsement.format()
            })
        except:
            db.session.rollback()
            abort(422)
Beispiel #2
0
  def post(self):
    viewer = self.user_model
    post = cgi.escape(self.request.get('key'))
    #Person getting the endorsement
    endorsee = cgi.escape(self.request.get('endorsee'))
    text = cgi.escape(self.request.get('text'))
    skill_key = ndb.Key(urlsafe=post)
    endorsee_key = ndb.Key(urlsafe=endorsee)
    endorsement = Endorsement.query(Endorsement.endorsee == endorsee_key,
      Endorsement.skill == skill_key).get()
    if text != "empty":
      details = EndorsementDetails()
      details.endorser = viewer.key
      details.endorsee = endorsee_key
      details.skill = skill_key
      details.description = text
      details.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
      details.put()

    if endorsement is not None:
      endorsement.endorsers.append(viewer.key)
      endorsement.endorsement_count +=1
    else:
      endorsement = Endorsement()
      endorsement.endorsers.append(viewer.key)
      endorsement.endorsee = endorsee_key
      endorsement.skill = skill_key
      endorsement.endorsement_count +=1
    endorsement.put()
Beispiel #3
0
  def post(self):
    viewer = self.user_model
    post = cgi.escape(self.request.get('key'))
    #Person getting the endorsement
    endorsee = cgi.escape(self.request.get('endorsee'))
    text = cgi.escape(self.request.get('text'))
    skill_key = ndb.Key(urlsafe=post)
    endorsee_key = ndb.Key(urlsafe=endorsee)
    endorsement = Endorsement.query(Endorsement.endorsee == endorsee_key,
      Endorsement.skill == skill_key).get()
    if text != "empty":
      details = EndorsementDetails()
      details.endorser = viewer.key
      details.endorsee = endorsee_key
      details.skill = skill_key
      details.description = text
      details.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
      details.put()

    if endorsement is not None:
      endorsement.endorsers.append(viewer.key)
      endorsement.endorsement_count +=1
    else:
      endorsement = Endorsement()
      endorsement.endorsers.append(viewer.key)
      endorsement.endorsee = endorsee_key
      endorsement.skill = skill_key
      endorsement.endorsement_count +=1
    endorsement.put()
Beispiel #4
0
def add_endorsement(request, commitment_id):

    commitment = get_object_or_404(Commitment, pk=commitment_id)

    if request.user.get_profile().is_representative and request.user.get_profile().representativeprofile.organisation == commitment.organisation:
        pass
    elif request.user.is_staff:
        pass
    else:
        raise Exception("Only organisation representatives and staff administrators make endorsements.")

    if request.POST:
        user = request.user
        text = request.POST.get('endorsement_text')

        endorsement = Endorsement(commitment=commitment, representative=user, endorsement_text=text)
        endorsement.save()

        messages.info(request, "Endorsement has been recorded.")
    else:
        messages.info(request, "Endorsement not saved, request must be post.")

    return redirect('hours.views.commitment', commitment_id=commitment.id)
Beispiel #5
0
  def get(self, profile_id):
    viewer = self.user_model
    q = User.query(User.username == profile_id)
    user = q.get()
    profile = Profile.query(Profile.owner == user.key).get()
    #if profile isn't created, create one
    if not profile:
      profile = Profile()
      profile.owner = user.key
      profile.about = "I'm new to Techeria. Add me!"
      profile.put()
    skill_list = []
    endorsements = Endorsement.query(Endorsement.endorsee == user.key).fetch()
    endorsement_details = EndorsementDetails.query(EndorsementDetails.endorsee == user.key).fetch()
    user.endorsement_count = len(endorsement_details)
    for skill in user.skills:
      skill = skill.get()
      if skill is not None:
        endorsement_list = []
        endorsement_list.append(skill)
        #Get endorsement messages
        #Add number #
        count = 0
        for x in endorsements:
          if x.skill == skill.key:
            count=x.endorsement_count
        endorsement_list.append(count)
        skill_list.append(endorsement_list)

    connection_list = []
    """Get friend count """
    counter = 0
    for connection in user.friends:
      connection = User.get_by_id(connection.id())
      counter+=1
    user.friend_count = counter
    user.put()
    # Get Nested Comments
    comments = Comment.query(Comment.root==True, ndb.OR(Comment.recipient_key == user.key, Comment.sender_key == user.key)).order(-Comment.time).fetch(10)
    index = 0
    while index < len(comments):
      children = Comment.query(Comment.parent == comments[index].key).fetch()
      index += 1
      comments[index:index] = children
    if user:
      self.response.out.write(template.render('views/profile.html',
                                        {'user':user, 'comments': comments,
                                        'viewer':viewer, 'skills':skill_list, 'profile':profile, 'endorsements':endorsement_details}))
Beispiel #6
0
  def get(self, profile_id):
    viewer = self.user_model
    q = User.query(User.username == profile_id)
    user = q.get()
    profile = Profile.query(Profile.owner == user.key).get()
    #if profile isn't created, create one
    if not profile:
      profile = Profile()
      profile.owner = user.key
      profile.about = "I'm new to Techeria. Add me!"
      profile.put()


    TutorPosts = RequestPost.query(RequestPost.requester == profile_id).fetch()
    user.jobpostings = len(TutorPosts)

    #posts_tutors_applied_to = []

    posts_tutors_applied_to = ""

    AllPosts = RequestPost.query()
    for onePost in AllPosts:
      if user.username in onePost.list_of_applicants:
        posts_tutors_applied_to = RequestPost.query().fetch()

    user.jobsapplied = len(posts_tutors_applied_to)

    skill_list = []
    endorsements = Endorsement.query(Endorsement.endorsee == user.key).fetch()
    endorsement_details = EndorsementDetails.query(EndorsementDetails.endorsee == user.key).fetch()
    user.endorsement_count = len(endorsement_details)
    for skill in user.skills:
      skill = skill.get()
      if skill is not None:
        endorsement_list = []
        endorsement_list.append(skill)
        #Get endorsement messages
        #Add number #
        count = 0
        for x in endorsements:
          if x.skill == skill.key:
            count=x.endorsement_count
        endorsement_list.append(count)
        skill_list.append(endorsement_list)

    connection_list = []
    """Get friend count """
    counter = 0
    for connection in user.friends:
      connection = User.get_by_id(connection.id())
      counter+=1
    user.friend_count = counter
    user.put()
    # Get Nested Comments
    comments = Comment.query(Comment.root==True, ndb.OR(Comment.recipient_key == user.key, Comment.sender_key == user.key)).order(-Comment.time).fetch(100)
    index = 0
    while index < len(comments):
      children = Comment.query(Comment.parent == comments[index].key).fetch()
      index += 1
      comments[index:index] = children
    if user:
      self.response.out.write(template.render('views/profile.html',
                                        {'user':user, 'comments': comments,
                                        'viewer':viewer, 'skills':skill_list, 'profile':profile, 'endorsements':endorsement_details, 
                                        'TutorPosts': TutorPosts, 'posts_tutors_applied_to': posts_tutors_applied_to
                                        }))
Beispiel #7
0
  def get(self, profile_id):
    viewer = self.user_model
    q = User.query(User.username == profile_id)
    user = q.get()
    profile = Profile.query(Profile.owner == user.key).get()
    #if profile isn't created, create one
    if not profile:
      profile = Profile()
      profile.owner = user.key
      profile.about = "I'm new to Techeria. Add me!"
      profile.put()

    TutorPosts = RequestPost.query(RequestPost.requester == profile_id).fetch()
    user.jobpostings = len(TutorPosts)


    # for starring and stuff
    starQry = RequestPost.query(RequestPost.payment_is_done == True)
    tutors_who_can_rate = []
    tutees_who_can_rate = []
    for a in starQry:
      tutors_who_can_rate.append(a.final_provider)
      tutees_who_can_rate.append(a.requester)


    #Get Notifications
    notifications = NotifiedMessage.query(NotifiedMessage.person_reference == viewer.username).fetch(10)
    notis_count = len(notifications)


    trl = Transaction.query()
    transactions_list = []
    for oneTransaction in trl:
      if viewer.username in oneTransaction.testPeoplewhocanseethis:
        transactions_list.append(oneTransaction)


    #Get Emails
    msg_count = viewer.msg_count


    posts_that_are_paid = RequestPost.query(RequestPost.payment_is_done == True).fetch()
    posts_tutors_applied_to = RequestPost.query().fetch()
    #payments history
    #for onePaid in PaidPosts:
      #if onePaid.final_provider == user.username:
      #posts_that_are_paid = PaidPosts


    skill_list = []
    endorsements = Endorsement.query(Endorsement.endorsee == user.key).fetch()
    endorsement_details = EndorsementDetails.query(EndorsementDetails.endorsee == user.key).fetch()
    user.endorsement_count = len(endorsement_details)
    for skill in user.skills:
      skill = skill.get()
      if skill is not None:
        endorsement_list = []
        endorsement_list.append(skill)
        #Get endorsement messages
        #Add number #
        count = 0
        for x in endorsements:
          if x.skill == skill.key:
            count=x.endorsement_count
        endorsement_list.append(count)
        skill_list.append(endorsement_list)

    connection_list = []
    """Get friend count """
    counter = 0
    for connection in user.friends:
      connection = User.get_by_id(connection.id())
      counter+=1
    user.friend_count = counter
    user.put()
    # Get Nested Comments
    comments = Comment.query(Comment.root==True, ndb.OR(Comment.recipient_key == user.key, Comment.sender_key == user.key)).order(-Comment.time).fetch(100)
    index = 0
    while index < len(comments):
      children = Comment.query(Comment.parent == comments[index].key).fetch()
      index += 1
      comments[index:index] = children
    if user:
      self.response.out.write(template.render('views/profile.html',
                                        {'user':user, 
                                        'comments': comments,
                                        'viewer':viewer, 
                                        'skills':skill_list, 
                                        'profile':profile, 
                                        'endorsements':endorsement_details, 
                                        'TutorPosts': TutorPosts, 
                                        'posts_tutors_applied_to': posts_tutors_applied_to, 
                                        'posts_that_are_paid': posts_that_are_paid,
                                        'notifications': notifications,
                                        'notis_count': notis_count,
                                        'transactions_list': transactions_list,
                                        'tutors_who_can_rate': tutors_who_can_rate,
                                        'tutees_who_can_rate': tutees_who_can_rate,
                                        'msg_count': msg_count
                                        }))
Beispiel #8
0
  def get(self, profile_id):
    viewer = self.user_model
    get_notifications(viewer)
    viewer.last_check =datetime.datetime.now() - datetime.timedelta(hours=8)
    viewer.put()

    # Get profile info
    profile_owner = User.query(User.username == profile_id).get()
    profile = Profile.query(Profile.owner == profile_owner.key).get()
    if not profile:
      # If profile isn't created, instantiate
      new_profile = Profile()
      new_profile.owner = profile_owner.key
      new_profile.about_me = "I love to eat food"
      new_profile.put()

    current_date = datetime.datetime.now() - datetime.timedelta(hours=8)

    # Get profile history
    history =  Request.query(Request.start_time <= current_date, Request.sender == profile_owner.key).order(Request.start_time)

    # Get Request regarding the user
    reqs = []
    timeline_requests = []
    waiting_requests = []
    my_reqs = []
    fired_requests = []
    table_reqs = []
    pending_requests = []
    accepted_requests = []
    completed_reqs = []
    alloted_time = current_date + datetime.timedelta(minutes=20)

    # Get all requests where profile owner is foodie and expert
    available_requests = Request.query(Request.start_time >= alloted_time).order(Request.start_time)
    my_reqs = Request.query(ndb.OR(Request.sender==profile_owner.key, Request.recipient == profile_owner.key), Request.start_time >= alloted_time).order(Request.start_time).fetch()
    dead_reqs = Request.query(ndb.OR(Request.sender==profile_owner.key, Request.recipient == profile_owner.key), Request.start_time <= alloted_time).order(Request.start_time).fetch()


    # Get all pending request that user has bid on
    for request in available_requests:
      # Get all requests you didn't send
      if request.sender != profile_owner.key:
        # Request not accepted yet
        if request.recipient == None:
          # Check for bidders
          for bid in request.bidders:
            bid = bid.get()
            if bid.name == profile_owner.username:
              # Bid by user
              pending_requests.append(request)

    table_requests = my_reqs[:] + dead_reqs[:] + pending_requests[:]
    table_requests = sorted(table_requests, key=lambda x: x.start_time, reverse=True)
    waiting_requests = [x for x in table_requests if x.status == "waiting for a bid"]
    accepted_requests = [x for x in table_requests if x.status == "accepted"]
    timeline_requests = table_requests
    pending_requests = [x for x in timeline_requests if x.status == "pending"]
    pending_requests = sorted(pending_requests, key = lambda x: x.start_time, reverse=True)
    timeline_requests = [x for x in timeline_requests if x.status != "waiting for a bid"]
    timeline_requests = [x for x in timeline_requests if x.status != "pending"]
    timeline_requests = [x for x in timeline_requests if x.status != "dead"]
    timeline_requests = [x for x in timeline_requests if x.status != "accepted"]


    timeline_comments = []
    for r in timeline_requests:
      c = Endorsement.query(Endorsement.request == r.key).fetch()
      if c:
        timeline_comments.append(c)
      else:
        timeline_comments.append("None")

    timeline_requests = zip(timeline_requests, timeline_comments)
    completed_requests = [x for x in timeline_requests if x[0].status == "complete"]
    fired_requests = [x for x in timeline_requests if x[0].status == "fired"]

    self.response.out.write(template.render('views/profile.html',
                             {'owner':profile_owner, 'profile':profile, 'history': history, 'user': viewer, 'timeline_requests': timeline_requests,
                             'pending_requests': pending_requests, 'accepted_requests': accepted_requests, 'completed_requests': completed_requests,
                             'waiting_requests': waiting_requests, 'fired_requests': fired_requests}))
Beispiel #9
0
  def post(self):
    user = self.user_model
    request_key = cgi.escape(self.request.get('request_comment'))
    request = ndb.Key(urlsafe=request_key).get()
    rating = cgi.escape(self.request.get('rating'))
    comment = cgi.escape(self.request.get('comment'))

    # Person getting endorsement
    recipient = cgi.escape(self.request.get('recipient_name'))
    recipient_user = User.query(User.username == recipient).get()
    recipient_key = recipient_user.key

    if len(comment) > 0:
      endorsement = Endorsement()
      endorsement.request = request.key
      endorsement.creation_time = datetime.datetime.now() - datetime.timedelta(hours=8)
      endorsement.reating = rating
      endorsement.text = comment

      if request.sender_name == user.username:
        # Foodie reviewing Expert
        endorsement.sender_name = request.sender_name
        endorsement.recipient = request.recipient
        endorsement.sender = request.sender
      else:
        # Expert reviewing Foodie
        endorsement.sender = request.recipient
        endorsement.recipient = request.sender
        endorsement.sender_name = request.recipient_name

      endorsement.put()

    # modify rating
    if rating == "positive":
      recipient_user.positive = recipient_user.positive + 1
    elif rating == "neutral":
      recipient_user.neutral = recipient_user.neutral + 1
    else:
      recipient_user.negative = recipient_user.negative + 1
    if recipient_user.positive != 0:
      recipient_user.percent_positive = (recipient_user.positive / (recipient_user.positive + recipient_user.negative)) * 100
    else:
      recipient_user.percent_positive = 0
    recipient_user.put()

    self.redirect('/foodie/{}'.format(recipient) + "?q=timeline/all")