def make_friends(self, user_profile1, user_profile2, source=None): """Save (p1, p2) and (p2, p1) as two complimentary friendships""" if source is None: source = Friendship.DEFAULT_SOURCE friendship1, created = Friendship.objects.get_or_create( user_profile1=user_profile2, user_profile2=user_profile1, defaults={'source':source} ) friendship2, created = Friendship.objects.get_or_create( user_profile1=user_profile1, user_profile2=user_profile2, defaults={'source':source} ) clear_keys('friends', user_profile1.pk) clear_keys('friends', user_profile2.pk) try: PendingFriendship.objects.get(inviter_profile=user_profile1, invitee_profile=user_profile2).delete() except PendingFriendship.DoesNotExist: pass try: PendingFriendship.objects.get(inviter_profile=user_profile2, invitee_profile=user_profile1).delete() except PendingFriendship.DoesNotExist: pass try: Follower.objects.get(followee=user_profile1, follower=user_profile2).delete() except Follower.DoesNotExist: pass try: Follower.objects.get(follower=user_profile1, followee=user_profile2).delete() except Follower.DoesNotExist: pass return friendship2
def save(self, *args, **kwargs): if not self.added_on: self.added_on = datetime.now() self.updated_on = datetime.now() if self.screen_name: self.screen_name_lower = self.screen_name.lower() amqp_headers = kwargs.pop('amqp_headers', None) super(TwitterProfile, self).save(*args, **kwargs) clear_keys(u'twitter_profile', self.user_profile.user.pk) from twitter.amqp.tasks import refresh_friends refresh_friends(self.appuser_id, extra_headers=amqp_headers, access_token=self.access_token)
def add_to_calendar(request, event_id, remove=False, force=False): """Add user to event attendees (or remove them)""" try: user_profile=request.user_profile event = get_object_or_404(Event.objects.active(), pk=event_id) retval = {'success':True, 'do_remove':False} is_ajax = request.is_ajax() if force or (is_ajax and request.method == 'POST') or request.method == 'GET': clear_keys('attendees', event.pk) attending = event.attendee_set.filter(attendee_profile=user_profile).all() for a in attending: ActionItem.objects.q_attendee_action_done(a, 'event-faved') if remove: attending.delete() retval['message'] = is_ajax and _(u'done!') or _(u'Event removed from your favorites') retval['do_remove'] = True retval['link_type'] = 'add' retval['old_link'] = reverse("event_remove_from_calendar", kwargs={"event_id":event.pk}) retval['reverse_link'] = reverse("event_add_to_calendar", kwargs={"event_id":event.pk}) else: if attending.count(): retval['message'] = is_ajax and _(u'done!') or _(u'Event added to your favorites') else: attendee = event.attendee_set.create(attendee_profile=user_profile) retval['message'] = is_ajax and _(u'done!') or _(u'Event added to your favorites') retval['link_type'] = 'remove' retval['old_link'] = reverse("event_add_to_calendar", kwargs={"event_id":event.pk}) retval['reverse_link'] = reverse("event_remove_from_calendar", kwargs={"event_id":event.pk}) if is_ajax: return HttpResponse(json.dumps(retval), mimetype='application/json') if retval.get('message', None): request.user.message_set.create(message=retval['message']) next = request.REQUEST.get('next', event.get_absolute_url()) return HttpResponseRedirect(next) return HttpResponseNotAllowed(permitted_methods=['POST', 'GET']) except Exception, e: _log.exception(e) raise
def save(self, *args, **kwargs): if not self.added_on: self.added_on = datetime.now() self.updated_on = datetime.now() super(BlackList, self).save(*args, **kwargs) clear_keys(u'blacklist', 0)
def save(self, **kwargs): if not self.added_on: self.added_on = datetime.now() super(Follower, self).save(**kwargs) clear_keys('friends', self.user_profile1.pk) clear_keys('friends', self.user_profile2.pk)