Пример #1
0
    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        #OwnableAdmin.save_form(self, request, form, change)
        if change == False:
            obj = form.save(commit=False)
            if obj.user_id is None:
                obj.user = request.user
            DisplayableAdmin.save_form(self, request, form, change)
        else:
            DisplayableAdmin.save_form(self, request, form, change)

        return DisplayableAdmin.save_form(self, request, form, change)
Пример #2
0
    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        #OwnableAdmin.save_form(self, request, form, change)
        if change==False:
            obj = form.save(commit=False)
            if obj.user_id is None:
                obj.user = request.user 
            DisplayableAdmin.save_form(self, request, form, change)
        else: 
            DisplayableAdmin.save_form(self, request, form, change)

        return DisplayableAdmin.save_form(self, request, form, change)
Пример #3
0
    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        #OwnableAdmin.save_form(self, request, form, change)
        #changed to made all secretariat editor of forum posts
        if change == False:
            obj = form.save(commit=False)
            if obj.user_id is None:
                obj.user = request.user
            DisplayableAdmin.save_form(self, request, form, change)
        else:
            DisplayableAdmin.save_form(self, request, form, change)

        #new forum post send notifications
        if change == False:
            emailto_all = []
            for g in request.POST.getlist('notification_groups'):
                group = Group.objects.get(id=g)
                users = group.user_set.all()
                for u in users:
                    user_obj = User.objects.get(username=u)
                    user_email = user_obj.email
                    print(user_email)
                    emailto_all.append(str(user_email))

            category = get_object_or_404(ForumCategory,
                                         id=request.POST['categories']).title
            #if(category == 'TPDP Forum'):
            #print('no notifification')
            #else:
            subject = 'IPPC FORUM: ' + category + ' - new discussion: ' + request.POST[
                'title']
            #markdowner = Markdown()
            bodycontent = markdown.markdown(request.POST['content'])

            text = '<html><body><p>Dear IPPC user,</p><p>a new discussion has been posted in the ' + category + ' Forum.</p><p><b>Discussion:</b>' + request.POST[
                'title'] + '</p><p><b>Post:</b></p><p>' + bodycontent + '</p><p>You can view it at the following url: https://www.ippc.int/forum/' + slugify(
                    request.POST['title']
                ) + '</p><p>-- International Plant Protection Convention team </p></body></html>'

            notifificationmessage = mail.EmailMessage(
                subject, text, '*****@*****.**', emailto_all,
                ['*****@*****.**'])
            notifificationmessage.content_subtype = "html"
            #paola sent =notifificationmessage.send()

        return DisplayableAdmin.save_form(self, request, form, change)
Пример #4
0
 def save_form(self, request, form, change):
     """
     Super class ordering is important here - user must get saved first.
     """
     # OwnableAdmin.save_form(self, request, form, change)
     # NOTE: ownable automatically sets owner to current user, not
     # sure that behavior makes sense for us
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #5
0
    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        #OwnableAdmin.save_form(self, request, form, change)
        #changed to made all secretariat editor of forum posts
        if change==False:
            obj = form.save(commit=False)
            if obj.user_id is None:
                obj.user = request.user 
            DisplayableAdmin.save_form(self, request, form, change)
        else: 
            DisplayableAdmin.save_form(self, request, form, change)
      
        #new forum post send notifications
        if change==False:
            emailto_all = []
            for g in request.POST.getlist('notification_groups'):
                group=Group.objects.get(id=g)
                users = group.user_set.all()
                for u in users:
                   user_obj=User.objects.get(username=u)
                   user_email=user_obj.email
                   print(user_email)   
                   emailto_all.append(str(user_email))
            
            category=get_object_or_404(ForumCategory, id=request.POST['categories']).title 
            #if(category == 'TPDP Forum'):
                #print('no notifification')
            #else:    
            subject='IPPC FORUM: '+category+' - new discussion: '+request.POST['title']       
            #markdowner = Markdown()

            bodycontent = markdown.markdown(request.POST['content'])


            text='<html><body><p>Dear IPPC user,</p><p>a new discussion has been posted in the '+category+' Forum.</p><p><b>Discussion:</b>'+ request.POST['title']+'</p><p><b>Post:</b></p><p>'+bodycontent+'</p><p>You can view it at the following url: https://www.ippc.int/forum/'+slugify(request.POST['title'])+'</p><p>-- International Plant Protection Convention team </p></body></html>'
            
            notifificationmessage = mail.EmailMessage(subject,text,'*****@*****.**',  emailto_all, ['*****@*****.**'])
            notifificationmessage.content_subtype = "html"  
            sent =notifificationmessage.send()
        return DisplayableAdmin.save_form(self, request, form, change)
Пример #6
0
    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        if not request.user.groups.all().filter(name="StoreOwners").count() and not request.user.is_superuser:
            raise ValidationError(_("Unauthorized operation!!"))

        if not change and not request.user.is_superuser:
            blog_posts = BlogPost.objects.published(for_user=request.user).select_related().filter(user=request.user)
            if blog_posts and blog_posts[0]:
                raise ValidationError(_("'%s' has already registered a vendor page" % request.user))

        OwnableAdmin.save_form(self, request, form, change)
        return DisplayableAdmin.save_form(self, request, form, change)
Пример #7
0
 def save_form(self, request, form, change):
     """
     Super class ordering is important here - user must get saved first.
     """
     OwnableAdmin.save_form(self, request, form, change)
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #8
0
 def save_form(self, request, form, change):
     """
     Super class ordering is important here - user must get saved first.
     """
     OwnableAdmin.save_form(self, request, form, change)
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #9
0
 def save_form(self, request, form, change):
     OwnableAdmin.save_form(self, request, form, change)
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #10
0
 def save_form(self, request, form, change):
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #11
0
 def save_form(self, request, form, change):
     """
     Super class ordering is important here - user must get saved first.
     """
     #OwnableAdmin.save_form(self, request, form, change)
     send=False
     
     news_slug=''
     if change==True:
       if request.POST['slug'] != None:
         news_slug=request.POST['slug']
         n_obj=get_object_or_404(NewsPost,slug=request.POST['slug']) 
         if n_obj.status == 1 and request.POST['status']=='2':
            send=True
         
     if change==False:
         slug1=slugify(request.POST['title'])
         alreadynews = NewsPost.objects.filter(slug__icontains=slug1)
         if alreadynews.count()>0:
             print(alreadynews[0].slug)
             old2slug=alreadynews[0].slug
             intslug=old2slug.replace(slug1+"-","")
             intslug1=int(intslug)+1
             
             print(intslug1)
             news_slug=slug1+"-"+str(intslug1)
             # print(news_slug)
             #slug = alreadynews[0].slug 
         else:
             news_slug= slug1
        
         obj = form.save(commit=False)
        
         
         if obj.user_id is None:
             obj.user = request.user 
             obj.slug = news_slug 
         DisplayableAdmin.save_form(self, request, form, change)
     else: 
         DisplayableAdmin.save_form(self, request, form, change)
     
         
     if change==False and request.POST['status'] == '2'  :
         send=True
         
     #new news post send notifications to Secretariat
     if send==True  :
         emailto_all = []
         group=Group.objects.get(name="News Notification group")
         users = group.user_set.all()
         for u in users:
            user_obj=User.objects.get(username=u)
            user_email=user_obj.email
            emailto_all.append(str(user_email))
            #print(user_email)
         category=None
         try:
             category=get_object_or_404(NewsCategory, id=request.POST['categories']).title 
         except:
             print("###################error in category ")
             
                 
         
         if(category!=None and (category == 'Announcements' or category == 'IPPC news' )):
             pdate= request.POST['publish_date_0']
             d = datetime.strptime(pdate, '%Y-%m-%d')
             day_string = d.strftime('%d-%m-%Y')
             subject=''
             text=''
            #subject='IPPC News: a new '+category+' has been posted'      
       
             if  category == 'IPPC news':
                 subject='IPPC News has been posted'     
                 text='<html><body><p>Dear IPPC User,</p><p>a new IPPC News has been posted on the International Phytosanitary Portal (IPP):<br><br> <b>'+ request.POST['title']+'</b></p><p>You can view it from '+day_string+' at the following url: <a href="http://www.ippc.int/news/'+news_slug+'">https://www.ippc.int/news/'+news_slug+'</a></p><p><br>Kind regards,<br><br>The International Plant Protection Convention Secretariat</p></body></html>'
             elif  category == 'Announcements':
                 subject='IPPC announcement has been posted'   
                 text='<html><body><p>Dear IPPC User,</p><p>a new IPPC announcement has been posted on the International Phytosanitary Portal (IPP):<br><br> <b>'+ request.POST['title']+'</b></p><p>You can view it from '+day_string+' at the following url: <a href="http://www.ippc.int/news/'+news_slug+'">https://www.ippc.int/news/'+news_slug+'</a></p><p><br>Kind regards,<br><br>The International Plant Protection Convention Secretariat</p></body></html>'
             
          
             
             notifificationmessage = mail.EmailMessage(subject,text,'*****@*****.**',  emailto_all, ['*****@*****.**'])
             notifificationmessage.content_subtype = "html"  
             sent =notifificationmessage.send()
     
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #12
0
 def save_form(self, request, form, change):
     """
     Super class ordering is important here - user must get saved first.
     """
     #OwnableAdmin.save_form(self, request, form, change)
     send=False
     
     news_slug=''
     if change==True:
       if request.POST['slug'] != None:
         news_slug=request.POST['slug']
         n_obj=get_object_or_404(NewsPost,slug=request.POST['slug']) 
         if n_obj.status == 1 and request.POST['status']=='2':
            send=True
         
     if change==False:
         slug1=slugify(request.POST['title'])
         alreadynews = NewsPost.objects.filter(slug__icontains=slug1)
         if alreadynews.count()>0:
             old2slug=alreadynews[0].slug
             intslug=old2slug.replace(slug1+"-","")
             intslug1=int(intslug)+1
             news_slug=slug1+"-"+str(intslug1)
         else:
             news_slug= slug1
        
         obj = form.save(commit=False)
        
         if obj.user_id is None:
             obj.user = request.user 
             obj.slug = news_slug 
         DisplayableAdmin.save_form(self, request, form, change)
     else: 
         DisplayableAdmin.save_form(self, request, form, change)
     
         
     if change==False and request.POST['status'] == '2'  :
         send=True
         
     #new news post send notifications to Secretariat
     if send==True  :
         emailto_all = []
         emailto_all_news = []
         emailto_all_announc = []
         
         group=Group.objects.get(name="News Notification group")
         users = group.user_set.all()
         for u in users:
            user_obj=User.objects.get(username=u)
            user_email=user_obj.email
            emailto_all_news.append(str(user_email))
         group2=Group.objects.get(name="Announcement Notification group")
         users2 = group2.user_set.all()
         for u in users2:
            user_obj=User.objects.get(username=u)
            user_email=user_obj.email
            emailto_all_announc.append(str(user_email))
         category=None
         try:
             category=get_object_or_404(NewsCategory, id=request.POST['categories']).title 
         except:
             print("###################error in category ")
         
         if(category!=None and (category == 'Announcements' or category == 'IPPC news' )):
             pdate= request.POST['publish_date_0']
             d = datetime.strptime(pdate, '%Y-%m-%d')
             day_string = d.strftime('%d-%m-%Y')
             subject=''
             text=''
             if  category == 'IPPC news':
                 subject='IPPC News has been posted'   
                 emailto_all=emailto_all_news
                 text='<html><body><p>Dear IPPC User,</p><p>a new IPPC News has been posted on the International Phytosanitary Portal (IPP):<br><br> <b>'+ request.POST['title']+'</b></p><p>You can view it from '+day_string+' at the following url: <a href="http://www.ippc.int/news/'+news_slug+'">https://www.ippc.int/news/'+news_slug+'</a></p><p><br>Kind regards,<br><br>The International Plant Protection Convention Secretariat</p><p><br><br>If you want to <b>un-subscribe</b> from the News notifications <b>login to IPP</b>, then go <a href="http://www.ippc.int/news/category/ippcnews/"><b>here</b></a> and click on the button <b>un-subscribe</b>.</p></body></html>'
             elif  category == 'Announcements':
                 subject='IPPC announcement has been posted'
                 emailto_all=emailto_all_announc
                 text='<html><body><p>Dear IPPC User,</p><p>a new IPPC announcement has been posted on the International Phytosanitary Portal (IPP):<br><br> <b>'+ request.POST['title']+'</b></p><p>You can view it from '+day_string+' at the following url: <a href="http://www.ippc.int/news/'+news_slug+'">https://www.ippc.int/news/'+news_slug+'</a></p><p><br>Kind regards,<br><br>The International Plant Protection Convention Secretariat</p><p><br><br>If you want to <b>un-subscribe</b> from the Announcements notifications <b>login to IPP</b>, then go <a href="http://www.ippc.int/news/category/announcements/"><b>here</b></a> and click on the button <b>un-subscribe</b>.</p></body></html>'
             
             emailto_all_final=''
             for eee in emailto_all:
                 emailto_all_final=emailto_all_final+eee+','
             
             author = get_object_or_404(User, pk=1652)    
             ############################################
             massemail = MassEmailUtilityMessage()
             massemail.emailfrom = '*****@*****.**'
             massemail.emailto = emailto_all_final
             massemail.emailtoISO3 = ''
             massemail.emailcc = ''
             massemail.subject = subject
             massemail.messagebody = text
             massemail.date = datetime.now()
             massemail.sent = 0
             massemail.status = 1
             massemail.not_sentto = emailto_all_final
             massemail.sentto =  ''
             massemail.not_senttoISO3 = ''
             massemail.senttoISO3 = ''
             massemail.author= author
             massemail.massmerge = 0
             
             massemail.save()
         
             subnew='MASS EMAIL STORED:'+subject
           
             notifificationmessage = mail.EmailMessage(subnew,text,'*****@*****.**',  ['*****@*****.**'], ['*****@*****.**'])
             notifificationmessage.content_subtype = "html"  
             # sent =notifificationmessage.send()
 
             #######################################
             #notifificationmessage = mail.EmailMessage(subject,text,'*****@*****.**',  emailto_all, ['*****@*****.**'])
             #notifificationmessage.content_subtype = "html"  
             #sent =notifificationmessage.send()
     
     return DisplayableAdmin.save_form(self, request, form, change)
Пример #13
0
 def changelist_view(self, request, **kwargs):
     kwargs.setdefault('extra_context', {})
     kwargs['extra_context']['page_models'] = \
         self.get_content_models()
     return DisplayableAdmin.changelist_view(self, request,
                                             **kwargs)