Beispiel #1
0
def otp_setup(request):
    confirmed_devices = list(devices_for_user(request.user, True))
    tfa_enabled = len(confirmed_devices) > 0
    if request.method == 'GET' and not tfa_enabled:
        unconfirmed_devices = list(devices_for_user(request.user, False))
        device = unconfirmed_devices[0]
        form = DeviceValidationForm(device)
        return render(request, 'otp_setup.html', {
            'device': device,
            'form': form,
        })
    elif request.method == 'POST':
        if request.POST.get(u'enable') and not tfa_enabled:
            device = TOTPDevice.objects.create(user=request.user,
                                               name=u'TOTP',
                                               confirmed=False)
            form = DeviceValidationForm(device)
            return render(request, 'otp_setup.html', {
                'device': device,
                'form': form,
            })
        elif request.POST.get(u'disable') and tfa_enabled:
            for device in confirmed_devices:
                device.delete()
            messages.success(
                request,
                u_(u'Disabled two-factor authentication for this account.'))
        else:
            messages.error(request, u_(u'Unknown error.'))
    return redirect('otp_status')
Beispiel #2
0
def otp_setup(request):
    confirmed_devices = list(devices_for_user(request.user, True))
    tfa_enabled = len(confirmed_devices) > 0
    if request.method == 'GET' and not tfa_enabled:
        unconfirmed_devices = list(devices_for_user(request.user, False))
        device = unconfirmed_devices[0]
        form = DeviceValidationForm(device)
        return render(request, 'otp_setup.html', {
            'device': device,
            'form': form,
        })
    elif request.method == 'POST':
        if request.POST.get(u'enable') and not tfa_enabled:
            device = TOTPDevice.objects.create(user=request.user,
                                               name=u'TOTP',
                                               confirmed=False)
            form = DeviceValidationForm(device)
            return render(request, 'otp_setup.html', {
                'device': device,
                'form': form,
            })
        elif request.POST.get(u'disable') and tfa_enabled:
            for device in confirmed_devices:
                device.delete()
            messages.success(request, u_(
                u'Disabled two-factor authentication for this account.'))
        else:
            messages.error(request, u_(u'Unknown error.'))
    return redirect('otp_status')
Beispiel #3
0
 def clean_download_path(self):
     download_path = self.cleaned_data['download_path']
     if Download_Ongoing.objects.all().count() > 0:
         if Download_Ongoing.objects.latest('id').active == True and Download_Ongoing.objects.latest('id').status != "Interrupted":
             raise forms.ValidationError(u_('Cannot change the download directory while downloading. Please wait for your download to finish.'), code='invalid')
     if download_path:
         if not os.path.exists(download_path):
             raise forms.ValidationError(u_('Indicated path could not be found. Please make sure you indicate the full directory path.'), code='invalid')
     return download_path
Beispiel #4
0
def Thumbnail(parser, token):
    bits = token.contents.split()
    username = None
    if len(bits) > 3:
        raise TemplateSyntaxError, u_(u"You have to provide only the size as \
            an integer (both sides will be equal) and optionally, the \
            username.")
    elif len(bits) == 3:
        username = bits[2]
    elif len(bits) < 2:
        bits.append(_settings.DEFAULT_AVATAR_WIDTH)
    return ResizedThumbnailNode(bits[1], username)
Beispiel #5
0
def Thumbnail(parser, token):
    bits = token.contents.split()
    username = None
    if len(bits) > 3:
        raise TemplateSyntaxError, u_(u"You have to provide only the size as \
            an integer (both sides will be equal) and optionally, the \
            username.")
    elif len(bits) == 3:
        username = bits[2]
    elif len(bits) < 2:
        bits.append(_settings.DEFAULT_AVATAR_WIDTH)
    return ResizedThumbnailNode(bits[1], username)
 def render(self, context):
     cancha=context['cancha']
     hora=context[self.hora]
     if self.dia == 'hoy':
         dia=date.today().day
     else:
         maniana=date.today()+timedelta(1)
         dia=maniana.day
     if cancha.esta_libre(hora, dia):
         estado=self.libre % { 'reservar': u_('Reservar'), 'cancha': cancha.id, 'dia': dia, 'hora': hora }
     else:
         estado=self.ocupada % { 'ocupada': u_('Ocupada') }
     return estado
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        super(FundingOfferSearchForm, self).__init__(*args, **kwargs)

        self.fields['organization'] = forms.MultipleChoiceField(
            choices=FundingOffer.objects.all().select_related('organization').values_list(
                'organization__pk', 'organization__name').distinct().order_by('organization__name'),
            required=False,
            label=_("Organizations")
        )

        self.fields['inv'] = forms.MultipleChoiceField(
            required=False,
            label=_("Sectors"),
            choices=[(i.lowerpathstring(), u'{} ({})'.format(i.name, i.count)) for i in
                     PropertyTag.objects.get(path="INV").get_children().annotate(
                         count=Count('fundingoffer_sector')).order_by('name') if i.count > 0]
        )
        self.fields['ben'] = forms.MultipleChoiceField(
            required=False,
            label=_("Beneficiaries"),
            choices=[(i.lowerpathstring(), u'{} ({})'.format(i.name, i.count)) for i in
                     PropertyTag.objects.get(path="BEN").get_children().annotate(
                         count=Count('fundingoffer_beneficiary')).order_by('name') if i.count > 0]
        )

        self.fields['act'] = forms.MultipleChoiceField(
            required=False,
            label=_("Activities"),
            choices=[(i.lowerpathstring(), u'{} ({})'.format(i.name, i.count)) for i in
                     PropertyTag.objects.get(path="ACT").get_children().annotate(
                         count=Count('fundingoffer_activity')).order_by('name') if i.count > 0]
        )

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-4'
        self.helper.field_class = 'col-lg-8'
        self.helper.form_method = 'get'
        self.helper.wrapper_class = 'form-group-sm col-lg-4 col-md-6 col-sm-12 row'
        self.helper.layout = Layout(
            Div(Fieldset(u_('Type and Keywords'),
                         Field('organization', wrapper_class=self.helper.wrapper_class),
                         Field('act', wrapper_class=self.helper.wrapper_class),
                         Field('inv', wrapper_class=self.helper.wrapper_class),
                         Field('ben', wrapper_class=self.helper.wrapper_class),
            ),
                Submit('search', u_('Search'), css_class="btn btn-info btn"),
                css_class='col-md-12 well'
            )
        )
Beispiel #8
0
def otp_setup_verify(request):
    if request.method == 'POST':
        unconfirmed_devices = list(devices_for_user(request.user, False))
        device = unconfirmed_devices[0]
        form = DeviceValidationForm(device, request.POST)
        if form.is_valid():
            device.confirmed = True
            device.save()
            messages.success(request, u_(
                u'Enabled two-factor authentication for this account.'))
        else:
            return redirect('otp_setup')
    else:
        messages.error(request, u_(u'Unknown error.'))
    return redirect('otp_status')
Beispiel #9
0
    def helper(self):
        helper = FormHelper()
        helper.form_class = 'form-horizontal datacenter-search-form'
        helper.label_class = 'col-lg-4'
        # self.helper.field_template = 'bootstrap3/layout/inline_field.html'
        helper.field_class = 'col-lg-8'
        wc = 'form-group-sm col-lg-6 col-md-6 col-sm-12 row'
        helper.wrapper_class = wc
        helper.form_method = 'get'

        helper.layout = Layout(

                Div(Fieldset(_('Search Projects'),
                             Field('name', wrapper_class=wc),
                             Field('act', css_class="", wrapper_class=wc),
                             Field('inv', css_class="", wrapper_class=wc),
                             Field('ben', css_class="", wrapper_class=wc),
                             Field('inactive', css_class="", wrapper_class=wc),
                             Field('status', css_class="", wrapper_class=wc),
                             Field('orgtype', css_class="applyselectize", wrapper_class=wc),
                             Field('enddateafter', css_class="datepicker", wrapper_class=wc),
                             Field('startdateafter', css_class="datepicker", wrapper_class=wc),
                             Field('pcode', wrapper_class=wc)
                             ),
                    Submit('search', u_('Search'), css_class="btn btn-success btn"),
                    )
        )

        return helper
Beispiel #10
0
def otp_setup_verify(request):
    if request.method == 'POST':
        unconfirmed_devices = list(devices_for_user(request.user, False))
        device = unconfirmed_devices[0]
        form = DeviceValidationForm(device, request.POST)
        if form.is_valid():
            device.confirmed = True
            device.save()
            messages.success(
                request,
                u_(u'Enabled two-factor authentication for this account.'))
        else:
            return redirect('otp_setup')
    else:
        messages.error(request, u_(u'Unknown error.'))
    return redirect('otp_status')
Beispiel #11
0
    def save(self):
        if self.desde.day != date.today().day:
            from utils import ntp_time
            from exceptions import NTPInvalidResponseError, NTPNoDataReturnedError, ReservaAntesDeHorarioError

            try:
                hora_ntp = ntp_time()
                ahora = datetime(hora_ntp.tm_year, hora_ntp.tm_mon, hora_ntp.tm_mday, hora_ntp.tm_hour, hora_ntp.tm_min)
            except Exception, e:
                print e
                ahora = datetime.now()
            if ahora.hour < 11:
                raise ReservaAntesDeHorarioError, u_(
                    u"Las reservas para el día siguiente se habilitan a las 11:50 hs de cada día."
                )
            elif ahora.hour == 11:
                if ahora.minute < 50:
                    raise ReservaAntesDeHorarioError, u_(
                        u"Las reservas para el día siguiente se habilitan a las 11:50 hs de cada día."
                    )
Beispiel #12
0
    def en_regla(self):
        # Si la ficha médica esta vencida.
        if self.vencimiento_ficha_medica < date.today():
            from exceptions import FichaMedicaVencidaError

            raise FichaMedicaVencidaError, u_(
                u"Lo sentimos, pero usted no tiene su ficha médica al día, por lo que no podemos permitirle reservar. Regularice su situación para poder continuar disfrutando de nuestro servicio. Muchas gracias."
            )
        # Si no está al día con las cuotas
        cuotas = Cuota.objects.all()[:2]
        al_dia = False
        for cuota in cuotas:
            if cuota == self.ultima_cuota_paga:
                al_dia = True
        if not al_dia:
            from exceptions import SocioDeudorError

            raise SocioDeudorError, u_(
                u"Usted tiene una deuda con el club, por favor regularice su situación para poder realizar reservas."
            )
        # Si está sancionado
        sancion = Sancion.objects.filter(socio=self.user, hasta__gt=date.today())
        print sancion
        if len(sancion) > 0:
            from exceptions import SocioSancionadoError

            raise SocioSancionadoError, u_(
                u"Lo sentimos, pero usted tiene una sanción en curso, la cual le impide realizar reservas. En menos de una semana podrá continuar disfrutando de nuestro servicio."
            )
        # Sino
        return True
def Thumbnail(parser, token):
    """
    The parser of the templatetag.

    Should get at least one argument, the filename. If you pass only one, will
try to get a default from DEFAULT_THUMBNAIL_SIZE from the settings module. If
it doesn't exist will default to a width of 150px.

    If you specify a size as well it will be used. In both cases it first tries
to split the string by 'x', if it's not possible uses the entire string. This
is useful because you can specify width and height or just the width.
    """
    bits = token.contents.split()
    if len(bits) in [2, 3]:
        if len(bits) == 3:
            if 'x' in bits[2]:
                dimensions = bits[2].split('x')
            else:
                dimensions = [bits[2], 0]
        else:
            if 'DEFAULT_THUMBNAIL_SIZE' in settings.get_all_members():
                if 'x' in settings.DEFAULT_THUMBNAIL_SIZE:
                    dimensions = settings.DEFAULT_THUMBNAIL_SIZE.split('x')
                else:
                    dimensions = [settings.DEFAULT_THUMBNAIL_SIZE, None]
            else:
                dimensions = [150, 0]

    else:
        raise TemplateSyntaxError, u_(u"thumb recieves two or three \
            arguments, the file to generate the thumbnail from and \
            optionally the size of the resulting thumbnail.")
    for dim in dimensions:
        try:
            int(dim)
        except:
            raise TemplateSyntaxError, u_(u"Tumbnail's size should be given \
                                            in píxels, as just integers.")
    return ResizedThumbnailNode(bits[1], dimensions)
Beispiel #14
0
    def helper(self):
        helper = FormHelper()
        helper.form_class = 'form-horizontal datacenter-search-form'
        helper.label_class = 'col-lg-2'
        # .helper.field_template = 'bootstrap3/layout/inline_field.html'
        helper.field_class = 'col-lg-10'
        helper.form_method = 'get'

        helper.layout = Layout(

                Div(Fieldset(_('Search Organizations'),
                             HTML('''<div class="btn-group"  data-toggle="button">
                              <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_act">
                                Activities
                              </a>
                              <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_ben">
                                Beneficiaries
                              </a>
                              <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_inv">
                                Sectors
                              </a>
                             <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_pcode">
                                Place
                              </a>
                                <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_orgtype">
                                Organization type
                              </a>
                                <a class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="collapse" href="#div_id_name">
                                Organization name
                              </a>
                            </div>'''),
                             Field('name', wrapper_class="collapse"),
                             Field('act', data_selecttwo='true', css_class='select2_auto', wrapper_class="collapse"),
                             Field('inv', data_selecttwo='true', css_class='select2_auto', wrapper_class="collapse"),
                             Field('ben', data_selecttwo='true', css_class='select2_auto', wrapper_class="collapse"),

                             Field('orgtype', wrapper_class="collapse"),
                             Field('pcode', wrapper_class="collapse"),
                             # Field('inactive'),
                             ),
                    Submit('search', u_('Search'), css_class="btn btn-success btn"),
                    )
        )

        return helper
Beispiel #15
0
    def helper(self):

        helper = FormHelper()
        helper.form_class = 'form-horizontal datacenter-search-form'
        helper.label_class = 'col-lg-4'
        helper.field_class = 'col-lg-8'
        helper.form_method = 'get'
        helper.wrapper_class = 'form-group-sm col-lg-6 col-md-6 col-sm-12 row'
        helper.layout = Layout(
                Fieldset(_("Search for Publications"),
                         Field('tag__id', wrapper_class=helper.wrapper_class,
                               data_selecturl="/selecttwo/library/tag/name/icontains/"),
                         Field('text', wrapper_class=helper.wrapper_class),
                         Field('organization', wrapper_class=helper.wrapper_class),
                         Field('sector__path', wrapper_class=helper.wrapper_class),
                         # Field('inv', wrapper_class=self.helper.wrapper_class),
                         Field('pubtype', wrapper_class=helper.wrapper_class),
                         Field('language_id', wrapper_class=helper.wrapper_class),
                         Field('year', wrapper_class=helper.wrapper_class, attrs={'maxItems': 2}),
                         Field('primary', wrapper_class=helper.wrapper_class),
                         ),
                Submit('search', u_('Search'), css_class="btn btn-success btn"),
        )
        return helper
Beispiel #16
0
def EstaLibre(parser, token):
    bits = token.contents.split()
    if len(bits) != 4:
        raise TemplateSyntaxError, u_(u'templatetag "estado_cancha" recibe tres parametros, "cancha", "hora" y "dia"')
    return EstaLibreNode(bits[1], bits[2], bits[3])