Example #1
0
def profile(request):
    if 'username' in request.session:
        u = request.session['username']
        member = Member.objects.get(pk=u)

        if 'text' in request.POST:
            text = request.POST['text']
            if member.profile:
                member.profile.text = text
                member.profile.save()
            else:
                profile = Profile(text=text)
                profile.save()
                member.profile = profile
            member.save()
        else:
            if member.profile:
                text = member.profile.text
            else:
                text = ""
        return render(request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text': text,
            'loggedin': True
        })
    else:  #Redirect back to index.html with accompanying error message
        return render(
            request, 'social/index.html', {
                'appname': appname,
                'error': "You are not logged in, no access to profile page!"
            })
Example #2
0
def profile(request):
    if 'username' in request.session:
        u = request.session['username']
        member = Member.objects.get(pk=u)

        if 'text' in request.POST:
            text = request.POST['text']
            if member.profile:
                member.profile.text = text
                member.profile.save()
            else:
                profile = Profile(text=text)
                profile.save()
                member.profile = profile
            member.save()
        else:
            if member.profile:
                text = member.profile.text
            else:
                text = ""
        return render(request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text' : text,
            'loggedin': True}
            )
    else: #Redirect back to index.html with accompanying error message
        return render(request, 'social/index.html', {
            'appname': appname,
            'error': "You are not logged in, no access to profile page!"
            })
Example #3
0
def profile(request):
    if 'username' in request.session:
        u = request.session['username']
        member = Member.objects.get(pk=u)
        if 'text' in request.POST:
            text = request.POST['text']
            if member.profile:
                member.profile.text = text
                member.profile.save()
            else:
                profile = Profile(text=text)
                profile.save()
                member.profile = profile
            member.save()
        else:
            if member.profile:
                text = member.profile.text
            else:
                text = ""
        return render(request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text' : text,
            'loggedin': True}
            )
    else:
    	checkMessage = "User is not logged in, no access to profiles! Please log in."
    	return render(request, 'social/login.html', {
    							'appname':appname,
    							'checkMessage' : checkMessage,
    							'loggedin' : False}
    							)
Example #4
0
def profile(request):
    if 'username' in request.session:
        u = request.session['username']
        member = Member.objects.get(pk=u)
        if 'text' in request.POST:
            text = request.POST['text']
            if member.profile:
                member.profile.text = text
                member.profile.save()
            else:
                profile = Profile(text=text)
                profile.save()
                member.profile = profile
            member.save()
        else:
            if member.profile:
                text = member.profile.text
            else:
                text = ""
        return render(request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text': text,
            'loggedin': True
        })
    else:
        raise Http404("User is not logged it, no access to profiles!")
Example #5
0
def profile(request):
    u = request.session['username']
    member = Member.objects.get(pk=u)
    if 'text' in request.POST:
        text = request.POST['text']
        if member.profile:
            member.profile.text = text
            member.profile.save()
        else:
            profile = Profile(text=text)
            profile.save()
            member.profile = profile
        member.save()
    else:
        if member.profile:
            text = member.profile.text
        else:
            text = ""
    invitations = Invitation.objects.filter(to_user=u)
    return render(request, 'social/profile.html', {
        'appname': appname,
        'username': u,
        'invitations':invitations,
        'text' : text,
        'loggedin': True}
        )
Example #6
0
def profile(request):
    if 'username' in request.session:
        u = request.session['username']
        member = Member.objects.get(pk=u)
        if 'text' in request.POST:
            text = request.POST['text']
            if member.profile:
                member.profile.text = text
                member.profile.save()
            else:
                profile = Profile(text=text)
                profile.save()
                member.profile = profile
            member.save()
        else:
            if member.profile:
                text = member.profile.text
            else:
                text = ""
        return render(request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text': text,
            'loggedin': True
        })
    else:
        template = loader.get_template('social/login.html')
        error = "User is not logged it, no access to profiles page!"
        context = RequestContext(request, {
            'appname': appname,
            'error': error,
        })
        return HttpResponse(template.render(context))
Example #7
0
def member(request):
   if 'username' in request.session:
      username = request.session['username']
      #member = Member.objects.get(pk=view_user)
      if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        result = handle_upload_file(request.FILES['file'],str(request.FILES['file']))
        member = Member.objects.get(pk=username)
        profile = Profile(text=result)
        profile.member =  member
        profile.save()
        '''if member.profile:
        	member.profile.text = result
        	member.profile.save()
        else:
        	profile = Profile(text=result)
        	profile.save()
        	member.profile = profile
        member.save()
        historyresult=member.profile.text
        '''
        historyresult = ""
        member = Member.objects.get(pk=username)
        for profiles in Profile.objects.all():
          if profiles.member == member:
            historyresult += str(profiles) + "\n"
        #promem_obj = Profile.objects.get(profile.member=member)
        #historyresult = promem_obj.text
        #historyresult =  ''
        historyresult = historyresult.replace('\n','<br>')
        context = {
          'result' : result,
          'form' : form,
          'username' : username,
          'history' : historyresult,
          'loggedin': True
        }
        return render(request, 'social/member.html', context)
      else:
        form = UploadFileForm()
        result = "Choose the file and upload, then you can get the result!"
        context = {
          'result' : result,
          'form' : form,
          'username' : username,
          'loggedin': True
        }
      return render(request, 'social/member.html', context)
   else:
      raise Http404("User is not logged it, no access to members page!")
Example #8
0
def profile(request):
    u = request.session['username']
    member = Member.objects.get(pk=u)

    if 'text' in request.POST:
        text = request.POST['text']
        email = request.POST['email']
        gender = request.POST['gender_info']
        city = request.POST['city']

        # store profile information in the member table
        member.email = email
        member.about = text
        member.gender = gender
        member.city = city

        if member.profile:
            member.profile.text = text
            member.profile.save()
        else:
            profile = Profile(text=text)
            profile.save()
            member.profile = profile
        member.save()
    else:
        if member.profile:
            text = member.profile.text
        else:
            text = ""

    # updating newRequest session
    allRequests = Requests.objects.filter(requestTo=u)
    request.session['newRequests'] = allRequests.count()
    # END updating
    return render(
        request, 'social/profile.html', {
            'appname': appname,
            'username': u,
            'text': text,
            'city': member.city,
            'about': member.about,
            'email': member.email,
            'newRequests': request.session['newRequests'],
            'loggedin': True
        })
Example #9
0
def profile(request):
    u = request.session["username"]
    member = Member.objects.get(pk=u)
    if "text" in request.POST:
        text = request.POST["text"]
        if member.profile:
            member.profile.text = text
            member.profile.save()
        else:
            profile = Profile(text=text)
            profile.save()
            member.profile = profile
        member.save()
    else:
        if member.profile:
            text = member.profile.text
        else:
            text = ""
    return render(request, "social/profile.html", {"appname": appname, "username": u, "text": text, "loggedin": True})
Example #10
0
def profile(request):
    u = request.session['username']
    data = {}
    member = Member.objects.get(pk=u)
    if request.POST:
        # Get all the posted data
        text = request.POST['text']
        country = request.POST['country']
        city = request.POST['city']
        workplace = request.POST['workplace']
        phone = request.POST['phone']

        # If a picture was uploaded, treat it... otherwise, just insert a null object
        if 'picture' in request.FILES:
            # Create a ImageFile object
            picture = ImageFile(request.FILES['picture'])
            # Check if the picture is inside the configured settings
            # If is not, it just delete the ImageFile object
            if checkPictureSize(picture) == False:
                picture = None
                flash.error(
                    request,
                    'Picture dimensions not allowed! Only up to 800x600.')
            elif checkPictureExtension(picture) == False:
                picture = None
                flash.error(request,
                            'Format not allowed! Only gif, jpeg and png.')
        else:
            picture = None

        if member.profile:
            member.profile.text = text
            member.profile.country = country
            member.profile.city = city
            member.profile.workplace = workplace
            member.profile.phone = phone

            # If there was a uploaded picture which respects the settings
            if picture != None:
                member.profile.picture.save(request.FILES['picture'].name,
                                            picture)

            member.profile.save()
        else:
            profile = Profile(text=text,
                              country=country,
                              city=city,
                              workplace=workplace,
                              phone=phone,
                              picture=picture)
            profile.save()
            member.profile = profile

        member.save()

    # Put all data which will be used on view on the data array (if there is a profile created)
    if member.profile:
        data['text'] = member.profile.text
        data['country'] = member.profile.country
        data['city'] = member.profile.city
        data['workplace'] = member.profile.workplace
        data['phone'] = member.profile.phone
        data['picture'] = member.profile.picture
    else:
        data['text'] = None
        data['country'] = None
        data['city'] = None
        data['workplace'] = None
        data['phone'] = None
        data['picture'] = None

    return render(request, 'social/profile.html', {
        'appname': appname,
        'username': u,
        'data': data,
        'loggedin': True
    })
Example #11
0
def load_extra_data(backend, details,request, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.

    """
    social_profile = Profile.objects.filter(user=user).first()
    social_contacts = Contact.objects.filter(codes__code=uid)
    if social_contacts.exists():
        social_contacts.update(user=user, _email=user.email)
    else:
        social_contact = Contact.objects.filter(Q(user=user) | Q(_email=user.email)).first()
        if social_contact:
            social_contact.user = user
            social_contact.email = user.email
            social_contact.save()
            ContactOwners.objects.filter(contact=social_contact).update(code=uid)

    if not social_profile:
        social_profile = Profile()
        social_profile.user = user
        social_profile.save()
    social_profile.headline = response.get('headline')
    social_profile.industry = response.get('industry')
    location = Region.objects.filter(code=response.get('location', {}).get('country', {}).get('code')).first()
    if not location:
        location = Region()
        location.code = response.get('location', {}).get('country', {}).get('code')
        location.save()
    if response.get('positions'):
        for position in response.get('positions', {}).get('position', []):
            if position == 'is-current' or (isinstance(position, dict) and
                                            position.get('is-current', '')):
                try:
                    if isinstance(response.get('positions', {}).get('position', {}), list):
                        position_company = response.get('positions', {}).get('position', {})[0].get('company', {})
                        if position_company.has_key('id'):
                            company = Company.objects.filter(code=position_company['id']).first()
                        elif position_company.has_key('name'):
                            company = Company.objects.filter(name=position_company.get('name', None)).first()
                    elif response.get('positions', {}).get('position', {}).has_key('company'):
                        position_company = response.get('positions', {}).get('position', {}).get('company', {})
                        if type(position_company) == str:
                            position_company = dict(name=position_company)
                        if position_company.has_key('id'):
                            company = Company.objects.filter(code=position_company['id']).first()
                        elif position_company.has_key('name'):
                            company = Company.objects.filter(name=position_company.get('name', None)).first()
                        else:
                            continue
                    elif isinstance(position, str):
                        company = Company.objects.filter(name=position).first()
                        position_company = {'name': position}
                    else:
                        position_company = position.get('company', {})
                        if position_company.has_key('id'):
                            company = Company.objects.filter(code=position_company['id']).first()
                        elif position_company.has_key('name'):
                            company = Company.objects.filter(name=position_company.get('name', None)).first()
                        else:
                            continue
                    if not company:
                        company = Company()
                        company.code = position_company.get('id', None)
                        company.name = position_company.get('name', None)
                        company.industry = LinkedInIndustry.objects.filter(name=response.get('industry', {})).first()
                        company.save()
                except:
                    logger.exception('Reponse error: %s' % response)
                    raise
                social_profile.company = company
                break
    elif response.get('industry'):
        company = Company.objects.filter(code=None, name=response.get('industry')).first()
        if not company:
            company = Company()
            company.code = None
            company.name = response.get('industry')
            company.industry = LinkedInIndustry.objects.filter(name=response.get('industry', {})).first()
            company.save()
        social_profile.company = company
    social_profile.location = location
    social_profile.save()
    return {'social_profile': social_profile}
Example #12
0
import json
from social.models import Profile, Post, Comment
dados = open('./db.json',) 
  
data = json.load(dados) 
  
for i in data['users']: 
    profile = Profile()
    profile.name = i['name']
    profile.username = i['username']
    profile.email = i['email']
    profile.street = i['address']['street']
    profile.suite = i['address']['suite']
    profile.city = i['address']['city']
    profile.zipcode = i['address']['zipcode']
    profile.save()

for j in data['posts']:
    post = Post()
    user = Profile.objects.get(id=j['userId'])
    post.user = user
    post.title = j['title']
    post.body = j['body']
    post.save()

for k in data['comments']:
    commet = Comment()
    post = Post.objects.get(id=k['postId'])
    commet.post = post
    commet.name = k['name']
    commet.email = k['email']
Example #13
0
def profile(request):
    u = request.session['username']
    member = Member.objects.get(pk=u)
    member_obj = Member.objects.get(pk=u)
    # list of all other members
    members = Member.objects.exclude(pk=u)
    # list of people that are friend
    friends_s = Member.objects.filter(friends__username=u)
    # list of people that are request_friend me
    request_friends = Member.objects.filter(request_friend__username=u)

    email_display = member.email
    notify = '';

    # follow new friend
    if 'add' in request.GET:
        friend = request.GET['add']
        friend_obj = Member.objects.get(pk=friend)
        member_obj.request_friend.add(friend_obj)

        request_friend = member_obj.request_friend.all()
        request_friends = Member.objects.filter(request_friend__username=u)
        members = Member.objects.exclude(pk=u)
        # list of people that are requested friend
        friends = member_obj.friends.all()

        for membera in members:
            if membera in request_friend:
                if membera in request_friends and membera not in friends:
                    member_obj.friends.add(friend_obj)

        member_obj.save()
        return redirect('/social/profile/')
    # unfollow a friend
    if 'remove' in request.GET:
        friend = request.GET['remove']
        friend_obj = Member.objects.get(pk=friend)

        member_obj.friends.remove(friend_obj)
        member_obj.request_friend.remove(friend_obj)
        friend_obj.request_friend.remove(member_obj)

        member_obj.save()
        return redirect('/social/profile/')
    if 'text' in request.POST:
        text = request.POST['text']
        if member.profile:
            member.profile.text = text
            member.profile.save()
        else:
            profile = Profile(text=text)
            profile.save()
            member.profile = profile
        member.save()

    else:
        notify = '';
        if member.profile:
            text = member.profile.text
        else:
            text = ""

    notification_for_profile_settings = ''
    #gets the full path of uri
    if(len(request.get_full_path()) == 20):
        notification_for_profile_settings = 'successfully updated your password' #2
    if(len(request.get_full_path()) == 21):
        notification_for_profile_settings = 'successfully updated your password and email' #3
    if(len(request.get_full_path()) == 22):
        notification_for_profile_settings = 'please input email' #4
    if(len(request.get_full_path()) == 23):
        notification_for_profile_settings = 'please input new password and confirm' #5
    if(len(request.get_full_path()) == 24):
        notification_for_profile_settings = 'please ensure confirm password matches with new password' #6
    if(len(request.get_full_path()) == 25):
        notification_for_profile_settings = 'Please ensure your old password matches with your input' #7
    if(len(request.get_full_path()) == 26):
        notification_for_profile_settings = 'successfully updated your email' #8
    if(len(request.get_full_path()) == 27):
        notification_for_profile_settings = 'please ensure fields are not empty' #9


    return render(request, 'social/profile.html', {
        'appname': appname,
        'username': u,
        'members': members,
        'request_friends': request_friends,
        'friends_s': friends_s,
        'notify' : notify,
        'notification_for_profile_settings' : notification_for_profile_settings,
        'text' : text,
        'email_display': email_display,
        'loggedin': True}
        )