Пример #1
0
def on_incoming_message(request):
    if request.method == 'POST':

        try:
            data = json.loads(request.body)
        except:
            data = request.POST

        try:
            sender = data['sender']
            stripped_text = data['stripped-text']
        except:
            sender = None
            stripped_text = None

        if stripped_text is not None:

            try:
                user = User.objects.get(email=sender)
            except User.DoesNotExist:
                user = None

            if user is not None:
                user_tz = pytz.timezone(user.timezone)
                local_time = datetime.now(user_tz)

                todays_day = local_time.day
                todays_month = local_time.month
                todays_year = local_time.year

                try:
                    todays_prompt = Prompt.objects.get(
                        mail_day__day=todays_day,
                        mail_day__month=todays_month,
                        mail_day__year=todays_year)
                except Prompt.DoesNotExist:
                    todays_prompt = None

                if todays_prompt is not None:
                    try:
                        entry_exists = Entry.objects.get(
                            pub_date__day=todays_day,
                            pub_date__month=todays_month,
                            pub_date__year=todays_year,
                            author=user)
                    except Entry.DoesNotExist:
                        entry_exists = None

                    if entry_exists is None:
                        entry = Entry(content=stripped_text,
                                      author=user,
                                      prompt=todays_prompt,
                                      pub_date=timezone.now())
                        entry.save()

    return HttpResponse('OK')
Пример #2
0
def api_putJSON(request):
    logger.info('function_call api_putJSON(request) ->')

    if request.POST:
        entry = Entry(id = request.POST.get('id'), json = request.POST.get('json'))
        entry.save()
        response = 'OK'
    else:
        response = 'No POST'

    return HttpResponse(response, content_type="application/json")
Пример #3
0
 def common_insert_approach(self):
     for i in range(100000):
         entry = Entry()
         entry.name = "Test {}".format(i)
         entry.save()