示例#1
0
def save_event(request):
    """Saves event to profile for later access.
    
    Creates a message object that is sent to the user about the event.
    
    Args:
        request: Django's HttpRequest object that contains metadata.
            https://docs.djangoproject.com/en/dev/ref/request-response/
    
    Returns:
        IF REQUEST IS POST:
        HttpResponseRedirect to /events/msg/
        ELSE:
        event/message_send.html with template_vars
    
    Raises:
        None.
    """
    template_var = base_template_vals(request)
    template_var["allusers"] = UserProfile.objects.all()    
    if request.method == "POST":
        if request.user.is_authenticated():
            message = Message()
            message.msg_from = UserProfile.objects.filter(
                               django_user=request.user)[0]
            message.msg_to = UserProfile.objects.filter(
                             id__exact=request.POST["msg_to_django_user_id"])[0]
            message.content = request.POST["content"]
            message.save()
        return HttpResponseRedirect("/events/msg/")
        
    return render_to_response("event/message_send.html", template_var, 
                              context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: karuto/usfevent
def sys_notification(target, types, from_user, event_id):
    """Collects / sends message for 'followed' and 'commented' notification.
    
    Set's that the user who sent the message is the 'Admin', creates 
    appropriate message based on notification type, and then saves the message.
    
    Args:
        target: User that message is being sent to.
        types: Type of message that is being sent.
        from_user: User that sent the message.
        event_id: ? ? ? #TODO: Bin decide if you're gonna use 'event_id' or not.
        
    Returns:
        None.
    
    Raises:
        None.
    """
    
    msg_from = UserProfile.objects.get(
               django_user=User.objects.get(username__exact='admin'))  
               #admin userprofile #TODO: F*****G HARDCODE, BUT NO BETTER WAY?!

    message = Message()
    message.msg_from = msg_from
    message.msg_to = target

    print "prepare to send"

    if (types == "followed"):
        message.title = str(from_user.django_user) + " followed you."
        message.content = str(from_user.django_user) + " followed you."
        print "send"
    elif(types == "add_comment"):
        message.title = str(from_user.django_user) + " comments on your event."
        message.content = str(from_user.django_user) + " comments on your event." + "<a href='/events/"+ event_id+"'>link</a>"
    elif(types == "save_event"):
        message.title = "The event saved successfully. "
        message.content = "The event saved successfully. " + "<a href='/events/"+ event_id+"'>link</a>"
    elif(types == "approve_event"):
        message.title = "The event has been approved."
        message.content = "The event has been approved. " + "<a href='/events/"+ event_id+"'>link</a>"
    elif(types == "approve_user"):
        message.title = "You have been promoted. "
        message.content = "You have been promoted. "
    

    else:
        message.title = "Unknown System Notification."
        message.content = "Unknown System Notification."    
    message.save()
示例#3
0
def msg_send(request):
    """Sends message from one user to another.
    
    Fills template vars and creates and saves message object. 
    
    Args:
        request: Django's HttpRequest object that contains metadata.
            https://docs.djangoproject.com/en/dev/ref/request-response/
    
    Returns:
        IF MESSAGE SEND SUCCESSFUL:
        HttpResponseRedirect to /events/msg/
        ELSE:
        event/message_send.html with template_vars
        
    Raises:
        None.
    """
    template_var = base_template_vals(request)
    template_var["allusers"] = UserProfile.objects.all()
    current_django_user = UserProfile.objects.filter(
                          django_user=request.user)[0]
    template_var["msg_sent_list"] = Message.objects.filter(
                                    msg_from=current_django_user)
    template_var["msg_received_list"] = Message.objects.filter(
                                        msg_to=current_django_user)
    
    if request.method == "POST":
        if request.user.is_authenticated():
            message = Message()
            message.msg_from = UserProfile.objects.filter(
                               django_user=request.user)[0]
            message.msg_to = UserProfile.objects.filter(
                             id__exact=request.POST["msg_to_django_user_id"])[0]
            message.content = request.POST["content"]
            message.save()    

        return HttpResponseRedirect("/events/msg/")
        
    return render_to_response("event/message_send.html", template_var,
                              context_instance=RequestContext(request))