コード例 #1
0
    def perform_create(self, serializer):
        request_product = serializer.save()
        logger.info(f'{request_product.name} was added for request by {self.request.person}')
        persons_to_be_notified = SaleProduct.objects.filter(category = request_product.category).values_list('person', flat=True).distinct()
        if(persons_to_be_notified.exists()):
            push_notification(
                template = f'{request_product.name} was requested',
                category = request_product.category,
                has_custom_users_target = True,
                persons = list(persons_to_be_notified)
            )
            email_push(
                subject_text = f'Your item {request_product.name} has a prospective seller on Buy and Sell!',
                body_text = f'{ request_product.person.full_name } has added the item that you requested for on Buy and Sell.'+
                            f'You can contact them by mailing them at { request_product.person.contact_information.first().email_address }'+
                            f'\n\n Note: If the  phone number or email id of the seller is missing, that means that { request_product.person.full_name }'
                            f' has not filled in their contact information in the channel-i database ',
                category = request_product.category,
                has_custom_user_target = True,
                persons = list(persons_to_be_notified)
            )
            logger.info(
                f'{self.request.person} requested a product. '
                f'Notifications and emails were dispatched for '
                f'{request_product.category}'
            )

        bit = Bit()
        bit.app_name = 'buy_and_sell'
        bit.entity = request_product
        bit.save()
コード例 #2
0
    def post(self, request):
        token = self.request.data['token']

        category = Category.objects.get(slug=self.request.data['slug'])
        if category.meta['token'] == token:
            subject = self.request.data['subject']
            body = self.request.data['body']

            try:
                by = self.request.data['by']
            except:
                by = None

            try:
                email_ids = self.request.data['email_ids']
            except:
                email_ids = None

            try:
                target_app_name = self.request.data['targetAppName']
            except:
                try:
                    target_app_name = category.meta['targetAppName']
                except:
                    target_app_name = None

            try:
                target_app_url = self.request.data['targetAppUrl']
            except:
                try:
                    target_app_url = category.meta['targetAppUrl']
                except:
                    target_app_url = None

            try:
                use_custom_email = self.request.data['use_custom_email']
            except:
                use_custom_email = False

            try:
                check_if_verified = self.request.data['check_if_verified']
            except:
                check_if_verified = False
            if email_ids:
                email_push(subject, body, None, True, None, email_ids, by,
                           use_custom_email, check_if_verified,
                           target_app_name, target_app_url)
コード例 #3
0
def send_request_email(person, request_data):
    """
    :param form:
    :return:
    """
    service = settings.DISCOVERY.get_app_configuration('r_care')
    app_category = Category.objects.get_or_create(
        name=service.nomenclature.verbose_name,
        slug=service.nomenclature.name,
    )
    category = Category.objects.get_or_create(name='Request',
                                              slug='r_care__request',
                                              parent=app_category[0])
    pin = request_data['pin_code']
    URL = 'https://api.postalpincode.in/pincode/' + str(pin)
    r = requests.get(url=URL)
    try:
        district = r.json()[0]['PostOffice'][0]['District']
        state = r.json()[0]['PostOffice'][0]['State']
        body_text = render_to_string('r_care/request_email.html', {
            'request': request_data,
            'state': state,
            'district': district
        })
    except Exception as e:
        body_text = render_to_string('r_care/request_email.html',
                                     {'request': request_data})
    try:
        target_app_url = f'http://channeli.in/r_care/leads-and-requests/{pin}'
    except Exception as e:
        target_app_url = f'http://channeli.in/r_care/'

    try:
        email_push(
            subject_text=f'Emergency medical request created in R Care',
            body_text=body_text,
            category=category,
            has_custom_user_target=True,
            persons=person,
            target_app_name=service.nomenclature.name,
            target_app_url=target_app_url,
        )
    except Exception as e:
        pass
コード例 #4
0
def send_email(
    subject_text,
    body_text,
    persons=None,
    has_custom_user_target=True,
    send_only_to_subscribed_targets=True,
    category=None,
    by=None,
    check_if_primary_email_verified=True,
    notice_id=None,
):
    """
    Utility to send an email
    :param subject_text: the subject of the e-mail
    :param body_text: the body of the e-mail
    :param persons: the list of ids of persons
    :param has_custom_user_target: whether to e-mail specified persons or not
    :param send_only_to_subscribed_targets: Flag for a notification only to be sent to subscribed users
    :param category: Category under which notice was uploaded
    :param by: id of the person who is posting the mail
    :param notice_id: id of the notice instance for full_path
    """

    app_verbose_name = Config.verbose_name
    app_slug = Config.name

    full_path = f'https://internet.channeli.in/{app_slug}'
    if notice_id:
        full_path = f'{full_path}/notice/{notice_id}'
    relative_url_resolver = (
        '<base href="https://internet.channeli.in/" target="_blank">')
    body_text = f'{relative_url_resolver}{body_text}'
    email_push(
        subject_text=subject_text,
        body_text=body_text,
        category=category,
        has_custom_user_target=has_custom_user_target,
        persons=persons,
        by=by,
        target_app_name=app_verbose_name,
        target_app_url=full_path,
        send_only_to_subscribed_users=send_only_to_subscribed_targets,
    )
コード例 #5
0
    def post(self, request):
        """
        Send email
        :param request: API request
        :return: API response 1 if successful
        """
        token = self.request.data.get('token', None)
        category = Category.objects.get(slug=self.request.data['slug'])

        if category.meta['token'] == token:
            subject = self.request.data.get('subject', None)
            body = self.request.data.get('body', None)
            by = self.request.data.get('by', None)
            email_ids = self.request.data.get('email_ids', None)
            target_app_name = self.request.data.get(
                'targetAppName', category.meta.get('targetAppName', None))
            target_app_url = self.request.data.get(
                'targetAppUrl', category.meta.get('targetAppUrl', None))
            use_primary_email = self.request.data.get('useCustomEmail', False)
            check_if_primary_email_verified = self.request.data.get(
                'checkIfVerified', False)

            if email_ids:
                return Response(
                    email_push(subject_text=subject,
                               body_text=body,
                               category=None,
                               has_custom_user_target=True,
                               persons=None,
                               email_ids=email_ids,
                               by=by,
                               use_primary_email=use_primary_email,
                               check_if_primary_email_verified=
                               check_if_primary_email_verified,
                               target_app_name=target_app_name,
                               target_app_url=target_app_url))
コード例 #6
0
def send_mass_change_report(report, verifier, update):
    """
    :param report: Mass update report
    :param verifier: Verifier object
    :param update: Update status
    :return:
    """

    app = settings.DISCOVERY.get_app_configuration('no_dues')
    app_verbose_name = app.nomenclature.verbose_name
    app_slug = app.nomenclature.name

    category, _ = Category.objects.get_or_create(
        name=app_verbose_name,
        slug=app_slug,
    )

    authority = verifier.authority
    person = verifier.person
    full_name = person.full_name
    persons = list(
        authority.verifiers.values_list('person_id', flat=True).distinct())

    full_path = f'https://newchanneli.iitr.ac.in/?next=/no_dues'
    subject_text = '[No Dues] Mass update report'

    body_text = """Hello,
    The following is the mass update report updated by {} to the status {}.
    <br><br>
    <table style="border: 1px solid black">
    <tr style="border: 1px solid black">
        <th style="border: 1px solid black">Enrolment Number</th>
        <th style="border: 1px solid black">Status (0-Fail, 1-Success)</th>
        <th style="border: 1px solid black">Description</th>
    </tr>
    """
    body_text = body_text.format(full_name, update)
    table_row_text = """<tr style="border: 1px solid black">
        <td style="border: 1px solid black">{}</td>
        <td style="border: 1px solid black">{}</td>
        <td style="border: 1px solid black">{}</td>
    """

    for record in report:
        body_text = body_text + \
            table_row_text.format(
                record['enrolment_number'], record['Status'], record['Info'])

    body_text = body_text + '</table>'

    try:
        email_push(
            subject_text=subject_text,
            body_text=body_text,
            category=category,
            has_custom_user_target=True,
            persons=persons,
            target_app_name=app_verbose_name,
            target_app_url=full_path,
        )

    except Exception as e:
        pass
コード例 #7
0
def send_notification(subject_text, body_text, front_path, to_authority,
                      subscriber, authority):
    """
    :param subject_text: Subject text for the email
    :param body_text: Body text for the email
    :param front_path: Path to the redirection view after the host
    :param to_authority: If the notification is for authority
    :param subscriber: Subscriber object
    :param authority: Authority object
    :return:
    """

    app = settings.DISCOVERY.get_app_configuration('no_dues')
    app_verbose_name = app.nomenclature.verbose_name
    app_slug = app.nomenclature.name

    category, _ = Category.objects.get_or_create(
        name=app_verbose_name,
        slug=app_slug,
    )

    if to_authority and authority is None:
        raise Exception(
            'to_authority and authority parameter can not be False together')
    elif subscriber is None:
        raise Exception(
            'Can not set subscriber to None with to_authority marked as False')

    if to_authority:
        persons = list(
            authority.verifiers.values_list('person_id', flat=True).distinct())
    else:
        subscriber_person_id = subscriber.person_id
        persons = list()
        persons.append(subscriber_person_id)

    subject_text = f'[No Dues] {subject_text}'
    full_path = f'https://newchanneli.iitr.ac.in/?next=/{front_path}'

    try:
        email_push(
            subject_text=subject_text,
            body_text=body_text,
            category=category,
            has_custom_user_target=True,
            persons=persons,
            target_app_name=app_verbose_name,
            target_app_url=full_path,
        )

        push_notification(
            template=subject_text,
            category=category,
            web_onclick_url=front_path,
            android_onclick_activity='',
            ios_onclick_action='',
            is_personalised=False,
            person=None,
            has_custom_users_target=True,
            persons=persons,
        )

    except Exception as e:
        pass