Exemple #1
0
class TradingAccountAdmin(BaseAdmin):
    list_display = ("mt4_id", "user_with_link", "platform_type", "group_name",
                    "is_deleted", "is_archived", 'deleted_comment',
                    "creation_ts")
    list_filter = ("platform_type", "group_name", "is_deleted", "is_archived")
    search_fields = (
        "user__username",
        "user__first_name",
        "user__last_name",
        "mt4_id",
        "group_name",
    )

    #exclude = ("user", )

    #readonly_fields = ("user_with_link", "mt4_id", "group_name")

    date_hierarchy = "creation_ts"

    user_with_link = with_link("user")
    registered_from_partner_domain_with_link = with_link(
        "registered_from_partner_domain")
    actions = [
        'mark_deleted',
    ]

    def mark_deleted(self, request, queryset):
        queryset.update(is_deleted=True)

    mark_deleted.short_description = u'Пометить как удаленные'  # type: ignore
Exemple #2
0
class VoiceDeviceAdmin(ViewLoggingAdmin):

    fieldsets = [
        ('Identity', {
            'fields': ['user', 'phone_number', 'is_deleted'],
        }),
    ]
    raw_id_fields = ("user", )
    readonly_fields = "phone_number",
    search_fields = ("user__username", "user__accounts__mt4_id", "user__pk")
    list_filter = ("is_deleted", )
    list_display = ('id', 'user_link', 'creation_ts', "is_deleted")
    ordering = ('-creation_ts', )

    user_link = with_link("user", u"User")
Exemple #3
0
class UserDocumentAdmin(BaseAdmin):
    form = UserDocumentAdminForm
    list_display = ('id', 'user_with_link', 'file_with_link', 'description',
                    'creation_ts')
    fields = ('user', 'name', 'file', 'description', 'fields', 'is_deleted',
              'is_rejected')
    search_fields = ('user__username', 'user__email', 'description')
    raw_id_fields = ('user', )
    list_filter = ('name', )
    user_with_link = with_link("user", u"User")

    def file_with_link(self, obj):
        return "<a href='/uploads/%s'>%s</a>" % (obj.file,
                                                 obj.get_name_display())

    file_with_link.allow_tags = True
    file_with_link.short_description = u"File"
Exemple #4
0
class InternalTransferIssueAdmin(IssueAdmin):
    exclude = ("sender", )
    readonly_fields = IssueAdmin.readonly_fields + [
        "sender_with_link", "recipient", "amount"
    ]
    actions = ["make_transfer"]

    sender_with_link = with_link("sender")
    get_queryset = BaseAdmin.get_queryset

    @short_descr(_("Make transaction"))
    def make_transfer(self, request, qs):
        from transfers.forms import InternalTransferForm
        for issue in qs:
            form = InternalTransferForm(request=request,
                                        internal=True,
                                        data={
                                            "sender": issue.sender.pk,
                                            "recipient_manual":
                                            issue.recipient,
                                            "amount": issue.amount,
                                            "currency": issue.currency,
                                            "mode": "manual",
                                        })
            if form.is_valid() and form.save():
                issue.status = "closed"
                issue.save()
            else:
                from itertools import chain
                messages.error(
                    request, u"Failed to process request #%s: %s" %
                    (issue.pk, "; ".join(
                        map(unicode, chain(*form.errors.values())))))

    @descr(_("Mark select issues as rejected"))
    def make_rejected(self, request, queryset):
        super(self.__class__, self).make_rejected(request, queryset)
        for q in queryset:
            notification.send([q.sender.user], 'internaltransfer_reject')
Exemple #5
0
class OTPDeviceAdmin(admin.ModelAdmin):

    fieldsets = [
        ('Identity', {
            'fields': ['user', 'name', 'is_deleted'],
        }),
        ('Configuration', {
            'fields': ['key', 'step', 't0', 'digits', 'tolerance'],
        }),
        ('State', {
            'fields': ['drift'],
        }),
    ]
    raw_id_fields = ("user", )

    radio_fields = {'digits': admin.HORIZONTAL}
    search_fields = ("user__username", "user__accounts__mt4_id", "user__pk")
    list_filter = ("is_deleted", )
    list_display = ('id', 'user_link', 'creation_ts', "is_deleted")
    ordering = ('-creation_ts', )

    user_link = with_link("user", u"User")
Exemple #6
0
class LoggerAdmin(admin.ModelAdmin):

    date_hierarchy = "at"
    list_display = ('id', 'user_with_link', 'at', 'event', 'ip')
    search_fields = (
        'user__pk',
        'user__email',
        'ip',
    )
    raw_id_fields = ['user']
    list_filter = ("event", )
    fields = ('user_with_link', 'event', 'object_with_link', 'at', 'ip',
              'json_as_table')
    readonly_fields = [
        'event', 'ip', 'object_with_link', 'at', 'user_with_link',
        'json_as_table'
    ]

    user_with_link = with_link("user", name=_("User"))
    object_with_link = with_link("content_object", name=_("Changing object"))

    @descr(_("Information"))
    def json_as_table(self, object):

        if not object.params:
            return "&mdash;"

        params = dict(object.params)
        fields = OrderedDict()

        if "from" in params and "to" in params:
            if "field" in params:
                fields[u"Поле"] = params["field"]
                del params["field"]

            if isinstance(params["from"], basestring) and isinstance(
                    params["from"], basestring):
                diff_before, diff_now = show_differences(
                    unicode(params["from"]), unicode(params["to"]))
            else:
                diff_before, diff_now = params["from"], params["to"]

            fields[u"Значение"] = mark_safe("%(before)s -> %(now)s" % {
                "now": diff_now,
                "before": diff_before
            })

            del params["from"]
            del params["to"]

        replaces = {
            "field": u"Поле",
            "state": u"Область",
            "agent_code": u"Агентский код",
            "currency": u"Валюта",
            "amount": u"Сумма",
            "auto": u"Ручной перевод",
            "email": u"Адрес почты",
            "account_status": u"Статус",
            "equity": u"Эквити",
            "account_minimal_equity": u"Минимальное эквити",
            "alias": u"Название",
            "purse": u"Кошелек",
            "new_requisit_id": u"Новый реквизит",
        }

        for k, v in params.items():

            if k == "new_requisit_id":
                req = UserRequisit.objects.get(id=v)
                v = mark_safe("<a href='%s'>%s</a>" %
                              (get_admin_url(req), req))
            elif isinstance(v, dict):
                if k in ["state", "city", "country"]:
                    v = "%s -> %s" % (v["from"] or "None", v["to"] or "None")
                else:
                    diff_now, diff_before = show_differences(
                        v["to"], v["from"])
                    v = mark_safe("%(before)s -> %(now)s" % {
                        "now": diff_now,
                        "before": diff_before
                    })

            fields[replaces.get(k, k)] = v

        return render_to_string("log/json_as_table.html", {"fields": fields})
Exemple #7
0
class UserRequisitAdmin(BaseAdmin):

    list_display = ("purse", "user_with_link", "payment_system", "is_valid",
                    "is_deleted", "creation_ts", "previous_with_link")
    list_filter = (('payment_system', PaymentSystemFilter), "is_deleted",
                   "creation_ts")
    search_fields = ["user__username", "purse"]

    readonly_fields = ("user_with_link", "purse", "payment_system",
                       "previous_with_link", "creation_ts", "get_params")
    fieldsets = ((None, {
        "fields":
        ("user_with_link", "alias", ("purse", "payment_system",
                                     "previous_with_link"), "creation_ts",
         "is_valid", "comment", "get_params", "is_deleted")
    }), )

    user_with_link = with_link("user")
    previous_with_link = with_link("previous", "previous version of requisit")

    @descr(u"Кошелек")
    def maybe_purse(self, obj):
        if not obj.purse or re.match(r"[a-z0-9]{32}", obj.purse):
            return mark_safe(u"&mdash;")
        else:
            return obj.purse

    def save_model(self, request, obj, form, change):
        obj.save()
        if 'is_valid' in obj.changes:
            Logger(user=request.user,
                   content_object=obj,
                   ip=request.META["REMOTE_ADDR"],
                   event=Events.REQUISIT_VALIDATION_UPDATE,
                   params={
                       'is_valid': obj.is_valid
                   }).save()

    def get_params(self, obj):
        try:
            if obj.get_params():
                res = ["<table>"]
                if obj.previous:
                    res.append(u"<thead><tr><th>Название</th>"
                               u"<th>В этом реквизите</th>"
                               u"<th class='prev'>Ранее</th></tr>")

                    for (k, v), (k_prev, v_prev) in zip(
                            obj.get_params().iteritems(),
                            obj.previous.get_params().iteritems()):
                        key = v.key
                        v = v.value
                        v_prev = v_prev.value

                        if key in ["country", "correspondent"]:
                            # обычно для стран и банка-корреспондента бессмысленно считать
                            # изменения посимвольно, так что выделяем сразу все слово
                            if v != v_prev:
                                v = u"<span class='replace'>%s</span>" % v
                                v_prev = u"<span class='replace'>%s</span>" % v_prev
                        else:
                            v, v_prev = show_differences(v, v_prev)

                        res.append(
                            u"<tr><td>%s</td><td>%s</td><td class='prev'>%s</td></tr>"
                            % (unicode(k), v, v_prev))
                else:
                    res.append(
                        u"<thead><tr><th>Параметр</th><th>В этом реквизите</th></tr>"
                    )
                    for k, v in obj.get_params().iteritems():
                        if v.key == "country":
                            v = get_country(v.value)
                        else:
                            v = v.value
                        res.append(u"<tr><td>%s</td><td>%s</td></tr>" %
                                   (unicode(k), v))
                value = "".join(res + [u"</table>"])
            else:
                value = u"&mdash;"

            return mark_safe(value)
        except Exception as e:
            pass
Exemple #8
0
class IndicatorEventAdmin(admin.ModelAdmin):
    form = make_ajax_form(IndicatorEvent, {'indicator': 'indicator'})
    list_display = ('title', 'event_date', 'indicator_with_link')
    list_filter = ('importance', )

    indicator_with_link = with_link('indicator', _("Indicator"))