Ejemplo n.º 1
0
def new_group_action(request, actionId):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    action = SharingActionNeeded.objects.get(pk=actionId)
    group = action.subject.group
    items = getItemsSharedByCurrentMember(currentParticipant.member)
    # this must be the person who the action is for
    if currentParticipant.member != action.alertee:
        raise Http404("Page does not exist or you do not have permission to view it.")
    
    if request.method == "POST":
        # erase existing share values
        for item in items:
            itemGroups = ItemGroup.objects.filter(group=group, item=item)
            for itemGroup in itemGroups:
                itemGroup.delete()
        # set ItemGroup for selected items and group 
        itemIds = request.POST.getlist('items[]')
        for itemId in itemIds:
            itemGroup = ItemGroup(item_id=itemId, group=group)
            itemGroup.save()
        action.delete()
        message="Your items have been updated with the selected share settings."
        messages.success(request, message)
        return redirect(reverse('home'))
    # get items shared with group just in case any of these are already shared
    sharedItemIds = ItemGroup.objects.filter(group=group).values_list('item_id', flat=True)
    context = {
        'action' : action,
        'current' : getCurrentUser(request),
        'items' : items,
        'sharedItemIds' : sharedItemIds,
    }
    return render(request, 'sharing/new_group_action.html', context)
Ejemplo n.º 2
0
def edit_sharelist(request, shareListId):
    shareListId = int(shareListId)
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    shareList = ShareList.objects.get(pk=shareListId)
    if request.method == "POST":
        shareListName = request.POST.get('share_list_name')
        shareListMemberIds = request.POST.getlist('participants[]')
        shareList.name = shareListName
        shareList.save()
        shareListSharees = shareList.sharelistsharee_set.all()
        shareListSharees.delete()
        for memberId in shareListMemberIds:
            shareListSharee = ShareListSharee(shareList=shareList, sharee_id=memberId)
            shareListSharee.save()
        messages.success(request, 'Changes to "' + shareList.name + '" have been saved.')
    friends = getRelations(currentParticipant, currentParticipant, [
        RelationshipTypes.FRIENDS,                                         
    ])      
    shareeIds = shareList.sharelistsharee_set.values_list('sharee_id', flat=True)
    context = {
        'current' : getCurrentUser(request),
        'shareList' : shareList,
        'shareeIds' : shareeIds,
        'friends' :  friends,
    }
    return render(request, 'sharing/edit_sharelist.html', context)
Ejemplo n.º 3
0
def post_request_comment(request):
    if request.method == "POST":
        body = request.POST.get("body")
        requestId = request.POST.get("request_id")
        currentParticipant = Participant.objects.get(user=request.user, type='member')
        comment = RequestComment(member=currentParticipant.member, body=body, request_id=requestId)
        comment.save()
        t = threading.Thread(target=email_new_request_comment, args=(request, comment,))
        t.start()
        eventDict = {
            'request_id' : requestId,
            'comment_id' : comment.id,
            'commenter_id' : comment.member.id
        }
        registerEvent('request comment', eventDict)
        context = {
            'current' : getCurrentUser(request),
            'comment' : comment,
            }
        html = render_to_string('requests/blocks/commentblock.html', context)
        data = {
            'request_id' : requestId,
            'html' : html,
        }
        return HttpResponse(json.dumps(data), content_type = "application/json")
    return redirect('login')
Ejemplo n.º 4
0
def items(request):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    filters = {
        'category' : request.GET.get('category'),
        'sharer' : request.GET.get('sharer'),
        'group' : request.GET.get('group'),
        'search_terms' : request.GET.get('search_terms'),
        'search_scope' : ifset(request.GET.get('search_scope'), 'title'),
        'has_image' : request.GET.get('has_image'),
    }
    # print(filters['search_scope'])
    category = request.GET.get('category');
    items = getItemsForParticipant(currentParticipant)
    items = filterItems(
        items,
        category = filters['category'],
        sharerId = filters['sharer'],
        groupId = filters['group'],
        searchTerms = filters['search_terms'], 
        searchScope = filters['search_scope'],
        hasImage = filters['has_image'],      
    )
    context = {
        'current' : getCurrentUser(request),
        'items' : items,
        'friends' :  getReciprocatedFriends(currentParticipant),
        'groups' : getReciprocatedGroups(currentParticipant),
        'categories' : SHARE_CATEGORIES,
        'filters' : filters,
    }
    return render(request, 'sharing/items.html', context)
Ejemplo n.º 5
0
def my_share_lists(request):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    shareLists = ShareList.objects.all().filter(owner=currentParticipant.member)
    context = {
        'current' : getCurrentUser(request),
        'shareLists' : shareLists,
    }
    return render(request, 'sharing/my_share_lists.html', context)
Ejemplo n.º 6
0
def my_items(request):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    items = getItemsSharedByCurrentMember(currentParticipant.member)
    context = {
        'current' : getCurrentUser(request),
        'items' : items,
        'shareCategories' : SHARE_CATEGORIES,
    }
    return render(request, 'sharing/my_items.html', context)
Ejemplo n.º 7
0
def quick_share(request):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    item_lists = getQuickShareItems()
    active_items = Item.objects.filter(sharer=currentParticipant.member)
    active_item_titles = []
    for active_item in active_items:
        active_item_titles.append(active_item.title)
    if request.method == "POST":
        shared_items = []
        removed_items = []
        for item_list in item_lists:
            for category in item_list:
                for item in item_list[category]:
                    title = item_list[category][item]
                    if request.POST.get(item):
                        if not title in active_item_titles:
                            new_item = Item(
                                sharer = currentParticipant.member,
                                share_type = 'all_friends',
                                type = 'stuff',
                                title = title,
                                description = request.POST.get(item + '_description')                
                            )
                            new_item.save()
                            for keyword in getQuickShareKeywords(category, item):
                                itemKeyword = ItemKeyword(item=new_item, keyword=keyword)
                                itemKeyword.save()
                            shared_items.append(title)
                    else:
                        if title in active_item_titles:
                            existing_items = Item.objects.filter(title=title)
                            for existing_item in existing_items:
                                existing_item.delete()
                            removed_items.append(title)
        message = '<strong>The following new items have been shared:</strong> ' + ', '.join(shared_items)
        if removed_items:
            message = message + '<br><br>  <strong>The following existing items have been removed:</strong> ' + ', '.join(removed_items)
        messages.success( request, message)
    
    active_items = Item.objects.filter(sharer=currentParticipant.member)
    active_item_titles = []
    for active_item in active_items:
        active_item_titles.append(active_item.title)
    context = {
        'current' : getCurrentUser(request),
        'item_lists' : item_lists,
        'active_item_titles' : active_item_titles
    }
    return render(request, 'sharing/quick_share.html', context)
Ejemplo n.º 8
0
def request(request, requestId):
    '''Be careful not to overwrite Django 'request' object with something else called request'''
    # check permission to view this request
    user = request.user
    currentParticipant = Participant.objects.get(user=user, type='member')
    singleRequest = getSingleRequest(requestId)['requests']
    rel = getRelationship(currentParticipant, singleRequest[0]['request'].member.participant)
    if rel != RelationshipTypes.FRIENDS and rel != RelationshipTypes.SELF:
        raise Http404("Page does not exist")
    context = {
        'requests' : singleRequest,
        'current' : getCurrentUser(request),
        'expand_comments' : True,
    }
    return render(request, 'requests/request.html', context)
Ejemplo n.º 9
0
def item(request, itemId):
    # verify approval to view item
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    items = getItemsForParticipant(currentParticipant)
    myItems = getItemsSharedByCurrentMember(currentParticipant.member)
    item = Item.objects.get(pk=itemId)
    if not item in items and not item in myItems:
        raise Http404("Item not available")
    context = {
         'current' : getCurrentUser(request),
         'item' : item,      
         'sharer' : getParticipantFull(item.sharer.id, currentParticipant),
         'RelationshipTypes' : RelationshipTypes,
         
    }
    return render(request, 'sharing/item.html', context)
Ejemplo n.º 10
0
def uncomplete_request(request):
    if request.method == "POST":
        url = request.POST.get("redirect")
        requestId = request.POST.get("request_id")
        myrequest = Request.objects.get(id=requestId)
        myrequest.complete = False
        myrequest.save()
        context = {
            'current' : getCurrentUser(request),
            'requests' : getSingleRequest(requestId)['requests']
            }
        html = render_to_string('requests/request_list.html', context)
        data = {
            'request_id' : requestId,
            'html' : html,
        }
        return HttpResponse(json.dumps(data), content_type = "application/json")
Ejemplo n.º 11
0
def edit_request_comment(request):
    if request.method == "POST":
        body = request.POST.get("body")
        commentId = request.POST.get("comment_id")
        comment = RequestComment.objects.get(id=commentId)
        comment.body = body
        comment.save()
        context = {
            'current' : getCurrentUser(request),
            'comment' : comment,
            }
        html = render_to_string('requests/blocks/commentblock.html', context)
        data = {
            'comment_id' : commentId,
            'html' : html,
        }
        return HttpResponse(json.dumps(data), content_type = "application/json")
    return redirect('login')
Ejemplo n.º 12
0
def messages(request, participantId):
    # !!don't create any variables with the name 'messages', especially for the context
    # passed to the template
    # print participantId
    participantId = int(participantId)
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    # post new message
    if request.method == "POST":
        newMessageForm = NewMessageForm(request.POST, participant=currentParticipant)
        if newMessageForm.is_valid():
            message = newMessageForm.save(commit=False)
            message.sender = currentParticipant
            message.save()
            t = threading.Thread(target=email_new_pm, args=(request, message,))
            t.start()
            contrib.messages.success(request, "Message sent to " + message.recipient.get_name() + '.')
            return redirect(reverse("pm:messages", args=[message.recipient.id]))
    participants = getParticipantsWithRecentMessages(currentParticipant)
    if participantId != 0:
        talkingTo = Participant.objects.get(id=participantId)
        messageList = getConversation(talkingTo, currentParticipant)
        messageList.filter(sender=talkingTo).update(viewed=True)
        form = NewMessageForm(participant=currentParticipant, initial={
            'recipient' : talkingTo,
            'body' : request.GET.get('msg')
        })
    else:
        messageList = []
        form = NewMessageForm(participant=currentParticipant)
        talkingTo = None
    context = {
        'messageList' : messageList,
        'conversation' : participantId,
        'participant' : talkingTo,
        'current' : getCurrentUser(request),
        'newMessageForm' : form,
        'participants' : participants,
    }
    return render(request, 'pm/messages.html', context)
Ejemplo n.º 13
0
def request_list(request):
    user = request.user
    currentParticipant = Participant.objects.get(user=user, type='member')
    start = request.GET.get("start")
    end = request.GET.get("end")
    requestList = getRequestList(currentParticipant, start, end)
    requests = requestList['requests']
    totalCount = requestList['total_count']
    if totalCount > int(end):
        moreRequests = True
    else:
        moreRequests = False
    context = {
        'current' : getCurrentUser(request),
        'requests' : requests,
    }
    html = render_to_string('requests/request_list.html', context)
    data = {
        'html' : html,
        'moreRequests' : moreRequests,
        'maxRequest' : end,
    }
    return HttpResponse(json.dumps(data), content_type = "application/json")
Ejemplo n.º 14
0
def edit_item(request, itemId):
    # verify approval to view item
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    item = Item.objects.get(pk=itemId)
    if item.sharer != currentParticipant.member:
        raise Http404("Item not available")
    if request.method == "POST":
        itemForm = ItemForm(request.POST, instance=item, participant=currentParticipant)
        keywordForm = KeywordForm(request.POST)
        if itemForm.is_valid() and keywordForm.is_valid():
            item = itemForm.save(commit=False)
            sharingWith = itemForm.cleaned_data['sharingWith']
            if sharingWith=='all_friends' or sharingWith=='all_friends_groups' or sharingWith=='custom':
                item.share_type = sharingWith
            else:
                item.share_type = 'share_list'
                item.sharelist_id = sharingWith
            item.save()
            ItemKeyword.objects.all().filter(item=item).delete()
            ItemSharee.objects.all().filter(item=item).delete()
            ItemGroup.objects.all().filter(item=item).delete()
            # save keywords
            keywordFieldName = 'keywords_' + item.type
            keywords = keywordForm.cleaned_data[keywordFieldName]
            for keyword in keywords:
                itemKeyword = ItemKeyword(item=item, keyword=keyword)
                itemKeyword.save()
            # save group sharing selections
            groupIds = request.POST.getlist("groups[]")
            for groupId in groupIds:
                record = ItemGroup(item=item, group_id=groupId)
                record.save()
            # save new custom list as share list
            shareListName = itemForm.cleaned_data['shareListName']
            if sharingWith=='custom':
                if itemForm.cleaned_data['createShareList'] == 'yes' and shareListName != '':
                    custom = request.POST.getlist("custom_list[]")
                    shareList = ShareList(name=shareListName, owner=currentParticipant.member)
                    shareList.save()
                    for participantId in custom:
                        record = ShareListSharee(shareList=shareList, sharee_id=int(participantId))
                        record.save()
                    item.share_type = 'share_list'
                    item.sharelist = shareList
                    item.save()
                else:
                    custom = request.POST.getlist("custom_list[]")
                    ItemSharee.objects.all().filter(item=item).delete()
                    for participantId in custom:
                        record = ItemSharee(item=item, sharee_id=int(participantId))
                        record.save()
            messages.success(request,'Your item "' + item.title + '" has been saved')
            return redirect(reverse('sharing:item', args=[itemId]))
    setKeywords = ItemKeyword.objects.all().filter(item=item).values_list('keyword', flat=True)
    itemForm = ItemForm(instance=item, participant=currentParticipant)
    keywordForm = KeywordForm(setKeywords=setKeywords)
    friends = getRelations(currentParticipant, currentParticipant, [
        RelationshipTypes.FRIENDS,
        RelationshipTypes.GUEST_FRIENDS,                                              
    ])   
    groups = getRelations(currentParticipant, currentParticipant, [
        RelationshipTypes.GROUP_OWNER,
        RelationshipTypes.GROUP_MEMBER,                         
    ])   
    sharees = item.itemsharee_set.values_list('sharee_id', flat=True)
    shareeGroups = item.itemgroup_set.values_list('group_id', flat=True)
    shareLists = ShareList.objects.all().filter(owner=currentParticipant.member)
    print(sharees)
    print(shareeGroups)
    context = {
        'current' : getCurrentUser(request),
        'item' : item,  
        'friends' : friends,
        'groups' : groups,  
        'itemForm' : itemForm, 
        'keywordForm' : keywordForm, 
        'itemImage' : item.get_image(),
        'sharees' : sharees,
        'shareeGroups' : shareeGroups,
        'shareLists' : shareLists,
    }
    return render(request, 'sharing/share_item.html', context)
Ejemplo n.º 15
0
def share_item(request):
    currentParticipant = Participant.objects.get(user=request.user, type='member')
    if request.method == "POST":
        itemForm = ItemForm(request.POST, participant=currentParticipant)
        keywordForm = KeywordForm(request.POST)
        if itemForm.is_valid() and keywordForm.is_valid():
            item = itemForm.save(commit=False)
            item.sharer = currentParticipant.member
            sharingWith = itemForm.cleaned_data['sharingWith']
            if sharingWith=='all_friends' or sharingWith=='custom':
                item.share_type = sharingWith
            else:
                item.share_type = 'share_list'
                item.sharelist_id = sharingWith
            item.save()
            # save keywords
            keywordFieldName = 'keywords_' + item.type
            keywords = keywordForm.cleaned_data[keywordFieldName]
            for keyword in keywords:
                itemKeyword = ItemKeyword(item=item, keyword=keyword)
                itemKeyword.save()
            # save group sharing selections
            groupIds = request.POST.getlist("groups[]")
            for groupId in groupIds:
                record = ItemGroup(item=item, group_id=groupId)
                record.save()
            # save new custom list as share list
            shareListName = itemForm.cleaned_data['shareListName']
            if sharingWith=='custom':
                if itemForm.cleaned_data['createShareList'] == 'yes' and shareListName != '':
                    custom = request.POST.getlist("custom_list[]")
                    shareList = ShareList(name=shareListName, owner=currentParticipant.member)
                    shareList.save()
                    for participantId in custom:
                        record = ShareListSharee(shareList=shareList, sharee_id=int(participantId))
                        record.save()
                    item.share_type = 'share_list'
                    item.sharelist = shareList
                    item.save()
                else:
                    custom = request.POST.getlist("custom_list[]")
                    for participantId in custom:
                        record = ItemSharee(item=item, sharee_id=int(participantId))
                        record.save()
            # messages.success(request,'Your item "' + item.title + '" has been saved')
            context = {
                 'item' : item    
            }
            t = threading.Thread(target=email_new_item, args=(request,item,))
            t.start()
            messages.success(request, render_to_string('sharing/blocks/share_confirm.html', context))
            return redirect(reverse('sharing:item', args=[item.id]))
    else:
        itemForm = ItemForm(initial={'type': request.GET.get('type')}, participant=currentParticipant)
        keywordForm = KeywordForm()
    friends = getRelations(currentParticipant, currentParticipant, [
        RelationshipTypes.FRIENDS,
        RelationshipTypes.GUEST_FRIENDS,                                              
    ])   
    groups = getRelations(currentParticipant, currentParticipant, [
        RelationshipTypes.GROUP_OWNER,
        RelationshipTypes.GROUP_MEMBER,                         
    ])     
    context = {
        'current' : getCurrentUser(request),
        'itemForm' : itemForm,
        'friends' : friends,
        'groups' : groups,
        'keywordForm' : keywordForm,
        'itemImage' : '/static/img/generic-item.png',
        'shareLists' : ShareList.objects.all().filter(owner=currentParticipant.member)
    }
    return render(request, 'sharing/share_item.html', context)