Exemple #1
0
 def add_participant(self, uid):
     if uid == self.owner_id or uid in self.participants:
         return False
     self.participants.append(uid)
     self.save(update_fields=['participants'])
     participant_modified.send(
         sender=self,
         participant=self.owner._default_manager.get(pk=uid),
         add=True)
     return True
Exemple #2
0
 def to_internal_value(self, participants):
     logger.info('User(%s) subscribes a remind(%s)',
                 self.parent.context['request'].user.nickname,
                 unicode(self.parent.instance))
     participant_modified.send(
         sender=self.parent.instance,
         participant=self.parent.context['request'].user,
         add=True)
     return list(
         set(p['id'] for p in participants if UserModel.objects.filter(
             pk=p['id'], subscribe=True).first()))
Exemple #3
0
 def perform_destroy(self, instance):
     user = self.request.user
     if instance.owner_id == user.pk:
         instance.delete()
         logger.info('User(%s) deletes a remind(%s)', user.nickname,
                     unicode(instance))
     elif user.pk in instance.participants:
         instance.participants.remove(self.request.user.pk)
         instance.save(update_fields=['participants'])
         logger.info('User(%s) quites a remind(%s)', user.nickname,
                     unicode(instance))
         participant_modified.send(sender=instance,
                                   participant=user,
                                   add=False)
     else:
         self.permission_denied(self.request, message=u'Unauthorized!')