Пример #1
0
def sendnotification(request):
    """
	Send notification to followers of event
	====Input=======
	email
	event_id
	message
	=====output=======
	success 
	sometimes message 
	"""
    response = {}
    response['success'] = 0
    if request.method == 'POST':
        email = request.POST['email']
        event_id = request.POST['event_id']
        message = request.POST['message']
        user = User.objects.get(username=email)
        if user.is_active and user.is_staff:
            event = Event.objects.get(id=event_id)
            if event.addedby == user:
                ids = UserEvents.objects.values_list(
                    'user__userprofile__mobile_id',
                    flat=True).filter(event=event)
                if len(ids) > 0:
                    notification.send_notification_custom(event, ids, message)
                response['success'] = 1
            else:
                response['message'] = "Not an event of the user"
        else:
            response['message'] = "Not a super user"
    return JsonResponse(response)
Пример #2
0
	def save_model(self, request, obj, form, change):
		if getattr(obj, 'addedby', None) is None:
			print "None"
			obj.addedby = request.user
			obj.save()
		if obj.event.name == 'all':
			users = UserProfile.objects.values_list('mobile_id',flat=True)
		else:
			users = UserEvents.objects.values_list('user__userprofile__mobile_id', flat=True).filter(event = obj.event)
		print "list is------------------------ ",users
		ids = users
			# ids = ["APA91bGzrX6HEgdPg4XCI-30TE9gTg9YeUFayr7xb8KDDl6WbyzXBJhfNIzeadptI_pjcfRTMVpjdAVZraHIC9m6t_-9o6lEPp-hb13RyBBtN5MJmNzk-6bAme8OHI0TcTFH4yRu4nhD"]
		if len(ids) > 0:
			notification.send_notification_custom(obj.event,ids,obj.message)
		return super(NotificationAdmin, self).save_model(request, obj, form, change)
Пример #3
0
 def save_model(self, request, obj, form, change):
     if getattr(obj, 'addedby', None) is None:
         print "None"
         obj.addedby = request.user
         obj.save()
     clubc = obj.event.club
     print "club is -> ", clubc
     ids = UserFollow.objects.values_list('user__userprofile__mobile_id',
                                          flat=True).filter(club=clubc)
     if len(ids) > 0:
         print 'follow list is', ids
         message = "A new event '" + obj.event.name + "' has been added by " + clubc.name + ". Check it out!"
         # custom notification for those users who are following the club
         notification.send_notification_custom(obj.event, ids, message)
     image_url = settings.BASE_URL + obj.image.url
     ids = UserProfile.objects.values_list('mobile_id', flat=True)
     # sending the event details via notification to all the users
     # notification.send_event(obj.event, image_url, ids)
     return super(ContentAdmin, self).save_model(request, obj, form, change)
Пример #4
0
	def save_model(self, request, obj, form, change):
		notification.send_notification_custom(obj.event,["APA91bFWMbep-aUAoZoNnYoygmGFbm0Bvhj9O-6qO83lDbHSEiSYNchWQl-rlo0Ho8MKJriracata6si-pUKlZR-QyzI_uvNzEujqD9IshuG4UlhUXGquBK-SDNr3p5TcCMGTZrxVKQQccY4KvFzmDRnACY5ustNLw"],"New event "+obj.event.name +" by " + obj.event.club.name)
		if getattr(obj, 'addedby', None) is None:
			print "None"
			obj.addedby = request.user
			obj.save()
		clubc=obj.event.club
		print "club is -> ",clubc
		ids = UserFollow.objects.values_list('user__userprofile__mobile_id', flat=True).filter(club = clubc)
		if len(ids) > 0:
			print 'follow list is', ids
			message="A new event '"+obj.event.name+"' has been added by "+clubc.name+". Check it out!"
			# custom notification for those users who are following the club
			notification.send_notification_custom(obj.event,ids,message)
		image_url = settings.BASE_URL+obj.image.url
		ids=UserProfile.objects.values_list('mobile_id',flat=True)
		# sending the event details via notification to all the users
		# notification.send_event(obj.event, image_url, ids)
		return super(ContentAdmin, self).save_model(request, obj, form, change)
Пример #5
0
def addevent(request):
    """
	Add an event if the user is admin
	=======input===========
	name
	type
	subtype
	club
	date_time
	contact_name_1
	contact_name_2
	contact_number_1
	contact_number_2
	venue
	photo -> It is an image that is sent here
	description

	====Output==========
	success 0 or 1
	message -> for toast

	"""
    response = {}
    response['success'] = 0
    if request.method == 'POST':
        email = request.POST['email']
        user = User.objects.get(username=email)
        if user.is_active and user.is_staff:
            event_name = request.POST['name']
            event_type = request.POST['type']
            event_subtype = request.POST['subtype']
            event_club_name = request.POST['club']
            event_club = Club.objects.get(name=event_club_name)
            event_date_time = request.POST['date_time']
            event_contact_name_1 = request.POST['contact_name_1']
            event_contact_name_2 = request.POST['contact_name_2']
            event_contact_number_1 = request.POST['contact_number_1']
            event_contact_number_2 = request.POST['contact_number_2']
            event_venue = request.POST['venue']
            event_alias = event_name + event_date_time.replace(
                ' ', '') + event_venue
            event_addedby = user
            event = Event(name=event_name,
                          type=event_type,
                          subtype=event_subtype,
                          club=event_club,
                          date_time=event_date_time,
                          contact_name_1=event_contact_name_1,
                          contact_number_1=event_contact_number_1,
                          contact_name_2=event_contact_name_2,
                          contact_number_2=event_contact_number_2,
                          venue=event_venue,
                          alias=event_alias,
                          addedby=event_addedby)
            event.save()
            event_image = request.FILES['photo']
            event_description = request.POST['description']
            event_desp = Content(event=event,
                                 image=event_image,
                                 description=event_description,
                                 addedby=event_addedby)
            event_desp.save()
            #Sending notification about the new event
            clubc = event.club
            ids = UserFollow.objects.values_list(
                'user__userprofile__mobile_id', flat=True).filter(club=clubc)
            if len(ids) > 0:
                message = "A new event '" + event.name + "' has been added by " + clubc.name + ". Check it out!"
                notification.send_notification_custom(event, ids, message)
            response['message'] = "Event " + event_name + " has been added"
            response['success'] = 1
        else:
            response['message'] = "User is not an admin. Cannot add the event"
            response['success'] = 0
    else:
        response['message'] = "Sorry wrong place"
    return JsonResponse(response)