Exemplo n.º 1
0
def confirm_refund_deposit(modeladmin, request, queryset: QuerySet):
    """
    Confirmation page for the "Refund Deposits to Sender" page.
    :param modeladmin:
    :param request:
    :param queryset:
    :return:
    """
    rp = request.POST
    deps = []
    for d in queryset:  # type: Deposit
        if empty(d.from_account):
            add_message(
                request, messages.ERROR,
                f'Cannot refund deposit ({d}) - from_account is blank!')
            continue
        deps.append(d)

    if len(deps) < 1:
        add_message(
            request, messages.ERROR,
            'No valid refundable deposits selected. Only deposits with from_account can be refunded.'
        )
        return redirect('/admin/payments/deposit/')

    return TemplateResponse(
        request, "admin/refund.html", {
            'deposits': deps,
            'action': rp.get('action', ''),
            'select_across': rp.get('select_across', ''),
            'index': rp.get('index', ''),
            'selected_action': rp.get('_selected_action', ''),
        })
Exemplo n.º 2
0
def user_edit(request,uid):
    '''用户管理页'''
    tmptag = True
    users = User.objects.get(id=uid)
    if request.method == 'POST':
        users.email = request.POST.get('email')
        oldpassword = request.POST.get('pre_password')
        newpassword = request.POST.get('password')
        repassword = request.POST.get('repassword')
        user = authenticate(username=users.username,password=oldpassword)
        if user:
            if newpassword is not None:
                if newpassword == repassword:
                    user.set_password(newpassword)
                else:
                    messages.add_message(request, message.INFO, _(u'两次输入的密码不一致'))
                    tmptag = False
            if request.POST.get('is_staff') == "on":
                users.is_staff = True
            else:
                users.is_staff = False
            if request.POST.get('is_active') == "on":
                users.is_active = True
            else:
                users.is_active = False
            users.save()
            if tmptag:
                return HttpResponseRedirect(reverse('manager'))
            else:
                pass
    t = get_template('systack/user_edit.html')
    c = RequestContext(request,locals())
    return HttpResponse(t.render(c))
Exemplo n.º 3
0
 def form_invalid(self, form, msg=None, msg_level=None, **kwargs):
     msg_level = msg_level or constants.ERROR
     msg = msg or self.get_message(msg_level)
     add_message(self.request, msg_level, msg)
     return self.render_to_response(
         self.get_context_data(form=form,
                               msg=msg,
                               msg_level=msg_level,
                               **kwargs))
Exemplo n.º 4
0
 def form_invalid(self,
                  form,
                  inline_form_views,
                  inline_views,
                  msg=None,
                  msg_level=constants.ERROR):
     msg = msg or self.get_message('error')
     add_message(self.request, msg_level, msg)
     return self.render_to_response(
         self.get_context_data(form=form,
                               inline_views=inline_views,
                               inline_form_views=inline_form_views))
Exemplo n.º 5
0
def validate_login(request, username, password):
    '''验证用户登录'''
    return_value = False
    user = authenticate(username=username,password=password)
    if user:
        if user.is_active:
            auth_login(request,user)
            return_value = True
        else:
            messages.add_message(request, message.INFO, _(u'此账户尚未激活,请联系管理员'))
    else:
        messages.add_message(request, message.INFO, _(u'此账户不存在,请联管理员'))
    return return_value
Exemplo n.º 6
0
 def success_render_to_response(self, obj, msg, msg_level):
     msg_level = msg_level or constants.SUCCESS
     msg = msg or self.get_message(msg_level, obj)
     if self.is_popup_form:
         return JsonHttpResponse({'messages': {msg_level: msg}, 'obj': self.get_popup_obj(obj)})
     elif self.is_ajax_form:
         add_message(self.request, msg_level, msg)
         location = self.get_success_url(obj)
         response = JsonHttpResponse({'location': location}, status=202)
         response['Location'] = location
         return response
     else:
         add_message(self.request, msg_level, msg)
         return HttpResponseRedirect(self.get_success_url(obj))
Exemplo n.º 7
0
 def success_render_to_response(self, obj, msg, msg_level):
     msg_level = msg_level or constants.SUCCESS
     msg = msg or self.get_message(msg_level, obj)
     if self.is_popup_form:
         return JsonHttpResponse({'messages': {msg_level: msg}, 'obj': self.get_popup_obj(obj)})
     elif self.is_ajax_form:
         add_message(self.request, msg_level, msg)
         location = self.get_success_url(obj)
         response = JsonHttpResponse({'location': location}, status=202)
         response['Location'] = location
         return response
     else:
         add_message(self.request, msg_level, msg)
         return HttpResponseRedirect(self.get_success_url(obj))
Exemplo n.º 8
0
def login_as_user(request, user_id):
    if (request.user.is_authenticated and
            request.user.is_staff and
            request.user.groups.filter(name='CAN_LOGIN_AS_OTHER_USER').first()
    ):
        user = get_object_or_404(User, id=user_id)
        logout(request)
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        login(request, user)
        add_message(request, messages.SUCCESS, "You just switched to user {} with email {}".format(
            user.username, user.email
        ))
        return redirect('ct:home')
    else:
        raise Http404("This action is not allowed")
Exemplo n.º 9
0
def user_login(request):
    if request.method == 'POST':
        redirect_url = request.POST.get('next', reverse('calendar'))
        form = AuthenticationForm(request, data=request.POST)
        if form.is_valid():
            login(request, form.get_user())
            return redirect(redirect_url)
        else:
            add_message(request, ERROR, _('WRONG_USERNAME_OR_PASSWORD'))
            data = {
                'login_form': AuthenticationForm(request),
                'static_version': STATIC_VERSION,
                'is_debug' : settings.DEBUG,
            }
            return render(request, 'login.html', data)
    return redirect(reverse('calendar'))
Exemplo n.º 10
0
def user_login(request):
    if request.method == 'POST':
        redirect_url = request.POST.get('next', reverse('calendar'))
        form = AuthenticationForm(request, data=request.POST)
        if form.is_valid():
            login(request, form.get_user())
            return redirect(redirect_url)
        else:
            add_message(request, ERROR, _('WRONG_USERNAME_OR_PASSWORD'))
            data = {
                'login_form': AuthenticationForm(request),
                'static_version': STATIC_VERSION,
                'is_debug': settings.DEBUG,
            }
            return render(request, 'login.html', data)
    return redirect(reverse('calendar'))
Exemplo n.º 11
0
def make_published(modeladmin, request, queryset):
    """Action for administrative interface to publish.

    Note that this is intentionally implemented in a less efficient way; this could be
    done with a QuerySet method of::

      queryset.update(status='published')

    However, this does not emit post_save events, which are needed by our search indexing
    system---so we do it in a less-efficient way that does trigger this required update.
    """

    with transaction.atomic():
        for o in queryset.all():
            o.status = 'published'
            try:
                o.full_clean()
                o.save()
            except ValidationError as e:
                # We can't publish this, so we'll let the user know via messages
                add_message(
                    request, messages.ERROR, "Could not publish %s (%s): %s" %
                    (str(o), o.pk, ", ".join(e.messages)))
Exemplo n.º 12
0
 def get_redirect_url(self, *args, **kwargs):
     add_message(self.request, self.message_type or constants.SUCCESS, self.message)
     return super(FlashRedirectView, self).get_redirect_url(*args, **kwargs)
Exemplo n.º 13
0
 def form_invalid(self, form, msg=None, msg_level=constants.ERROR):
     msg = msg or self.get_message('error')
     add_message(self.request, msg_level, msg)
     return self.render_to_response(self.get_context_data(form=form))
Exemplo n.º 14
0
 def form_invalid(self, form, msg=None, msg_level=None, **kwargs):
     msg_level = msg_level or constants.ERROR
     msg = msg or self.get_message(msg_level)
     add_message(self.request, msg_level, msg)
     return self.render_to_response(self.get_context_data(form=form, msg=msg, msg_level=msg_level, **kwargs))
Exemplo n.º 15
0
def user_logout(request):
    redirect_url = request.GET.get('next', reverse('calendar'))
    logout(request)
    add_message(request, INFO, _('LOGGED_OUT'))
    return redirect(redirect_url)
Exemplo n.º 16
0
def refund_deposits(request):
    rp = request.POST
    objlist = rp.getlist('objects[]')
    if empty(rp.get('refund')) or empty(objlist, itr=True):
        log.info('Refund value: %s - Objects: %s', rp.get('refund'), objlist)
        add_message(request, messages.ERROR,
                    f'Error - missing POST data for refund_deposits!')
        return redirect('/admin/payments/deposit/')

    deposits = Deposit.objects.filter(id__in=objlist)
    for d in deposits:  # type: Deposit
        try:
            if empty(d.from_account):
                add_message(
                    request, messages.ERROR,
                    f'Cannot refund deposit ({d}) - from_account is blank!')
                continue
            with transaction.atomic():
                log.info('Attempting to refund deposit (%s)', d)

                convs = Conversion.objects.filter(deposit=d)

                if len(convs) > 0:
                    for conv in convs:
                        log.info('Removing linked conversion %s', conv)
                        add_message(request, messages.WARNING,
                                    f'Removed linked conversion {str(conv)}')
                        conv.delete()

                sym = d.coin_symbol
                memo = f'Refund of {sym} deposit {d.txid}'

                log.debug('Initializing manager for %s', sym)
                mgr = get_manager(sym)

                log.debug(
                    'Calling send_or_issue for amount "%s" to address "%s" with memo "%s"',
                    d.amount, d.from_account, memo)

                res = mgr.send_or_issue(amount=d.amount,
                                        address=d.from_account,
                                        memo=memo)

                d.status = 'refund'
                d.refunded_at = timezone.now()
                d.refund_coin = res.get('coin', sym)
                d.refund_memo = memo
                d.refund_amount = res.get('amount', d.amount)
                d.refund_address = d.from_account
                d.refund_txid = res.get('txid', 'N/A')
                d.save()

                add_message(
                    request, messages.SUCCESS,
                    f'Successfully refunded {d.amount} {sym} to {d.from_account}'
                )
        except Exception as e:
            d.status = 'err'
            d.error_reason = f'Error while refunding: {type(e)} {str(e)}'
            log.exception('Error while refunding deposit %s', d)
            d.save()
            add_message(
                request, messages.ERROR,
                f'Error while refunding deposit ({d}) - Reason: {type(e)} {str(e)}'
            )
    return redirect('/admin/payments/deposit/')
Exemplo n.º 17
0
def user_logout(request):
    redirect_url = request.GET.get('next', reverse('calendar'))
    logout(request)
    add_message(request, INFO, _('LOGGED_OUT'))
    return redirect(redirect_url)
Exemplo n.º 18
0
 def get_redirect_url(self, *args, **kwargs):
     add_message(self.request, self.message_type or constants.SUCCESS,
                 self.message)
     return super(FlashRedirectView, self).get_redirect_url(*args, **kwargs)