示例#1
0
    def post(self, request, *args, **kwargs):
        """HTTP POST: handle form"""

        form_class = self.get_form_class()

        form = form_class(request.POST, request.FILES, **self.get_form_kwargs())
        if form.is_valid():
            contact = form.save(request)
            try:
                send_verification_email(contact)
                return HttpResponseRedirect(self.get_success_url(contact))
            except EmailSendError:
                except_text = 'send_verification_email'
                logger.exception(except_text)
                
                #create action
                detail = _(u"An error occurred while verifying the email address of this contact.")
                fix_action = ActionType.objects.get_or_create(name=_(u'Balafon'))[0]
                action = Action.objects.create(
                    subject=_(u"Need to verify the email address"), planned_date=now_rounded(),
                    type=fix_action, detail=detail, display_on_board=True,
                )
                action.contacts.add(contact)
                action.save()
                
                return HttpResponseRedirect(self.get_error_url(contact))
        else:
            except_text = u'contact form : {0}'.format(form.errors)
            logger.warning(except_text)
        return self._display_form(form)
示例#2
0
文件: views.py 项目: ljean/balafon
    def post(self, request, *args, **kwargs):
        """HTTP POST: handle form"""

        form_class = self.get_form_class()

        form = form_class(request.POST, request.FILES,
                          **self.get_form_kwargs())
        if form.is_valid():
            contact = form.save(request)
            if self.require_confirmation():
                contact.confirmed = False
                contact.save()
                entity = contact.entity
                entity.confirmed = False
                entity.save()
            try:
                subscription_queryset = contact.subscription_set.filter(
                    accept_subscription=True)

                subscription_types = []
                for subscription in subscription_queryset:
                    new_subscription.send(sender=Subscription,
                                          instance=subscription,
                                          contact=contact)
                    subscription_types.append(subscription.subscription_type)

                send_verification_email(contact, subscription_types)
                return HttpResponseRedirect(self.get_success_url(contact))
            except EmailSendError:
                except_text = 'send_verification_email'
                logger.exception(except_text)

                # create action
                detail = _(
                    "An error occurred while verifying the email address of this contact."
                )
                fix_action = ActionType.objects.get_or_create(
                    name=_('Balafon'))[0]
                action = Action.objects.create(
                    subject=_("Need to verify the email address"),
                    planned_date=now_rounded(),
                    type=fix_action,
                    detail=detail,
                    display_on_board=True,
                )
                action.contacts.add(contact)
                action.save()

                return HttpResponseRedirect(self.get_error_url(contact))
        else:
            except_text = 'contact form : {0}'.format(form.errors)
            logger.warning(except_text)
        return self._display_form(form)
示例#3
0
def patch_emailing_html(html_text, emailing, contact):
    """transform links into magic link"""
    links = re.findall('href="(?P<url>.+?)"', html_text)

    ignore_links = [
        reverse("emailing_unregister", args=[emailing.id, contact.uuid]),
        reverse("emailing_view_online", args=[emailing.id, contact.uuid]),
    ]
    ignore_prefixes = ['mailto:', 'tel:']

    for lang_tuple in settings.LANGUAGES:
        ignore_links.append(
            reverse("emailing_view_online_lang",
                    args=[emailing.id, contact.uuid, lang_tuple[0]]))

    for link in links:
        ignore_link = False
        for prefix in ignore_prefixes:
            if link.lower().startswith(prefix):
                ignore_link = True
                break

        if (not ignore_link) and (link[0] != "#") and link not in ignore_links:
            # mailto, internal links, 'unregister' and 'view online' are not magic
            if len(link) < 500:

                magic_links = MagicLink.objects.filter(emailing=emailing,
                                                       url=link)
                if magic_links.count() == 0:
                    magic_link = MagicLink.objects.create(emailing=emailing,
                                                          url=link)
                else:
                    magic_link = magic_links[0]

                view_magic_link_url = reverse(
                    'emailing_view_link', args=[magic_link.uuid, contact.uuid])
                magic_url = emailing.newsletter.get_site_prefix(
                ) + view_magic_link_url
                html_text = html_text.replace('href="{0}"'.format(link),
                                              'href="{0}"'.format(magic_url))
            else:
                if 'test' not in sys.argv:
                    logger.warning(
                        "magic link size is greater than 500 ({0}) : {1}".
                        format(len(link), link))
    return html_text
示例#4
0
 def get_object(self):
     """get action"""
     action = get_object_or_404(models.Action, pk=self.kwargs['pk'])
     try:
         return action.actiondocument
     except self.model.DoesNotExist:
         warning_text = ""
         if not action.type:
             warning_text = _(u"The action has no type set: Unable to create the corresponding document")
         elif not action.type.default_template:
             warning_text = _(
                 u"The action type has no document template defined: Unable to create the corresponding document"
             )
         if warning_text:
             logger.warning(warning_text)
             user_message.warning(self.request, warning_text)
             raise Http404
         else:
             return self.model.objects.create(action=action, template=action.type.default_template)
示例#5
0
文件: utils.py 项目: ljean/balafon
def resolve_city(city_name, zip_code, country='', default_department=''):
    """get a city form a name and zip code"""
    country = country.strip()
    city_name = format_city_name(city_name)
    default_country = crm_settings.get_default_country()
    foreign_city = bool(country) and (country != default_country)
    if foreign_city:
        zone_type = models.ZoneType.objects.get(type='country')
        queryset = models.Zone.objects.filter(type=zone_type)
        queryset = filter_icontains_unaccent(queryset, '"Crm_zone"."name"',
                                             country)
        country_count = queryset.count()
        if country_count == 0:
            parent = models.Zone.objects.create(name=country.capitalize(),
                                                type=zone_type)
        else:
            parent = queryset[0]
            if country_count > 1:
                logger_message = "{0} different zones for '{1}'".format(
                    country_count, country)
                logger.warning(logger_message)
    else:
        code = zip_code[:2] or default_department
        try:
            parent = models.Zone.objects.get(code=code)
        except models.Zone.DoesNotExist:
            parent = None

    queryset = models.City.objects.filter(parent=parent)
    queryset = filter_icontains_unaccent(queryset, '"Crm_city"."name"',
                                         city_name)
    cities_count = queryset.count()
    if cities_count:
        if cities_count > 1:
            logger_message = "{0} different cities for '{1}' {2}".format(
                cities_count, city_name, parent)
            logger.warning(logger_message)
        return queryset[0]
    else:
        return models.City.objects.create(name=city_name, parent=parent)
示例#6
0
 def get_object(self):
     """get action"""
     action = get_object_or_404(models.Action, pk=self.kwargs['pk'])
     try:
         return action.actiondocument
     except self.model.DoesNotExist:
         warning_text = ""
         if not action.type:
             warning_text = _(
                 "The action has no type set: Unable to create the corresponding document"
             )
         elif not action.type.default_template:
             warning_text = _(
                 "The action type has no document template defined: Unable to create the corresponding document"
             )
         if warning_text:
             logger.warning(warning_text)
             user_message.warning(self.request, warning_text)
             raise Http404
         else:
             return self.model.objects.create(
                 action=action, template=action.type.default_template)