Beispiel #1
0
def add_interest(request, interest):

    s = Session.objects.get(session_key=request.session["auth_token"])
    user = User.objects.get(login=s.get_decoded()['login'])
    if Thematic.objects.filter(name=interest).count() is 0:
        thematic = Thematic(name=interest)
        thematic.save()
    else:
        thematic = Thematic.objects.get(name=interest)
    interest = Interest(user=user, thematic=thematic)
    interest.save()
    return HttpResponse('Interest added successful')
Beispiel #2
0
def add_interests(user_id, interests):
    logger.warning('add_interests user_id:%s interests:%s' % (user_id, str(interests)))
    user = User.get_by_id(user_id)
    for interest in interests:
        if not interest:
            continue
        if interest not in user.get('interests', []):
            User.push_user_field(user_id, 'interests', interest)
        network = user.get('network')
        interest = interest.strip('#').lower()
        interest_data = Interest.get_by_name_network(interest, network)
        int_col = get_interest_collection()
        
        if not interest_data:
            #Add a new one
            interest_data = {
                'name'          : interest,
                'num_followers' : 1,
                'followers'     : [user_id],
                'network'       : network,
                'created'       : datetime.datetime.now(),
                'creator'       : user_id
            }
            user_id = int_col.insert(interest_data)
        else:
            #Update existing
#            push={}
#            updates = {}
            followers = interest_data.get('followers')
            if user_id not in followers:
                updates = {"$push" : {'followers' : user_id}, "$set" : { "num_followers" : len(followers) + 1 }}
                int_col.update({"name" : interest}, updates)
Beispiel #3
0
def random_setting():
    allUsers = User.query.all()
    user = User.query.filter_by(email=session['email']).first()

    if user is None:
        return redirect(url_for('signin'))

    form = RandomForm()
    session['room'] = 'General'

    if 'email' not in session:
        return redirect(url_for('signin'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('random_setting.html',
                                   form=form,
                                   user=user,
                                   allUsers=allUsers)
        else:
            user.interests.append(Interest(form.interest.data))
            db.session.commit()
            return redirect(url_for('random_setting'))

    if request.method == 'GET':
        return render_template('random_setting.html',
                               form=form,
                               user=user,
                               allUsers=allUsers)
Beispiel #4
0
 def form_valid(self, form):
     """ Edit or create a new Interest """
     name = form.cleaned_data['interest']
     if self.request.GET['interest']:
         interest = Interest.objects.get( pk = self.request.GET['interest'] )
     else:
         # Each interest must be unique. The form overrides unique_validate, so make sure 
         try:
             interest = Interest.objects.get( interest = name )
         except Interest.DoesNotExist:
             interest = Interest( interest = name )
     
     interest.status = form.cleaned_data['status']
     interest.save()
     
     return HttpResponseRedirect(reverse('interest'))
Beispiel #5
0
    def post(self):
        # get the user info from their form
        uni_in_form = self.request.get("schools")
        age_in_form = self.request.get("ages")
        major_in_form = self.request.get("majors")
        insta = self.request.get("social_media")
        handle = str(insta).replace("@", '')
        social_media_in_form = "https://www.instagram.com/" + handle + "/"

        # this gets me an array of strings, where each string is a value
        interest_in_form_array = self.request.get("interests",
                                                  allow_multiple=True)

        # image is caught
        # image_in_form = self.request.get("image")
        # print "\n\n\n\n\n\n\n\n"
        # print image_in_form
        # print "\n\n\n\n\n\n\n\n"
        # self.response.out.write('<div><img src="/img?img_id=%s"></img>' %
        # user.key.urlsafe())
        # image_in_form = images.resize(image_in_form, 32, 32)
        # image is saved to a specific file (aka /images)

        # convert the string array into an array of Interest Objects
        array_of_interest_objs = []
        for interest in interest_in_form_array:
            this_interest = Interest(name=interest)
            array_of_interest_objs.append(this_interest)
            this_interest.put()

        # our_user is the existing_user
        our_user = get_logged_in_user(self)

        # give our_user values in the data store
        our_user.university = uni_in_form
        our_user.age = age_in_form
        our_user.major = major_in_form
        our_user.social_media = social_media_in_form
        our_user.interests = array_of_interest_objs
        # our_user.image = image_in_form

        # save those changes to our_user values
        our_user.put()

        log_out_dict = {'logout_link': users.create_logout_url('/')}

        self.redirect('/people')
 def create_project(self, request):
     u = self.current_user(request)
     n = t = e = key = ''; c = 0
     for k, v in request.POST.items():
         if 'title' in k: n = '#%s' % v.replace(" ", "")
         elif 'credit' in k: c = v#+int(float(v)*0.1)
         elif 'content' in k: t = v
         elif 'deadline' in k: e = datetime.strptime(v, '%d/%m/%Y')
         elif 'keyword' in k: key = v
     project = Project(name=n,user=u,content=t,end_time=e,credit=int(c))
     project.save()
     interest = Interest(project=project,key=key)
     interest.save()
     service = StreamService()
     access_token = u.profile.google_token
     t = re.compile(r'<.*?>').sub('', t)
     url, token = service.video_entry(n[:1], t, 'efforia', access_token)
     return render(request, 'projectvideo.jade', {'static_url':settings.STATIC_URL,
                                         'hostname':request.get_host(),
                                         'url':url, 'token':token}, content_type='text/html')
Beispiel #7
0
def add_interests(interests: List[str],
                  user_session_tuple: (UserInDB,
                                       Session) = Depends(get_current_user)):
    user: UserInDB = user_session_tuple[0]
    session: Session = user_session_tuple[1]

    prev_interests = [interest.subject for interest in user.interests]
    user.interests += [
        Interest(user=user, subject=i) for i in interests
        if i not in prev_interests
    ]
    session.commit()

    return make_user_from_db(user)
Beispiel #8
0
def sync_user_fb_interests(user):
    fb_account = FacebookAccount.objects.get(user=user)
    fb_id = fb_account.social_id
    fb_token = fb_account.token

    graph = GraphAPI(fb_token)
    graph_likes = graph.get_connections(fb_id, "likes")
    likes = graph_likes['data']

    for like in likes:
        like_name = like['name']
        like_category = like['category']
        like_id = like['id']
        try:
            like_date = like['created_time']
            like_creation = strptime(like_date[:-5],"%Y-%m-%dT%H:%M:%S")
            like_datecreation = datetime.date(like_creation.tm_year, like_creation.tm_mon, like_creation.tm_mday)
        except KeyError:
            like_datecreation = datetime.date.today()
        (category, created) = InterestCategory.objects.get_or_create(name=like_category)
        interests = Interest.objects.filter(fb_id=like_id)
        if len(interests) == 0:
            interest = Interest(name=like_name, category=category, fb_id=like_id)
        else:
            interest = interests[0]

        interest.name = like_name
        interest.category = category
        interest.save()

        user_interests = UserInterests.objects.filter(user=user, interest=interest)
        if len(user_interests) == 0:
            user_interest = UserInterests.objects.create(user=user, interest=interest, created=like_datecreation)
        else:
            user_interest = user_interests[0]
        user_interest.created = like_datecreation
        user_interest.save()
Beispiel #9
0
def remove_interests(user_id, interests):
    logger.warning('remove_interests user_id:%s interests:%s' % (user_id, str(interests)))
    for interest in interests:
        user = User.get_by_id(user_id)
        network = user.get('network')
        existing = set(user.get('interests', []))
        if interest in existing:
            remaining = list(existing - set([interest]))
            User.set_user_field(user_id, 'interests', remaining)
        
        interest_data = Interest.get_by_name_network(interest, network)
        int_col = get_interest_collection()
    #    user = User.get_by_id(user_id)
    #    network = user.get('network')
        if user_id in interest_data.get('followers'):
            int_col.update({"name" : interest, 'network' : network}, {"$inc" : { "num_followers" : -1 }, "$pull" : { "followers" : user_id } })
Beispiel #10
0
def check_network_interests(network):
    """
    Checks that the current network has the pre populated interests added, if not it adds them
    """
    logger.warning("check_network_interests network:%s" % network)
    if not network:
        logger.warning("check_network_interests network:%s network value none so exiting" % network)
        return
    interests = list(Interest.get_all_from_network(network))
    logger.warning("check_network_interests network:%s %s interests found" % (network, str(len(interests))))
    if len(interests) == 0:
        new_interests = []
        for name in Interest.PRE_POPULATE:
            new_interests.append({
                'name'          : name,
                'num_followers' : 0,
                'followers'     : [],
                'network'       : network,
                'created'       : datetime.datetime.now(),
                'creator'       : 'prepop'
            })
        int_col = get_interest_collection()
        user_id = int_col.insert(new_interests)
Beispiel #11
0
def interest(itemid):
    userid = session.get('user_id')
    new_interest = Interest(userid=userid, itemid=itemid)
    db.session.add(new_interest)
    db.session.commit()
    return redirect(url_for('detail', itemid=itemid))
Beispiel #12
0
        city_data = [('Ann Arbor', 'Michigan', 'EST', 42.281389, -83.748333), ('North Campus', 'Michigan', 'EST', 42.292126, -83.715819), \
           ('Detroit', 'Michigan', 'EST', 42.331598, -83.046528)]
        cities = {}
        for city_d in city_data:
            cities[city_d[0]] = City(city_d[0], city_d[1], city_d[2],
                                     city_d[3], city_d[4])
            db.session.add(cities[city_d[0]])
        db.session.commit()

        interest_data = [
            'Sports', 'Clothing', 'Food', 'Entertainment', 'Technology',
            'Home Goods', 'Transportation'
        ]
        interests = {}
        for interest_d in interest_data:
            interests[interest_d] = Interest(interest_d)
            db.session.add(interests[interest_d])
        db.session.commit()




        business_data = [("Zingerman's Delicatessen", '422 Detroit St', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.2846861, -83.7472546, ['Food']), ("University of Michigan Museum of Natural History", '1109 Geddes Ave', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.278429, -83.735133, ['Entertainment']), \
            ('Bubble Island', '1220 S University Ave #100', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.274919, -83.733405, ['Food']), ('University of Michigan Law School', '625 S State St', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.274317, -83.740231, ['Entertainment']), \
            ('Mujo Cafe', '2281 Bonisteel Blvd', cities['North Campus'].id, users['*****@*****.**'].email, 42.291595, -83.715970, ['Food']), ('Woodward Coney Island', '616 Woodward Ave', cities['Detroit'].id, users['*****@*****.**'].email, 42.330873, -83.045599, ['Food']), \
            ('Detroit Tigers', '2100 Woodward Ave', cities['Detroit'].id, users['*****@*****.**'].email, 42.338888, -83.048517, ['Food', 'Entertainment', 'Sports']), ('Jimmy John\'s', '600 Packard St', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.271592, -83.741702, ['Food']), \
            ('Domino\'s Pizza', '716 Packard St', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.270431, -83.740315, ['Food']), ('Michigan Ticket Office', '', cities['Ann Arbor'].id, users['*****@*****.**'].email, 42.269460, -83.740768, ['Food','Sports','Entertainment'])]
        businesses = {}
        for business_d in business_data:
            businesses[business_d[0]] = (Business(business_d[0], business_d[1],
                                                  business_d[2], business_d[3],