예제 #1
0
def handle_user_logged_in(sender, **kwargs):
    log(
        user=kwargs.get("user"),
        #	userid = kwargs.get("userid"),
        #	phone = kwargs.get("phone"),
        action="USER_LOGGED_IN",
        extra={})
예제 #2
0
 def reload(cls, session):
     content = fetch.ISO_639_3Fetcher(session).fetch()
     if not content:
         return
     reader = csv.DictReader(StringIO(content), dialect="excel-tab")
     rows_updated = rows_created = 0
     for row in reader:
         defaults = dict(part_2b=row["Part2B"] or "",
                         part_2t=row["Part2T"] or "",
                         part_1=row["Part1"] or "",
                         scope=row["Scope"],
                         language_type=row["Language_Type"],
                         ref_name=row["Ref_Name"],
                         comment=row["Comment"] or "")
         record, created = cls.objects.get_or_create(code=row["Id"],
                                                     defaults=defaults)
         if created:
             rows_created += 1
         else:
             for key in defaults:
                 setattr(record, key, defaults[key])
             record.save()
             rows_updated += 1
     log(user=None,
         action="SOURCE_SIL_ISO_639_3_RELOADED",
         extra={
             "rows_created": rows_created,
             "rows-updated": rows_updated
         })
예제 #3
0
 def reload(cls, session):
     content = fetch.EthnologueLanguageCodesFetcher(session).fetch()
     if not content:
         return
     reader = csv.DictReader(StringIO(content), dialect="excel-tab")
     rows_updated = rows_created = 0
     for row in reader:
         defaults = dict(
             country_code=row["CountryID"],
             status=row["LangStatus"],
             name=row["Name"],
         )
         record, created = cls.objects.get_or_create(code=row["LangID"],
                                                     defaults=defaults)
         if created:
             rows_created += 1
         else:
             for key in defaults:
                 setattr(record, key, defaults[key])
             record.save()
             rows_updated += 1
     log(user=None,
         action="SOURCE_ETHNOLOGUE_LANG_CODE_RELOADED",
         extra={
             "rows_created": rows_created,
             "rows-updated": rows_updated
         })
예제 #4
0
 def test_retirement_plan_advice_feed_list_unread(self):
     self.content_type = ContentTypeFactory.create()
     self.bonds_asset_class = AssetClassFactory.create(
         investment_type=InvestmentType.Standard.BONDS.get())
     self.stocks_asset_class = AssetClassFactory.create(
         investment_type=InvestmentType.Standard.STOCKS.get())
     self.bonds_ticker = TickerFactory.create(
         asset_class=self.bonds_asset_class,
         benchmark_content_type=self.content_type)
     self.stocks_ticker = TickerFactory.create(
         asset_class=self.stocks_asset_class,
         benchmark_content_type=self.content_type)
     plan = RetirementPlanFactory.create()
     elog = log(user=plan.client.user, action='Triggers retirement advice')
     advice = RetirementAdviceFactory(plan=plan,
                                      trigger=elog,
                                      read=timezone.now())
     elog2 = log(user=plan.client.user,
                 action='Triggers another, unread retirement advice')
     advice2 = RetirementAdviceFactory(plan=plan, trigger=elog)
     url = '/api/v1/clients/{}/retirement-plans/{}/advice-feed'.format(
         plan.client.id, plan.id)
     self.client.force_authenticate(user=plan.client.user)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data.get('results')[0]['id'], advice.id)
     self.assertEqual(response.data.get('results')[0]['id'], advice2.id)
     self.assertEqual(response.data.get('count'), 1)
예제 #5
0
 def post(self, request, **kwargs):
     tag_id = request.POST.get("tag_id")
     amount = request.POST.get("amount")
     item_id = request.POST.get("item_id")
     hash = request.POST.get("hash")
     if None in [tag_id, amount, item_id, hash]:
         return HttpResponseBadRequest("The request was malformed.")
     for secret in Secret.objects.all():
         calc_string = str(tag_id) + str(amount) + str(item_id) + str(
             secret.value)
         calc_hash = hashlib.sha256(calc_string.encode("ascii")).hexdigest()
         print(calc_string)
         print(calc_hash.upper())
         print(hash)
         if calc_hash.upper() == hash.upper():
             tag = get_object_or_404(Tag, pk=tag_id)
             item = get_object_or_404(Item, pk=item_id)
             transaction = Transaction(owner=tag.attendee,
                                       item=item,
                                       amount=amount)
             transaction.save()
             return HttpResponse("Success")
     log(user=request.user,
         action="attempted_break_in",
         extra={
             "REMOTE_ADDR": request.META.get('REMOTE_ADDR'),
             "body": str(request.body),
         })
     return HttpResponseForbidden(
         "Unauthorized attempt, this has been logged")
예제 #6
0
파일: views.py 프로젝트: dblohm7/socorro
def releases(request):
    context = {}
    platforms_api = Platforms()
    platform_names = [x['name'] for x in platforms_api.get()]

    if request.method == 'POST':
        form = forms.ReleaseForm(request.POST, platforms=platform_names)
        if form.is_valid():
            api = Releases()
            api.post(
                product=form.cleaned_data['product'],
                version=form.cleaned_data['version'],
                update_channel=form.cleaned_data['update_channel'],
                build_id=form.cleaned_data['build_id'],
                platform=form.cleaned_data['platform'],
                beta_number=form.cleaned_data['beta_number'],
                release_channel=form.cleaned_data['release_channel'],
                throttle=form.cleaned_data['throttle'],
            )
            log(request.user, 'release.add', form.cleaned_data)
            messages.success(
                request, 'New release for %s:%s added.' %
                (form.cleaned_data['product'], form.cleaned_data['version']))
            return redirect('manage:releases')
    else:
        form = forms.ReleaseForm(platforms=platform_names,
                                 initial={
                                     'throttle': 1,
                                     'update_channel': 'Release',
                                     'release_channel': 'release',
                                 })

    context['form'] = form
    context['page_title'] = "Releases"
    return render(request, 'manage/releases.html', context)
 def commit_and_log(self, filename):
     self.inserter.commit()
     if log is not None:
         log(user=None,
             action=filename,
             extra={"filename": filename},
             obj=ContentType.objects.get_for_model(ExcelImportTask))
예제 #8
0
파일: views.py 프로젝트: dblohm7/socorro
def products(request):
    context = {}
    api = ProductVersions()
    if request.method == 'POST':
        existing_products = set(x['product'] for x in api.get()['hits'])
        form = forms.ProductForm(request.POST,
                                 existing_products=existing_products)
        if form.is_valid():
            api.post(product=form.cleaned_data['product'],
                     version=form.cleaned_data['initial_version'])
            log(request.user, 'product.add', form.cleaned_data)
            messages.success(
                request, 'Product %s (%s) added.' %
                (form.cleaned_data['product'],
                 form.cleaned_data['initial_version']))
            return redirect('manage:products')
    else:
        product = request.GET.get('product')
        if product is not None:
            messages.error(
                request,
                'Product %s not found. Submit the form below to add it.' %
                (product))
        form = forms.ProductForm(initial={
            'product': product,
            'initial_version': '1.0'
        })
    context['form'] = form
    context['page_title'] = "Products"
    return render(request, 'manage/products.html', context)
예제 #9
0
def handle_user_signed_up(sender, **kwargs):
    log(
        user=kwargs.get("user"),
        action="USER_SIGNED_UP",
        extra={}
    )
    customers.create(kwargs.get("user"))
예제 #10
0
def add_item_type(request):
    if request.method == "POST":
        form = ItemTypeForm(request.POST, request.FILES)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.subCategoryID = get_object_or_404(
                ItemSubCategory, pk=request.POST['subCategory'])
            obj.save()
            # for now redirect back to item listings. Until detailed page is done

            log(user=request.user,
                action="ITEM_TYPE_CREATED",
                obj=obj,
                extra={})
            return redirect('itemList')
    else:
        form = ItemTypeForm()
        form2 = ItemForm()
        categories = ItemCategory.objects.all()
        subcategories = ItemSubCategory.objects.all()
        return render(
            request, 'addItemType.html', {
                'title': 'Add Item',
                'form': form,
                'form2': form2,
                'categories': categories,
                'subcategories': subcategories
            })
예제 #11
0
def handle_user_signed_up(sender, **kwargs):
    log(
        user=kwargs.get("user"),
        #	userid = kwargs.get("userid"),
        #	phone = kwargs.get("phone"),
        action="USER_SIGNED_UP",
        extra={})
예제 #12
0
 def reload(cls, session):
     content = fetch.EthnologueCountryCodesFetcher(session).fetch()
     if not content:
         return
     reader = csv.DictReader(StringIO(content), dialect="excel-tab")
     rows_updated = rows_created = 0
     for row in reader:
         defaults = dict(
             name=row["Name"],
             area=row["Area"]
         )
         record, created = cls.objects.get_or_create(
             code=row["CountryID"],
             defaults=defaults
         )
         if created:
             rows_created += 1
         else:
             for key in defaults:
                 setattr(record, key, defaults[key])
             record.save()
             rows_updated += 1
     log(user=None, action="SOURCE_ETHNOLOGUE_COUNTRY_CODE_RELOADED", extra={
         "rows_created": rows_created,
         "rows-updated": rows_updated
     })
예제 #13
0
def checkin_item(request, checkoutitem_id):
    # fill checked in date for checkout item
    ci = CheckoutItem.objects.get(pk=checkoutitem_id)
    ci.dateTimeIn = datetime.now()
    ci.checkedInBy = request.user

    # mark item as in
    item = ci.item
    item.checkoutStatus = CONST_STATUS_CHECKEDIN

    ci.save()
    item.save()

    log(user=request.user, action="ITEM_CHECKED_IN", obj=ci, extra={})

    # is checkout complete
    items = CheckoutItem.objects.filter(
        checkout=ci.checkout, item__checkoutStatus=CONST_STATUS_CHECKEDOUT)
    if not items:
        checkout = ci.checkout
        checkout.status = CONST_STATUS_CLOSED
        checkout.save()
        log(user=request.user, action="CHECKOUT_CLOSED", obj=ci, extra={})
    return render(request, 'checkoutEdit.html', {
        'title': 'Check In',
        'checkout': ci.checkout
    })
예제 #14
0
 def handle(self, *args, **options):
     overdue = CheckoutItem.objects.filter(dateTimeDue__lt=datetime.now(),
                                           dateTimeIn=None)
     for ci in overdue:
         nSent = send_templated_mail(
             template_name='itemOverdue',
             recipient_list=[ci.checkout.person.email],
             from_email=None,
             fail_silently=True,
             context={'checkoutItem': ci})
         if nSent == 0:
             log(user=None,
                 action="EMAIL_SENDING_FAILED",
                 obj=None,
                 extra={
                     'email': 'itemOverdue',
                     'recipient_list': [ci.checkout.person.email]
                 })
         else:
             log(user=None,
                 action="EMAIL_SENT",
                 obj=None,
                 extra={
                     'email': 'itemOverdue',
                     'recipient_list': [ci.checkout.person.email]
                 })
예제 #15
0
def _process_obs_response(response):
    if response.status_code != 200 or _clean_json_data(response) is None:
        log(
            user=None,
            action="GET_OBS_CATALOG_FAILED",
            extra={"status_code": response.status_code, "text": response.content}
        )
    else:
        title, _ = Title.objects.get_or_create(slug="open-bible-stories", defaults={"name": "Open Bible Stories"})
        medias = (Media.objects.get_or_create(slug="print", defaults={"name": "Print"}),
                  Media.objects.get_or_create(slug="mobile", defaults={"name": "Mobile"}))
        record_count = resources_created = resources_updated = 0
        for row in response.json():
            lang = next(iter(Language.objects.filter(code=row["language"])), None)
            if lang:
                resource, created = lang.resources.get_or_create(title=title)
                resource.extra_data = row["status"]
                resource.save()
                for media, _ in medias:
                    resource.medias.add(media)
                if created:
                    resources_created += 1
                else:
                    resources_updated += 1
            record_count += 1
        log(
            user=None,
            action="GET_OBS_CATALOG_SUCCEEDED",
            extra={"records_processed": record_count, "resources_created": resources_created, "resources_updated": resources_updated}
        )
    return response.json()
예제 #16
0
def user(request, id):
    context = {}
    user_ = get_object_or_404(User, id=id)
    if request.method == 'POST':
        # make a copy because it's mutable in the form
        before = copy.copy(user_)
        # expand the many-to-many field before changing it in the form
        before.__groups = [unicode(x) for x in before.groups.all()]

        form = forms.EditUserForm(request.POST, instance=user_)
        if form.is_valid():
            form.save()
            log(request.user, 'user.edit', {
                'change': notice_change(before, user_),
                'id': user_.id,
            })
            messages.success(
                request,
                'User %s update saved.' % user_.email
            )
            return redirect('manage:users')
    else:
        form = forms.EditUserForm(instance=user_)
    context['form'] = form
    context['edit_user'] = user_
    return render(request, 'manage/user.html', context)
예제 #17
0
def edit_category(request,category_id):
    cat = get_object_or_404(ItemCategory, pk=category_id)
    if request.method == "POST":
        form = ItemCategoryForm(request.POST, instance=cat)
        if form.is_valid():
            obj = form.save(commit=False)
            oldValues = obj.tracker.changed()
            # build the extras for the log
            obj.save()

            extras = {}
            for key in oldValues:
                extras.update({'old-' + key: oldValues[key]})
                extras.update({'new-' + key: obj.tracker.previous(key)})

            log(
                user=request.user,
                action="CATEGORY_MODIFIED",
                obj=obj,
                extra=extras
            )

            # for now redirect back to item listings. Until detailed page is done
            return redirect('categoryList')
    else:
        form = ItemCategoryForm(instance=cat)
        return render(request, 'editCategory.html', {'title': "Edit: " + cat.categoryName, 'form': form, 'category': cat, })
예제 #18
0
def reprocessing(request):
    if request.method == 'POST':
        form = forms.ReprocessingForm(request.POST)
        if form.is_valid():
            crash_id = form.cleaned_data['crash_id']
            url = reverse('manage:reprocessing')
            worked = Reprocessing().post(crash_ids=[crash_id])
            if worked:
                url += '?crash_id={}'.format(crash_id)
                messages.success(
                    request,
                    '{} sent in for reprocessing.'.format(crash_id)
                )
            else:
                messages.error(
                    request,
                    'Currently unable to send in the crash ID '
                    'for reprocessing.'
                )
            log(request.user, 'reprocessing', {
                'crash_id': crash_id,
                'worked': worked,
            })

            return redirect(url)
    else:
        form = forms.ReprocessingForm()
    context = {
        'form': form,
        'crash_id': request.GET.get('crash_id'),
    }
    return render(request, 'manage/reprocessing.html', context)
예제 #19
0
def groups(request):
    context = {}
    if request.method == 'POST':
        if request.POST.get('delete'):
            group = get_object_or_404(Group, pk=request.POST['delete'])
            group.delete()
            log(request.user, 'group.delete', {'name': group.name})
            messages.success(
                request,
                'Group deleted.'
            )
            return redirect('manage:groups')
        form = forms.GroupForm(request.POST)
        if form.is_valid():
            group = form.save()
            log(request.user, 'group.add', {
                'id': group.id,
                'name': group.name,
                'permissions': [x.name for x in group.permissions.all()]
            })
            messages.success(
                request,
                'Group created.'
            )
            return redirect('manage:groups')
    else:
        form = forms.GroupForm()
    context['form'] = form
    context['groups'] = Group.objects.all().order_by('name')
    context['permissions'] = Permission.objects.all().order_by('name')
    return render(request, 'manage/groups.html', context)
예제 #20
0
def group(request, id):
    context = {}
    group_ = get_object_or_404(Group, id=id)
    if request.method == 'POST':
        before = copy.copy(group_)
        before.__permissions = [x.name for x in before.permissions.all()]
        # print "permissions before", before.permissions.all()
        form = forms.GroupForm(request.POST, instance=group_)
        if form.is_valid():
            form.save()
            # print "permissions after", group_.permissions.all()
            group_.__permissions = [x.name for x in group_.permissions.all()]
            log(request.user, 'group.edit', {
                'id': group_.id,
                'change': notice_change(before, group_),
            })
            messages.success(
                request,
                'Group saved.'
            )
            return redirect('manage:groups')
    else:
        form = forms.GroupForm(instance=group_)
    context['form'] = form
    context['group'] = group_
    return render(request, 'manage/group.html', context)
예제 #21
0
 def delete(self, request, pk):
     if TokenVerify(request) and BackEndPermissionVerifier(request):
         try:
             I = get_user_ID(request)
             teams = Team.objects.get(id=pk)
             for i in teams.achievement.all():
                 ach = Achievement.objects.get(id=i.id)
                 teams.achievement.remove(ach)
                 ach.delete()
             teams.delete()
             log(
                 user=User.objects.get(id=I),
                 action="Deleted a team",
             )
             return Response({"msg": "Deleted successfully!"},
                             status=status.HTTP_200_OK)
         except ObjectDoesNotExist:
             return Response({"msg": "This team doesn't exist"},
                             status=status.HTTP_400_BAD_REQUEST)
         except Exception as ex:
             log_errors(str(ex), I)
             return Response({"msg": "An error has happened! "},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return Response({"msg": "Token Invalid"},
                         status=status.HTTP_400_BAD_REQUEST)
예제 #22
0
def edit_item(request, item_type_id, item_id):
    item = get_object_or_404(Item, pk=item_id)
    itemType = get_object_or_404(ItemType, pk=item_type_id)
    if request.method == "POST":
        form = ItemForm(request.POST, instance=item)
        if form.is_valid():
            obj = form.save(commit=False)
            oldValues = obj.tracker.changed()
            # build the extras for the log
            obj.save()

            extras = {}
            for key in oldValues:
                extras.update({'old-' + key: oldValues[key]})
                extras.update({'new-' + key: obj.tracker.previous(key)})

            log(user=request.user,
                action="ITEM_MODIFIED",
                obj=item,
                extra=extras)
            # for now redirect back to item listings. Until detailed page is done
            return redirect('itemList')
    else:
        form = ItemForm(instance=item)
        return render(
            request, 'editItem.html', {
                'title': "Edit: " + itemType.name,
                'form': form,
                'item': item,
                'itemType': itemType
            })
예제 #23
0
 def post(self, request):
     if TokenVerify(request):
         try:
             id = get_user_ID(request)
             serializer = FAQSerializer(data=request.data)
             if (serializer.is_valid()):
                 serializer.save()
                 log(
                     user=User.objects.get(id=id),
                     action="Added FAQ",
                 )
                 return Response(serializer.data,
                                 status=status.HTTP_201_CREATED)
             else:
                 log(
                     user=User.objects.get(id=id),
                     action="Tried to add FAQ",
                 )
                 return Response(serializer.errors,
                                 status=status.HTTP_400_BAD_REQUEST)
         except Exception as ex:
             log_errors(str(ex), id)
             return Response({"msg": "An error has happened! "},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return Response({"msg": "unauthorized"},
                         status=status.HTTP_400_BAD_REQUEST)
예제 #24
0
 def reload(cls, session):
     content = fetch.ISO_639_3Fetcher(session).fetch()
     if not content:
         return
     reader = csv.DictReader(StringIO(content), dialect="excel-tab")
     rows_updated = rows_created = 0
     for row in reader:
         defaults = dict(
             part_2b=row["Part2B"] or "",
             part_2t=row["Part2T"] or "",
             part_1=row["Part1"] or "",
             scope=row["Scope"],
             language_type=row["Language_Type"],
             ref_name=row["Ref_Name"],
             comment=row["Comment"] or ""
         )
         record, created = cls.objects.get_or_create(
             code=row["Id"],
             defaults=defaults
         )
         if created:
             rows_created += 1
         else:
             for key in defaults:
                 setattr(record, key, defaults[key])
             record.save()
             rows_updated += 1
     log(user=None, action="SOURCE_SIL_ISO_639_3_RELOADED", extra={
         "rows_created": rows_created,
         "rows-updated": rows_updated
     })
예제 #25
0
 def get(self, request, id):
     if TokenVerify(request) and BackEndPermissionVerifier(request):
         try:
             I = get_user_ID(request)
             # TargetUser = User.objects.filter(id = id).first()
             profile = Profile.objects.get(user=id)
             user_dictionary = {}
             user_dictionary["name"] = profile.name
             user_dictionary["phone"] = profile.mobile
             user_dictionary["college_id"] = profile.college_id
             user_dictionary["email"] = profile.user.email
             user_dictionary["group"] = profile.user.groups.all().first(
             ).name
             log(
                 user=User.objects.get(id=I),
                 action="Viewed one user",
             )
             return Response(user_dictionary)
         except ObjectDoesNotExist:
             return Response({"msg": "This user doesn't exist"},
                             status=status.HTTP_400_BAD_REQUEST)
         except Exception as ex:
             log_errors(str(ex), I)
             return Response({"msg": "An error has happened! "},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return Response({"msg": "unauthorized"},
                         status=status.HTTP_400_BAD_REQUEST)
예제 #26
0
 def put(self, request, id):
     if TokenVerify(request) and BackEndPermissionVerifier(request):
         try:
             I = get_user_ID(request)
             user = User.objects.get(pk=id)
             updated_group = Group.objects.get(name=request.data['group'])
             print(user)
             user.groups.clear()
             user.groups.add(updated_group)
             log(
                 user=User.objects.filter(id=I).first(),
                 action="Updated a user",
             )
             return Response(
                 {"msg": "User Group Permissions SUccessfully Updated"},
                 status=status.HTTP_202_ACCEPTED)
         except ObjectDoesNotExist:
             return Response({"msg": "This user doesn't exist"},
                             status=status.HTTP_400_BAD_REQUEST)
         except Exception as ex:
             log_errors(str(ex), I)
             return Response({"msg": "An error has happened! "},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return Response({"msg": "unauthorized"},
                         status=status.HTTP_400_BAD_REQUEST)
예제 #27
0
def handle_user_login_attempt(sender, **kwargs):
    log(user=None,
        action="LOGIN_ATTEMPTED",
        extra={
            "username": kwargs.get("username"),
            "result": kwargs.get("result")
        })
예제 #28
0
def handle_user_sign_up_attempt(sender, **kwargs):
    log(user=None,
        action="SIGNUP_ATTEMPTED",
        extra={
            "username": kwargs.get("username"),
            "email": kwargs.get("email"),
            "result": kwargs.get("result")
        })
예제 #29
0
 def fetch(self):
     response = self.session.get(self.url)
     if response.status_code != 200:
         log(
             user=None,
             action=self.error_action_label,
             extra={"status_code": response.status_code, "text": response.content}
         )
     return response.content
예제 #30
0
def status_message(request):
    if request.method == 'POST':
        form = forms.StatusMessageForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            status = StatusMessage.objects.create(
                message=data['message'],
                severity=data['severity'],
            )

            log(request.user, 'status_message.create', {
                'user': request.user.email,
                'severity': status.severity,
            })

            messages.success(
                request,
                'Status Message created. '
            )
            return redirect('manage:status_message')
    else:
        form = forms.StatusMessageForm()

    try:
        page = int(request.GET.get('page', 1))
        assert page >= 1
    except (ValueError, AssertionError):
        return http.HttpResponseBadRequest('invalid page')

    statuses = (
        StatusMessage.objects.all().order_by('-created_at')
    )

    count = statuses.count()
    batch_size = settings.STATUS_MESSAGE_ADMIN_BATCH_SIZE
    m = (page - 1) * batch_size
    n = page * batch_size

    current_query = request.GET.copy()
    if 'page' in current_query:
        del current_query['page']
    current_url = '{}?{}'.format(
        reverse('manage:status_message'),
        current_query.urlencode()
    )

    context = {
        'form': form,
        'statuses': statuses[m:n],
        'pagination_data': {
            'page': page,
            'current_url': current_url,
            'total_pages': int(math.ceil(float(count) / batch_size)),
            'total_count': count,
        }
    }
    return render(request, 'manage/status_message.html', context)
예제 #31
0
def handle_invite_accepted(sender, **kwargs):
    invitation = kwargs.get("invitation")
    log(user=invitation.to_user, action="INVITE_ACCEPTED", extra={})
    send([invitation.from_user],
         "invite_accepted",
         extra_context={
             "joiner": invitation.to_user.username,
             "email": invitation.to_user.email
         })
예제 #32
0
    def history(self, cats):
        counter = 0
        for cell in cats:
            cat = None
            if counter >= 1:
                # print len(cell)
                # if len(cell) != 18:
                #   print ', '.join(cell)
                try:
                    (animal_id, animal_name, type_colour, breed, date_from,
                     return_reason, status, none, other_reason,
                     last_owner_notes, shelter_location, adoption_date) = cell
                except Exception as e:
                    import pdb
                    pdb.set_trace()

                cat, cat_is_new = Cat.objects.get_or_create(pk=animal_id)
                if cat_is_new is True:
                    cat.name = animal_name
                    cat.sex = sex.lower()[0] if sex else None
                    cat.breed = breed
                    cat.save()

                message = '%s' % return_reason
                if other_reason:
                    message = '%s, - %s' % (message, other_reason)

                log(user=self.user,
                    action=status.lower(),
                    obj=cat,
                    dateof=parse(date_from) if date_from else None,
                    extra={
                        'animal_id':
                        animal_id,
                        'name':
                        animal_name,
                        'type':
                        type_colour,
                        'breed':
                        breed,
                        'date_from':
                        parse(date_from) if date_from else None,
                        'return_reason':
                        return_reason,
                        'status':
                        status,
                        'other_reason':
                        other_reason,
                        'last_owner_notes':
                        last_owner_notes,
                        'shelter_location':
                        shelter_location,
                        'adoption_date':
                        parse(adoption_date) if date_from else None,
                    })

            counter = counter + 1
예제 #33
0
def _log_bet_event(user, instance, status, *args, **kwargs):
    """
    Log a custom event
    """
    log(user=user,
        action=status.lower(),
        obj=instance,
        dateof=datetime.datetime.utcnow(),
        extra=kwargs)
예제 #34
0
def handle_user_login_attempt(sender, **kwargs):
    log(
        user=None,
        action="LOGIN_ATTEMPTED",
        extra={
            "username": kwargs.get("username"),
            "result": kwargs.get("result")
        }
    )
예제 #35
0
def graphics_devices(request):
    context = {}
    form = forms.GraphicsDeviceForm()
    upload_form = forms.GraphicsDeviceUploadForm()

    if request.method == 'POST' and 'file' in request.FILES:
        upload_form = forms.GraphicsDeviceUploadForm(
            request.POST,
            request.FILES
        )
        if upload_form.is_valid():
            if upload_form.cleaned_data['database'] == 'pcidatabase.com':
                function = utils.pcidatabase__parse_graphics_devices_iterable
            else:
                function = utils.pci_ids__parse_graphics_devices_iterable

            payload = list(function(upload_form.cleaned_data['file']))
            api = GraphicsDevices()
            result = api.post(data=payload)
            log(request.user, 'graphicsdevices.post', {
                'success': result,
                'database': upload_form.cleaned_data['database'],
                'no_lines': len(payload),
            })
            messages.success(
                request,
                'Graphics device CSV upload successfully saved.'
            )
            return redirect('manage:graphics_devices')

    elif request.method == 'POST':
        form = forms.GraphicsDeviceForm(request.POST)
        if form.is_valid():
            payload = [{
                'vendor_hex': form.cleaned_data['vendor_hex'],
                'adapter_hex': form.cleaned_data['adapter_hex'],
                'vendor_name': form.cleaned_data['vendor_name'],
                'adapter_name': form.cleaned_data['adapter_name'],
            }]
            api = GraphicsDevices()
            result = api.post(data=payload)
            log(request.user, 'graphicsdevices.add', {
                'payload': payload,
                'success': result
            })
            if result:
                messages.success(
                    request,
                    'Graphics device saved.'
                )
            return redirect('manage:graphics_devices')

    context['page_title'] = "Graphics Devices"
    context['form'] = form
    context['upload_form'] = upload_form
    return render(request, 'manage/graphics_devices.html', context)
예제 #36
0
def handle_user_sign_up_attempt(sender, **kwargs):
    log(
        user=None,
        action="SIGNUP_ATTEMPTED",
        extra={
            "username": kwargs.get("username"),
            "email": kwargs.get("email"),
            "result": kwargs.get("result")
        }
    )
예제 #37
0
 def fetch(self):
     response = self.session.get(self.url)
     if response.status_code != 200:
         log(user=None,
             action=self.error_action_label,
             extra={
                 "status_code": response.status_code,
                 "text": response.content
             })
     return response.content
def integrate_imports():
    """
    Integrate imported language data into the language model
    """
    cursor = connection.cursor()
    cursor.execute("""
select coalesce(nullif(x.part_1, ''), x.code) as code,
       coalesce(nullif(nn1.native_name, ''), nullif(nn2.native_name, ''), x.ref_name) as name,
       coalesce(nullif(nn1.language_name, ''), nn2.language_name, lc.name, '') as anglicized_name,
       coalesce(cc.code, ''),
       nullif(nn1.native_name, '') as nn1name,
       nn1.id,
       nullif(nn2.native_name, '') as nn2name,
       nn2.id,
       x.ref_name as xname,
       x.id,
       x.code as iso_639_3
  from imports_sil_iso_639_3 x
left join imports_ethnologuelanguagecode lc on x.code = lc.code
left join imports_wikipediaisolanguage nn1 on x.part_1 = nn1.iso_639_1
left join imports_wikipediaisolanguage nn2 on x.code = nn2.iso_639_3
left join imports_ethnologuecountrycode cc on lc.country_code = cc.code
 where lc.status = %s or lc.status is NULL order by code;
""", [EthnologueLanguageCode.STATUS_LIVING])
    rows = cursor.fetchall()
    rows.extend([
        (
            x.merge_code(), x.merge_name(), x.native_name, None, "", None, "",
            None, "!ADDL", x.id, x.three_letter
        )
        for x in AdditionalLanguage.objects.all()
    ])
    rows.sort()
    for r in rows:
        if r[0] is not None:
            language, _ = Language.objects.get_or_create(code=r[0])
            language.name = r[1]
            language.anglicized_name = r[2]
            if r[1] == r[4]:
                language.source = WikipediaISOLanguage.objects.get(pk=r[5])
            if r[1] == r[6]:
                language.source = WikipediaISOLanguage.objects.get(pk=r[7])
            if r[1] == r[8]:
                language.source = SIL_ISO_639_3.objects.get(pk=r[9])
            if r[8] == "!ADDL":
                language.source = AdditionalLanguage.objects.get(pk=r[9])
            if r[10] != "":
                language.iso_639_3 = r[10]
            language.save()
            if r[3]:
                language.country = next(iter(Country.objects.filter(code=r[3])), None)
                language.source = EthnologueCountryCode.objects.get(code=r[3])
                language.save()
    languages_integrated.send(sender=Language)
    log(user=None, action="INTEGRATED_SOURCE_DATA", extra={})
예제 #39
0
    def history(self, cats):
        counter = 0
        for cell in cats:
            cat = None
            if counter >= 1:
                # print len(cell)
                # if len(cell) != 18:
                #   print ', '.join(cell)
                try:
                  (animal_id,
                   animal_name,
                   type_colour,
                   breed,
                   date_from,
                   return_reason,
                   status,
                   none,
                   other_reason,
                   last_owner_notes,
                   shelter_location,
                   adoption_date) = cell
                except Exception as e:
                    import pdb;pdb.set_trace()

                cat, cat_is_new = Cat.objects.get_or_create(pk=animal_id)
                if cat_is_new is True:
                    cat.name = animal_name
                    cat.sex = sex.lower()[0] if sex else None
                    cat.breed = breed
                    cat.save()

                message = '%s' % return_reason
                if other_reason:
                    message = '%s, - %s' % (message, other_reason)

                log(user=self.user,
                    action=status.lower(),
                    obj=cat,
                    dateof=parse(date_from) if date_from else None,
                    extra={'animal_id': animal_id,
                           'name': animal_name,
                           'type': type_colour,
                           'breed': breed,
                           'date_from': parse(date_from) if date_from else None,
                           'return_reason': return_reason,
                           'status': status,
                           'other_reason': other_reason,
                           'last_owner_notes': last_owner_notes,
                           'shelter_location': shelter_location,
                           'adoption_date': parse(adoption_date) if date_from else None,})

            counter = counter + 1
예제 #40
0
def update_map_gateways():
    country_gateways = {
        country.alpha_3_code: {
            "fillKey": country.gateway_language().code if country.gateway_language() else "defaultFill",
            "url": reverse("country_detail", args=[country.pk]),
            "country_code": country.code,
            "gateway_language": country.gateway_language().name if country.gateway_language() else "",
            "gateway_languages": [unicode("({0}) {1}").format(ogl.code, ogl.name) for ogl in country.gateway_languages()]
        }
        for country in Country.objects.all()
    }
    cache.set("map_gateways", country_gateways)
    log(user=None, action="UPDATE_MAP_GATEWAYS")
예제 #41
0
 def reload(cls, session):
     content = fetch.WikipediaCountryFetcher(session).fetch()
     if not content:
         return
     soup = bs4.BeautifulSoup(content)
     records = []
     for tr in soup.select("table.sortable tr"):
         row = [td.text for td in tr.find_all("td")]
         if len(row) == 5:
             records.append(cls(
                 english_short_name=row[0].strip(),
                 alpha_2=row[1].strip(),
                 alpha_3=row[2].strip(),
                 numeric_code=row[3].strip(),
                 iso_3166_2_code=row[4].strip()
             ))
     if len(records) > 0:
         cls.objects.all().delete()
         cls.objects.bulk_create(records)
         log(user=None, action="SOURCE_WIKIPEDIA_COUNTRIES_RELOADED", extra={})
예제 #42
0
 def reload(cls, session):
     content = fetch.EthnologueLanguageIndexFetcher(session).fetch()
     if not content:
         return
     reader = csv.DictReader(StringIO(content), dialect="excel-tab")
     rows_updated = rows_created = 0
     for row in reader:
         record, created = cls.objects.get_or_create(
             language_code=row["LangID"],
             country_code=row["CountryID"],
             name_type=row["NameType"],
             name=row["Name"]
         )
         if created:
             rows_created += 1
         else:
             rows_updated += 1  # @@@ Should never be an update on this table
     log(user=None, action="SOURCE_ETHNOLOGUE_LANG_INDEX_RELOADED", extra={
         "rows_created": rows_created,
         "rows-updated": rows_updated
     })
예제 #43
0
 def reload(cls, session):
     content = fetch.WikipediaFetcher(session).fetch()
     if not content:
         return
     soup = bs4.BeautifulSoup(content)
     records = []
     for tr in soup.select("table.wikitable tr"):
         row = [td.text for td in tr.find_all("td")]
         if len(row) == 10:
             records.append(cls(
                 language_family=row[1].strip(),
                 language_name=row[2].strip(),
                 native_name=row[3].strip(),
                 iso_639_1=row[4][:2].strip(),
                 iso_639_2t=row[5][:3].strip(),
                 iso_639_2b=row[6][:3].strip(),
                 iso_639_3=row[7][:3].strip(),
                 iso_639_9=row[8][:4].strip(),
                 notes=row[9].strip()
             ))
     if len(records) > 0:
         cls.objects.all().delete()
         cls.objects.bulk_create(records)
         log(user=None, action="SOURCE_WIKIPEDIA_RELOADED", extra={})
예제 #44
0
파일: adoptions.py 프로젝트: rosscdh/catmap
    def history(self, cats):
        counter = 0
        for cell in cats:
            cat = None
            if counter >= 1:
                # print len(cell)
                # if len(cell) != 18:
                #   print ', '.join(cell)

                try:
                  (tab_no,
                   animal_id,
                   outgoing_adoption_date,
                   adopter_id,
                   suburb_state_post,
                   jurisdiction,
                   status,
                   age_category_at_adoption,
                   sex,
                   animal_name,
                   microchip,
                   sorted_by_tab_no_only,
                   total_17345,
                   tab_1_2645,
                   tab_2_1294,
                   tab_3_4915,
                   tab_4_4667,
                   tab_5_3824) = cell
                except Exception as e:
                    import pdb;pdb.set_trace()

                cat, cat_is_new = Cat.objects.get_or_create(pk=animal_id)
                #print '%s (%s)' % (cat, status)

                outgoing_adoption_date = outgoing_adoption_date.strip()

                try:
                    outgoing_adoption_date = arrow.get(outgoing_adoption_date, 'D MMM YYYY')
                except Exception as e:
                    try:
                        outgoing_adoption_date = arrow.get(outgoing_adoption_date, 'D-MMM-YYYY')
                    except Exception as e:
                        try:
                            outgoing_adoption_date = arrow.get(outgoing_adoption_date, 'D/MM/YYYY')
                        except Exception as e:
                            try:
                                outgoing_adoption_date = arrow.get(outgoing_adoption_date, 'MMM D, YY')
                            except Exception as e:
                                try:
                                    outgoing_adoption_date = arrow.get(outgoing_adoption_date, 'MM/D/YYYY')
                                except Exception as e:
                                    import pdb;pdb.set_trace()

                #if cat_is_new is True:
                cat.name = animal_name
                cat.fake_date_event = outgoing_adoption_date.datetime

                try:
                    gender = sex.lower()[0]
                except IndexError:
                    gender = 'u'
                except Exception as e:
                    import pdb;pdb.set_trace()

                if gender in ['m', 'f']:
                    cat.sex = gender
                else:
                    cat.sex = None

                cat.save()

                log(user=self.user,
                    action=status.lower(),
                    obj=cat,
                    dateof=outgoing_adoption_date.datetime,
                    extra={
                        'animal_id': animal_id,
                        'outgoing_adoption_date': outgoing_adoption_date.datetime,
                        'adopter_id': adopter_id,
                        'suburb_state_post': suburb_state_post,
                        'jurisdiction': jurisdiction,
                        'status': status,
                        'age_category_at_adoption': age_category_at_adoption,
                        'sex': sex,
                        'gender': gender,
                        'animal_name': animal_name,
                        'microchip': microchip
                      })

            counter = counter + 1
        print counter
예제 #45
0
    def history(self, cats):
        counter = 0
        for cell in cats:
            cat = None
            if counter >= 1:
                # print len(cell)
                # if len(cell) != 18:
                #   print ', '.join(cell)
                try:
                  (animal_id,
                   physical_location,
                   shelter_loc,
                   animal_name,
                   breed,
                   type_colour,
                   has_tattoo,
                   has_microchip,
                   lost_found_address,
                   sex,
                   desexed,
                   status,
                   sub_status,
                   source,
                   date_in,
                   due_date_out,
                   date_out,
                   identification_type) = cell
                except Exception as e:
                    import pdb;pdb.set_trace()

                cat, cat_is_new = Cat.objects.get_or_create(pk=animal_id)
                if cat_is_new is True:
                    cat.name = animal_name
                    cat.sex = sex.lower()[0] if sex else None
                    cat.breed = breed
                    cat.coat_type = type_colour
                    cat.colour = type_colour
                    cat.tattoo = has_tattoo
                    cat.desex_done = desexed in TRUTHY
                    cat.save()

                message = '%s' % status
                if sub_status:
                    message = '%s, - %s' % (message, sub_status)

                log(user=self.user,
                    action=status.lower(),
                    obj=cat,
                    dateof=parse(date_in) if date_in else datetime.datetime.utcnow(),
                    extra={'physical_location': physical_location,
                           'shelter_loc': shelter_loc,
                           'animal_name': animal_name,
                           'breed': breed,
                           'type_colour': type_colour,
                           'has_tattoo': has_tattoo,
                           'has_microchip': has_microchip,
                           'lost_found_address': lost_found_address,
                           'sex': sex,
                           'desexed': desexed,
                           'status': status,
                           'sub_status': sub_status,
                           'source': source,
                           'date_in': date_in,
                           'due_date_out': due_date_out,
                           'date_out': date_out,
                           'identification_type': identification_type})

            counter = counter + 1
예제 #46
0
    def history(self, cats):
        counter = 0
        for cell in cats:
            cat = None
            if counter >= 1:
                # print len(cell)
                # if len(cell) != 18:
                #   print ', '.join(cell)
                try:
                  (tab_no,
                   animal_id,
                   received_surrender_date,
                   surrender_source,
                   suburb_state_post,
                   jurisdiction,
                   status,
                   age_category_at_adoption,
                   sex,
                   animal_name,
                   sorted_by_tab_no_only,
                   correct_total_of_28360_cats,
                   tab_1_5323,
                   tab_2_384,
                   tab_3_6754,
                   tab_4_8795,
                   tab_5_7104) = cell
                except Exception as e:
                    import pdb;pdb.set_trace()

                cat, cat_is_new = Cat.objects.get_or_create(pk=animal_id)
                #print '%s (%s)' % (cat, status)

                try:
                    received_surrender_date = arrow.get(received_surrender_date, 'D MMM YYYY')
                except Exception as e:
                    try:
                        received_surrender_date = arrow.get(received_surrender_date, 'D-MMM-YYYY')
                    except Exception as e:
                        try:
                            received_surrender_date = arrow.get(received_surrender_date, 'D/MM/YYYY')
                        except Exception as e:
                            import pdb;pdb.set_trace()

                # if cat_is_new is True:
                cat.name = animal_name
                cat.fake_date_event = received_surrender_date.datetime

                gender = sex.lower()[0]
                if gender in ['m', 'f']:
                    cat.sex = gender
                else:
                    cat.sex = None

                cat.save()

                log(user=self.user,
                    action=status.lower(),
                    obj=cat,
                    dateof=received_surrender_date.datetime,
                    extra={'animal_id': animal_id,
                           'received_surrender_date': received_surrender_date.datetime,
                           'surrender_source': surrender_source,
                           'suburb_state_post': suburb_state_post,
                           'jurisdiction': jurisdiction,
                           'status': status,
                           'age_category_at_adoption': age_category_at_adoption,
                           'sex': sex,
                           'gender': gender,
                           'animal_name': animal_name,
                           })

            counter = counter + 1
        print counter
예제 #47
0
 def reload(cls, session):
     content = fetch.IMBPeopleFetcher(session).fetch()
     if content is None or content == "":
         return
     book = xlrd.open_workbook(file_contents=content)
     sheet = book.sheet_by_index(0)
     key_cell = (4, 0)   # todo: replace this with code to "find" the PEID column properly
     sh_field_names = [sheet.cell_value(key_cell[0], key_cell[1] + x) for x in range(0, 40)]
     current_row_num = key_cell[0] + 1
     rows_created = rows_updated = 0
     while True:
         row = {sh_field_names[x]: sheet.cell_value(current_row_num, x) for x in range(0, 40)}
         if str(row["PEID"]) == "":
             break
         defaults = dict(
             affinity_bloc=row["Affinity Bloc"],
             people_cluster=row["People Cluster"],
             continent=row["Continent"],
             sub_continent=row["Sub-Continent"],
             country=row["Country"],
             country_of_origin=row["Country of Origin"],
             people_group=row["People Group"],
             global_status_evangelical_christianity=row["Global Status of  Evangelical Christianity"],
             evangelical_engagement=str_to_bool(row["Evangelical Engagement"]),
             population=row["Population"],
             dispersed=str_to_bool(row["Dispersed (Yes/No)"], allow_null=True),
             rol=row["ROL"],
             language=row["Language"],
             religion=row["Religion"],
             written_scripture=str_to_bool(row["Written Scripture"]),
             jesus_film=str_to_bool(row["Jesus Film"]),
             radio_broadcast=str_to_bool(row["Radio Broadcast"]),
             gospel_recording=str_to_bool(row["Gospel Recording"]),
             audio_scripture=str_to_bool(row["Audio Scripture"]),
             bible_stories=str_to_bool(row["Bible Stories"]),
             resources=row["Resources"],
             physical_exertion=row["Physical Exertion"],
             freedom_index=row["Freedom Index"],
             government_restrictions_index=row["Government Restrictions Index"],
             social_hostilities_index=row["Social Hostilities Index"],
             threat_level=row["Threat Level"],
             prayer_threads=str_to_bool(row["Prayer Threads"], allow_null=True),
             sbc_embracing_relationship=str_to_bool(row["SBC Embracing Relationship"], allow_null=True),
             embracing_priority=str_to_bool(row["Embracing Priority"]),
             rop1=row["ROP1"],
             rop2=row["ROP2"],
             rop3=row["ROP3"],
             people_name=row["People Name"],
             fips=row["FIPS"],
             fips_of_origin=row["FIPS of Origin"],
             latitude=row["Latitude"],
             longitude=row["Longitude"],
             peid_of_origin=row["PEID of Origin"],
             imb_affinity_group=row["IMB Affinity Group"]
         )
         record, created = cls.objects.get_or_create(
             peid=row["PEID"],
             defaults=defaults
         )
         if created:
             rows_created += 1
         else:
             for key in defaults:
                 setattr(record, key, defaults[key])
             record.save()
             rows_updated += 1
         current_row_num += 1
     log(user=None, action="SOURCE_IMB_PEOPLE_GROUPS_LOADED", extra={
         "rows_created": rows_created,
         "rows-updated": rows_updated
     })
예제 #48
0
def handle_password_changed(sender, **kwargs):
    log(
        user=kwargs.get("user"),
        action="PASSWORD_CHANGED",
        extra={}
    )
예제 #49
0
def handle_user_logged_in(sender, **kwargs):
    log(
        user=kwargs.get("user"),
        action="USER_LOGGED_IN",
        extra={}
    )