Beispiel #1
0
    def _do_robotstxt(self):
        publications = PublicationExtended.objects.all()
        set_robot = {}
        disallow_all = False
        struct_tmp = []
        try:
            public = get_current_publication()
            if public.g11n.disallow_all_robots:
                disallow_all = True
        except:
            pass
        if not disallow_all:
            for pub_extended in publications:
                current_struct = pub_extended.tree_structure
                if current_struct not in struct_tmp:
                    struct_tmp.append(current_struct)
                    nodes = current_struct.tree_root.get_descendants()

                    for node in nodes:
                        if node.page and node.disallow:
                            regex = r'%s' % node.slug

                            for robot in node.robots.all():
                                if robot.name_id in set_robot.keys():
                                    set_robot[robot.name_id].append(regex)
                                else:
                                    set_robot[robot.name_id] = [regex, ]
        tpl_str = render_to_string('robots.tpl.html',
                                   {'set': set_robot, 'disallow_all': disallow_all},
                                   context_instance=RequestContext(self.request))

        return tpl_str
Beispiel #2
0
def favicon(request):
    """
    It returns favicon's location
    """
    favicon = "/upy_static/images/favicon.ico"
    try:
        publication = get_current_publication()
        if publication.favicon:
            favicon = publication.favicon
            if favicon.__class__.__name__ == "FieldFile":
                favicon = favicon.url
        return HttpResponseRedirect(favicon)
    except:
        return HttpResponseRedirect(favicon)
Beispiel #3
0
 def send_confirm_mail(self,request):
     """
     It sends a mail to a contact with confirmation link
     """
     current_publication = get_current_publication()
     try:
         contact = Contact.objects.get(email = request.POST.get("email"))
     except:
         contact = None
     if not contact:
         if self.is_valid():
             try:
                 contact = self.save()
             except:
                 return {"status": False, "error":"contact_save"}
             try:
                 nwl_list = List.objects.get(name = "List %s" % current_publication)
             except:
                 nwl_list = List(name = "List %s" % current_publication, 
                                                   description = "List created on %s" % datetime.now(),
                                                   priority = 1,
                                                   publication = current_publication)
             try:
                 nwl_list.save()
                 nwl_list.contacts.add(contact)
                 nwl_list.save()
             except:
                 result = {"status": False, "error":"list_save"}
             user = "******" % contact
             
             confirm_url = "http://%s/confirm_subscription/%s" % (current_publication.url,contact.secret_key)
             message = render_to_string("send_confirmation.txt.html",{"user": user,
                                                                      "confirm_url":confirm_url,
                                                                      "website": "http://%s" % current_publication.url})
             send_rendered_mail(_(u"Confirm subscription"), message,
                                       "send_confirmation.html", {"user": user,
                                                                  "confirm_url":confirm_url,
                                                                  "website": "http://%s" % current_publication.url}, 
                                       settings.EMAIL_USER,[contact.email])
             result = {"status": True, "error":""}
             return result
         return {"status": False, "error":"form_not_valid"}
     else:
         return {"status": False, "error":"contact_exists"}