示例#1
0
def friend_accept(request):
    if request.GET['username']:
        friend_username = request.GET['username']
        try:
            friend = User.objects.get(username__exact=friend_username)
        except:
            friend = None
        try:
            friend_relation = MemberRelations.objects.get(
                Q(member_who_added__exact = friend.members) &
                Q(member_who_was_added__exact = request.user.members)

            )
        except:
            return HttpResponseRedirect("/profile/")
        friend_relation.active = True
        friend_relation.save()
        new_hist=History()
        new_hist.user=request.user.members
        new_hist.item_type="FRIEND"
        new_hist.timestamp=datetime.datetime.now()
        new_hist.item_id=friend_relation.id
        new_hist.save()
        next_hist=History()
        next_hist.user=friend.members
        next_hist.item_type="FRIEND"
        next_hist.timestamp=datetime.datetime.now()
        next_hist.item_id=friend_relation.id
        next_hist.save()
        return HttpResponseRedirect("/notifications/")
    return HttpResponseRedirect("/profile/")
示例#2
0
def signed(request, pet_id):
    p = get_object_or_404(Petition, pk=pet_id)
    userobject = get_object_or_404(Member, user=request.user)
    print userobject
    print "^^userobject^^"
    already_signed = SignPetition.objects.filter(user=userobject).filter(
        signedpet_id=pet_id)
    print already_signed
    if request.method == 'POST':
        signform = PetitionSignForm(request.POST)
        if already_signed:
            print "user already signed this petition!!!"
        elif signform.is_valid():
            print 'user not signed yet. going to update database'
            instance = signform.save(commit=False)
            instance.user = userobject
            instance.signedpet = p
            instance.save()
            p.current_num = p.current_num + 1
            p.save()
            new_hist = History()
            new_hist.user = userobject
            new_hist.item_type = "SIGN"
            new_hist.timestamp = datetime.datetime.now()
            new_hist.item_id = instance.id
            new_hist.save()
    return HttpResponseRedirect('/petitions/' + pet_id + '/')
示例#3
0
def index(request):
    userobject = Member.objects.get(user=request.user)
    print userobject
    if request.method == 'POST':
        form = PetitionForm(request.POST)
        if form.is_valid():
            newpetobj = form.save(commit=False)
            newpetobj.user = userobject
            newpetobj.current_num = 0
            newpetobj.timestamp = datetime.datetime.now()
            newpetobj.save()
            new_hist = History()
            new_hist.user = userobject
            new_hist.item_type = "PETITION"
            new_hist.timestamp = newpetobj.timestamp
            new_hist.item_id = newpetobj.id
            new_hist.save()
            return HttpResponseRedirect('/petitions/')
    else:
        form = PetitionForm()

    return render_to_response('user_pages/home/base_home_petitions.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
示例#4
0
def index(request):
    userobject = Member.objects.get(user=request.user)
    inv_list = Invited.objects.filter(invited_user=userobject).values_list(
        'debateinvite_id', flat=True)
    debate_list = Debate.objects.filter(id__in=inv_list)
    part_list = Participants.objects.filter(
        participant=userobject).values_list('debateparticipate_id', flat=True)
    part_deb_list = Debate.objects.filter(id__in=part_list)
    if request.method == 'POST':
        #form1=InviteDebateForm()
        form2 = ParticipantDebateForm()
        form = CreateDebateForm(request.POST)
        print 'request method is post(index)'
        if form.is_valid():
            print 'form is valid(index)'
            new_debate = form.save(commit=False)
            new_debate.created_by = userobject
            new_debate.privacy = "none"
            new_debate.timestamp = datetime.datetime.now()
            new_debate.save()
            #
            #	HISTORY TABLE UPDATION>>>
            #
            new_hist = History()
            new_hist.user = userobject
            new_hist.item_type = "DEBATE"
            new_hist.timestamp = new_debate.timestamp
            new_hist.item_id = new_debate.id
            new_hist.save()
            #p=get_object_or_404(Debate,pk=pet_id)
            print new_debate.num_part
            formset1 = formset_factory(InviteDebateForm,
                                       extra=new_debate.num_part)
            form1 = formset1()
            return render_to_response('user_pages/home/base_home_debate.html',
                                      {
                                          'dform1': form1,
                                          'dform2': form2,
                                          'new_debate': new_debate,
                                          'cur_user': request.user
                                      },
                                      context_instance=RequestContext(request))
        else:
            form = CreateDebateForm()
            return render_to_response('user_pages/home/base_home_debate.html',
                                      {
                                          'debate_list': debate_list,
                                          'part_deb_list': part_deb_list,
                                          'dform': form,
                                      },
                                      context_instance=RequestContext(request))
    else:
        form = CreateDebateForm()
        return render_to_response('user_pages/home/base_home_debate.html', {
            'debate_list': debate_list,
            'part_deb_list': part_deb_list,
            'dform': form,
        },
                                  context_instance=RequestContext(request))
示例#5
0
def index(request):
    userobject = get_object_or_404(Member, user=request.user)
    print userobject.id
    user_albums = Album.objects.filter(user=userobject)
    dic = []
    i = 0
    print user_albums
    print "^^look here"
    print "now"
    if user_albums:
        for alb in user_albums:
            print alb
            print "---"
            try:
                pic = Photo.objects.filter(album=alb).latest('timestamp')
                dic.append([{
                    'albumid': alb.id
                }, {
                    'albuma': alb.name
                }, {
                    'photo': pic.filename
                }])
            except:
                dic.append([{'albumid': alb.id}, {'albuma': alb.name}])
            print dic[i]
            i = i + 1
    print "look down"
    print dic
    if request.method == 'POST':
        form = CreateAlbumForm(request.POST)
        #uploading image
        form2 = UploadImageForm(request.POST, request.FILES)
        f = request.FILES['file']
        filename = ''.join(
            random.choice(string.ascii_lowercase + string.ascii_uppercase +
                          string.digits) for x in range(80))
        originalfilename = str(userobject.id) + "-" + datetime.datetime.now(
        ).strftime("%Y-%m-%d-%H-%M-%S") + "-" + filename + '.jpeg'
        if form.is_valid() and form2.is_valid():
            new_album = form.save(commit=False)
            new_album.user = userobject
            new_album.timestamp = datetime.datetime.now()
            new_album.save()
            #uploding image
            foldername = settings.PHOTO_DIR
            try:
                os.mkdir(foldername)
            except OSError as exc:  # Python >2.5
                if exc.errno == errno.EEXIST and os.path.isdir(foldername):
                    pass
                else:
                    raise
            with open('ups/albumpics/' + originalfilename,
                      'wb+') as destination:
                for chunk in f.chunks():
                    destination.write(chunk)
            size = 150, 150
            infile = 'ups/albumpics/' + originalfilename
            outfile = infile + "_thumbnail.jpeg"
            #		outfile=os.path.splitext(infile)[0]+"_thumbnail.jpeg"
            if infile != outfile:
                try:
                    im = Image.open(infile)
                    im.thumbnail(size, Image.ANTIALIAS)
                    im.save(outfile, "JPEG")
                except IOError:
                    print "cannot create thumbnail"
            savepic = form2.save(commit=False)
            savepic.album_id = new_album.id
            savepic.filename = originalfilename
            savepic.timestamp = datetime.datetime.now()
            savepic.save()

            new_hist = History()
            new_hist.user = userobject
            new_hist.item_type = "ALBUM"
            new_hist.timestamp = new_album.timestamp
            new_hist.item_id = new_album.id
            new_hist.save()
            print "saving object with"
            print new_album.user
            print new_album.timestamp
            print new_album.name
            return HttpResponseRedirect('/albumlist/' + str(new_album.id) +
                                        '/')
    else:
        form = CreateAlbumForm()
        uploadform = UploadImageForm()
    return render_to_response('user_pages/photo/gallery.html', {
        'albumlist': dic,
        'form': form,
        'imageform': uploadform
    },
                              context_instance=RequestContext(request))