Ejemplo n.º 1
0
def update_shops_data():
    from presta.db_logging import log_user_action
    from presta.forms import UpdateProductValidator
    shops = Shop.objects.filter(is_schedule_enabled=True)
    #shops = Shop.objects.filter(schedule__is_null=False).select_related('schedule')
    for shop in shops:
        update_index = shop.interval / 60 - 1
        if shop.update_index == update_index:
            try:
                csv_file = urllib2.urlopen(shop.location).read()
            except urllib2.URLError:
                log_user_action.delay(shop.domain, "CSV Update location error",
                                      str(shop.location), "Error")
                continue
            lines = UpdateProductValidator(csv_file.splitlines())
            # TODO: proper language detection
            if shop.domain.endswith(u'.ru') or shop.domain.endswith(u'.ua'):
                language = 'ru'
            else:
                language = 'en'
            checked_update_presta_data_periodic.delay(shop, lines, language)
            shop.update_index = 0
        else:
            shop.update_index += 1
        # TODO: django 1.5 update only one field
        shop.save()
Ejemplo n.º 2
0
 def get_data(self, page=0, page_limit=settings.PAGINATION):
     from presta.utils.presta_api import build_id_list
     from presta.db_logging import whosdaddy, log_user_action
     data, error_dict = self.api.get_presta_data(page, page_limit)
     if not error_dict:
         data = build_id_list(data)
     else:
         log_user_action.delay(self.domain, whosdaddy(), str(data), str(error_dict))
     return data, error_dict
Ejemplo n.º 3
0
def module_activate(request):
    import socket
    from users.models import Profile
    from presta.forms import clean_domain
    from presta.db_logging import log_user_action

    form = ActivationForm(request.POST)
    if form.is_valid():
        # Check that request goes from the valid domain
        ip_addr = request.META["REMOTE_ADDR"]
        domain_name = clean_domain(form.cleaned_data["domain"]).split(":")[0]
        try:
            if ip_addr != socket.gethostbyname(domain_name):
                log_user_action.delay(form.cleaned_data["domain"], "Register IP mismatch", str(ip_addr), "")
                # return HttpResponseForbidden()
        except socket.error:
            log_user_action.delay(form.cleaned_data["domain"], "Socket Error", "Socket error on module activate", "")

        user, created = Profile.objects.get_or_create(email=form.cleaned_data["email"])
        if created:
            user.set_password(form.cleaned_data["password"])
            user.save()
        shop, created = Shop.objects.get_or_create(
            domain=form.cleaned_data["domain"], user=user, defaults={"key": form.cleaned_data["key"]}
        )

        # If by some reason shop was already created as temp, make it not temp
        if not created and shop.temp:
            shop.temp = False
        _, error_dict = shop.get_data()
        if not error_dict:
            shop.set_ok()
        elif PrestaError.rewrite_disabled(error_dict):
            shop.set_alarm(PrestaError.REGEN_HTACCESS)
        else:
            shop.set_alarm(error_dict.values()[0])

        log_user_action.delay(form.cleaned_data["domain"], "Register Success", "", "")
        return HttpResponse("ok")
    raise Http404
Ejemplo n.º 4
0
def module_activate(request):
    import socket
    from users.models import Profile
    from presta.forms import clean_domain
    from presta.db_logging import log_user_action
    form = ActivationForm(request.POST)
    if form.is_valid():
        # Check that request goes from the valid domain
        ip_addr = request.META['REMOTE_ADDR']
        domain_name = clean_domain(form.cleaned_data['domain']).split(':')[0]
        try:
            if ip_addr != socket.gethostbyname(domain_name):
                log_user_action.delay(form.cleaned_data['domain'], "Register IP mismatch", str(ip_addr), "")
                #return HttpResponseForbidden()
        except socket.error:
            log_user_action.delay(form.cleaned_data['domain'], "Socket Error",
                "Socket error on module activate", "")

        user, created = Profile.objects.get_or_create(email=form.cleaned_data['email'])
        if created:
            user.set_password(form.cleaned_data['password'])
            user.save()
        shop, created = Shop.objects.get_or_create(domain=form.cleaned_data['domain'], user=user,
                                                   defaults={'key': form.cleaned_data['key']})

        # If by some reason shop was already created as temp, make it not temp
        if not created and shop.temp:
            shop.temp = False
        _, error_dict = shop.get_data()
        if not error_dict:
            shop.set_ok()
        elif PrestaError.rewrite_disabled(error_dict):
            shop.set_alarm(PrestaError.REGEN_HTACCESS)
        else:
            shop.set_alarm(error_dict.values()[0])

        log_user_action.delay(form.cleaned_data['domain'], "Register Success", "", "")
        return HttpResponse("ok")
    raise Http404