def save_related_object(self, related_object, user=None, silent=False): ct = ContentType.objects.get_for_model(related_object) # Adds the object to project obj, created = ProjectRelatedObject.objects.get_or_create( content_type_id=ct.id, object_id=related_object.id, project_id=self.id) if user: # Adds user as contributor self.contributors.add(user) # Creates update entry if created and not silent: from update.models import Update from update.signals import create_update create_update.send(sender=obj.__class__, user=user, instance=obj, type=Update.EDIT) return created
def comments_add(request): logger.debug('POST={}'.format(request.POST)) form_comment = FormComment(request.POST) if form_comment.is_valid(): comment = form_comment.save(user=request.user) create_update.send(sender=Comment, instance=comment, user=request.user, type=Update.DISCUSSION) return { 'success': True, 'comment': render_to_response('comments/comment.html', dict(comment=comment, comment_class=''), context_instance=RequestContext(request)).content } else: logger.debug(_('invalid form: {}'.format(form_comment.errors))) return {'success': False, 'errors': form_comment.errors}
def insert_all(self): if self.inserted: success = True return success success = True for wks in self.worksheets: success = success and self.insert(wks.title) if success: # just inserted all objects for u in self.mappers: from update.models import Update from update.signals import create_update create_update.send(sender=Importsheet, user=u, instance=self, type=Update.INSERT) return success
def save(self, *args, **kwargs): from update.models import Update from update.signals import create_update obj = super(AjaxModelForm, self).save(*args, **kwargs) if (not self.cleaned_data['id']): update_type = Update.ADD if self.user and hasattr(obj, 'creator'): obj.creator_id = self.user.id else: update_type = Update.EDIT if self.user and hasattr(obj, 'last_editor'): obj.last_editor_id = self.user.id obj.save() create_update.send(sender=obj.__class__, user=self.user, instance=obj, type=update_type) return obj
def comments_add(request): logger.debug('POST={}'.format(request.POST)) form_comment = FormComment(request.POST) if form_comment.is_valid(): comment = form_comment.save(user=request.user) create_update.send(sender=Comment, instance=comment, user=request.user, type=Update.DISCUSSION) return { 'success': True, 'comment': render_to_response( 'comments/comment.html', dict(comment=comment, comment_class=''), context_instance=RequestContext(request)).content } else: logger.debug(_('invalid form: {}'.format(form_comment.errors))) return {'success': False, 'errors': form_comment.errors}
def add_related_object(request): ct = request.POST.get('content_type', '') obj_id = request.POST.get('object_id', '') proj_id = request.POST.get('project_id', '') proj = get_object_or_404(Project, pk=proj_id) if proj and obj_id and ct: obj, created = ProjectRelatedObject.objects.get_or_create( content_type_id=ct, object_id=obj_id, project_id=proj_id) if created: from update.models import Update from update.signals import create_update create_update.send(sender=obj.__class__, user=request.user, instance=obj, type=Update.EDIT) return {'success': True, 'project': { 'id': proj.id, 'name': proj.name, 'link': proj.view_url }} else: return {'success': False}