def process_final(self): self.object.published_on = datetime.datetime.now() self.object.published_by = self.request.user self.object.save() create_resource_feed(self.object, 'article_published', self.object.created_by) notify_update_article_state(self.request.user, self.object, 'published') return
def process_visible(self): if self.object.mediatype == 'IMAGE': create_resource_feed(self.object, 'image_edit', self.object.created_by) if self.object.mediatype == 'AUDIO': create_resource_feed(self.object, 'audio_edit', self.object.created_by) if self.object.mediatype == 'VIDEO': create_resource_feed(self.object, 'video_edit', self.object.created_by) return
def process_publishable(self): if self.object.mediatype == 'IMAGE': create_resource_feed(self.object, 'image_no_edit', self.request.user) if self.object.mediatype == 'AUDIO': create_resource_feed(self.object, 'audio_no_edit', self.request.user) if self.object.mediatype == 'VIDEO': create_resource_feed(self.object, 'video_no_edit', self.request.user) notify_update_media_state(self.request.user, self.object, 'publishable') return
def process_final(self): self.object.published_on = datetime.datetime.now() self.object.published_by = self.request.user self.object.save() if self.object.mediatype == 'IMAGE': create_resource_feed(self.object, 'image_published', self.object.created_by) notify_update_media_state(self.request.user, self.object, 'published') if self.object.mediatype == 'AUDIO': create_resource_feed(self.object, 'audio_published', self.object.created_by) notify_update_media_state(self.request.user, self.object, 'published') if self.object.mediatype == 'VIDEO': create_resource_feed(self.object, 'video_published', self.object.created_by) notify_update_media_state(self.request.user, self.object, 'published') return
def update_course_info(request, pk): if request.user.is_authenticated: course = Course.objects.get(pk=pk) if course.state == States.objects.get( name='draft') and course.created_by != request.user: return redirect('home') community = CommunityCourses.objects.get(course=pk) uid = request.user.id membership = None comm = Community.objects.get(pk=community.community.id) errormessage = '' try: membership = CommunityMembership.objects.get(user=uid, community=comm.id) if membership: if request.method == 'POST': title = request.POST['name'] body = request.POST['desc'] getstate = request.POST['change_course_state'] state = States.objects.get(name=getstate) course.title = title course.body = body course.state = state try: image = request.FILES['course_image'] course.image = image except: errormessage = 'image not uploaded' course.save() notify_edit_course(request.user, course, 'Course information was updated') if getstate == 'visible': create_resource_feed(course, 'course_edit', request.user) elif getstate == 'publishable': create_resource_feed(course, 'course_no_edit', request.user) notify_update_course_state(request.user, course, 'publishable') elif getstate == 'publish': create_resource_feed(course, 'course_published', request.user) notify_update_course_state(request.user, course, 'publish') return redirect('course_view', pk=pk) else: message = canEditCourse(course.state.name, membership.role.name, course, request) if message != 'True': return render( request, 'error.html', { 'message': message, 'url': 'course_view', 'argument': pk }) return render( request, 'update_course_info.html', { 'course': course, 'membership': membership, 'community': community, 'comm': comm }) else: return redirect('course_view', pk=pk) except CommunityMembership.DoesNotExist: return redirect('login') else: return redirect('login')
def edit_article(request, pk): """ A function to edit an article. The function check whether the method is post, if not it will check if the article belong to group or community and whether the user is a member of that group or cummunity. If the user is not a member, he will not be allowed to edit this article. If the user is a member of the group and not the community than he will not be allowed to edit this article """ if request.user.is_authenticated: if request.method == 'POST': if 'state' in request.POST and request.POST['state'] == 'save': article = Articles.objects.get(pk=pk) article.title = request.POST['title'] article.body = getHTML(article) try: article.image = request.FILES['article_image'] article.save(update_fields=["title", "body", "image"]) except: article.save(update_fields=["title", "body"]) current_state = request.POST['current'] notify_edit_article(request.user, article, current_state) return redirect('article_view', pk=article.pk) else: article = Articles.objects.get(pk=pk) title = request.POST['title'] body = getHTML(article) current_state = request.POST['current'] try: current_state = States.objects.get(name=current_state) if 'private' in request.POST: to_state = States.objects.get(name='private') article.state = to_state #Article got rejected notify_update_article_state(request.user, article, 'rejected') create_resource_feed(article, "article_edit", request.user) else: to_state = request.POST['state'] to_state = States.objects.get(name=to_state) if current_state.name == 'draft' and to_state.name == 'visible' and 'belongs_to' in request.POST: article.state = to_state create_resource_feed(article, 'article_edit', request.user) elif current_state.name == 'visible' and to_state.name == 'publish' and 'belongs_to' in request.POST: article.state = to_state else: transitions = Transitions.objects.get( from_state=current_state, to_state=to_state) article.state = to_state if (to_state.name == 'publishable'): notify_update_article_state( request.user, article, 'publishable') create_resource_feed(article, "article_no_edit", request.user) # sending group feed and personal notificaions when an article goes from draft to private state. if (to_state.name == 'private'): create_resource_feed(article, "article_edit", request.user) notify_update_article_state( request.user, article, 'private') # sending group feed and personal notification to all publishers and admins of group. if (current_state.name == 'private' and to_state.name == 'visible'): create_resource_feed(article, "article_no_edit", request.user) notify_update_article_state( request.user, article, 'visible') article.title = title article.body = body try: article.image = request.FILES['article_image'] article.save( update_fields=["title", "body", "image", "state"]) except: article.save(update_fields=["title", "body", "state"]) except Transitions.DoesNotExist: message = "transition doesn' exist" except States.DoesNotExist: message = "state doesn' exist" if to_state.name == 'publish': article.published_on = datetime.datetime.now() article.published_by = request.user article.save() create_resource_feed(article, 'article_published', article.created_by) notify_update_article_state(request.user, article, 'published') return redirect('article_view', pk=pk) else: message = "" transition = "" cmember = "" gmember = "" private = "" try: # print ("Hello") article = CommunityArticles.objects.get(article=pk) # print ("Hello2") if article.article.state == States.objects.get( name='draft' ) and article.article.created_by != request.user: return redirect('home') if article.article.state == States.objects.get(name='publish'): return redirect('article_view', pk=pk) belongs_to = 'community' # print ("Hello3") try: cmember = CommunityMembership.objects.get( user=request.user.id, community=article.community.pk) sessionid = create_session_community( request, article.community.id) try: transition = Transitions.objects.get( from_state=article.article.state) state1 = States.objects.get(name='draft') state2 = States.objects.get(name='private') if transition.from_state == state1 and transition.to_state == state2: transition.to_state = States.objects.get( name='visible') except Transitions.DoesNotExist: message = "transition doesn't exist" except States.DoesNotExist: message = "state doesn't exist" except CommunityMembership.DoesNotExist: cmember = 'FALSE' except CommunityArticles.DoesNotExist: try: # print ("Hello4") article = GroupArticles.objects.get(article=pk) if article.article.state == States.objects.get( name='publish'): return redirect('article_view', pk=pk) if article.article.state == States.objects.get( name='draft' ) and article.article.created_by != request.user: return redirect('home') belongs_to = 'group' private = '' try: # print ("Hello5") communitygroup = CommunityGroups.objects.get( group=article.group.pk) cmember = CommunityMembership.objects.get( user=request.user.id, community=communitygroup.community.pk) try: gmember = GroupMembership.objects.get( user=request.user.id, group=article.group.pk) sessionid = create_session_group( request, article.group.id) except GroupMembership.DoesNotExist: gmember = 'FALSE' try: transition = Transitions.objects.get( from_state=article.article.state) state1 = States.objects.get(name='visible') state2 = States.objects.get(name='publishable') if transition.from_state == state1 and transition.to_state == state2: transition.to_state = States.objects.get( name='publish') private = States.objects.get(name='private') except Transitions.DoesNotExist: message = "transition doesn't exist" except CommunityMembership.DoesNotExist: message = 'You are not a member of <h3>%s</h3> community. Please subscribe to the community.' % ( communitygroup.community.name) except GroupArticles.DoesNotExist: # print ("Hello6") raise Http404 padid = get_pad_id(article.article.id) response = render( request, 'edit_article.html', { 'article': article, 'cmember': cmember, 'gmember': gmember, 'message': message, 'belongs_to': belongs_to, 'transition': transition, 'private': private, 'url': settings.SERVERURL, 'padid': padid }) response.set_cookie('sessionID', sessionid) return response else: return redirect('login')
def process_publishable(self): notify_update_article_state(self.request.user, self.object, 'publishable') create_resource_feed(self.object, "article_no_edit", self.request.user) return
def process_visible(self): create_resource_feed(self.object, 'article_edit', self.request.user) return