예제 #1
0
 def save(self, *args, **kwargs):
     if not self.pk and self.is_active(self.instance):
         raise RequestLimitExceeded(
                 "The number of open requests for "
                 "instance %s has been exceeded."
                 % self.instance.provider_alias)
     Model.save(self, *args, **kwargs)
예제 #2
0
파일: views.py 프로젝트: flesser/OpenSlides
    def post(self, request, *args, **kwargs):
        if not request.user.has_perm('agenda.can_manage_agenda'):
            messages.error(
                request,
                _('You are not authorized to manage the agenda.'))
            context = self.get_context_data(**kwargs)
            return self.render_to_response(context)

        transaction.commit()
        for item in Item.objects.all():
            form = ItemOrderForm(request.POST, prefix="i%d" % item.id)
            if form.is_valid():
                try:
                    parent = Item.objects.get(id=form.cleaned_data['parent'])
                except Item.DoesNotExist:
                    parent = None
                item.weight = form.cleaned_data['weight']
                item.parent = parent
                Model.save(item)
            else:
                transaction.rollback()
                messages.error(
                    request, _('Errors when reordering of the agenda'))
                break
        else:
            Item.objects.rebuild()
            # TODO: assure, that it is a valid tree
        context = self.get_context_data(**kwargs)
        transaction.commit()

        if get_active_slide()['callback'] == 'agenda':
            update_projector()
        context = self.get_context_data(**kwargs)
        transaction.commit()
        return self.render_to_response(context)
예제 #3
0
def recache_lat_long(apps, schema_editor):
    from issues.models import Issue as CurrentIssue
    Issue = apps.get_model('issues', 'Issue')
    for issue in Issue.objects.filter(location__isnull=False):
        issue._cache_location = CurrentIssue._cache_location
        issue._cache_location()
        Model.save(self=issue, update_fields=('lat', 'long'))
예제 #4
0
파일: utils.py 프로젝트: pombredanne/dezede
def enlarged_create(Model, filter_kwargs, commit=True):
    filter_kwargs, m2m_kwargs = separate_m2m_kwargs(Model, filter_kwargs)
    obj = Model(**filter_kwargs)
    if commit:
        obj.save()
    for k, v in m2m_kwargs.items():
        getattr(obj, k).add(*v)
    return obj
예제 #5
0
파일: models.py 프로젝트: berdario/bdblog
	def save(self, *args, **kwargs):
		self.ascii_tag = unidecode(self.tag)
		words = self.ascii_tag.split()
		known_words_list = known_words(words)
		for word in words:
			new_word = Word(word)
			if not new_word in known_words_list:
				new_word.save()
		Model.save(self, *args, **kwargs)
예제 #6
0
파일: atualizar.py 프로젝트: lucastx/vestat
def versao_1_2_2(cmd, *args):
    """
    Atualizações pra versão 1.2.2.

    Deve ser chamada após exportar o banco de dados pra um arquivo de
    dump JSON e remover o arquivo do banco de dados.

    Ações:

    - Cria um novo banco de dados e o superusuário padrão
    - Faz as conversões necessárias sobre o dump nos modelos que mudaram
    - Importa o dump convertido pro banco de dados
    - Carrega fixture de feriados bancários

    Argumentos da linha de comando:
        - dump_file: arquivo de dump do banco de dados na versão
          1.2.1
    """
    if len(args) != 1:
        raise CommandError("Uso: atualizar 1.2.2 <dump_file>\n\ndump: arquivo de dump do banco de dados anterior (JSON)")

    sync_and_evolve()
    criar_superusuario()

    print("Convertendo entradas no modelo antigo pro novo modelo...")

    novo_bd_json = converter(args[0])
    tmp_dump_filename = "fixture_convertida.json"

    print("Armazenando dados convertidos em {tmp_dump_filename}".format(**vars()))

    with open(tmp_dump_filename, "w") as tmp_dump_file:
        tmp_dump_file.write(novo_bd_json)

    print("Carregando dados convertidos no banco de dados...")

    call_command("loaddata", tmp_dump_filename)

    print("Removendo arquivo temporário...")
    os.remove(tmp_dump_filename)

    print("Carregando fixture de feriados bancários...")
    call_command("loaddata", "feriados_bancarios")

    print("Reunindo arquivos estáticos...")
    call_command("collectstatic", interactive=False)

    print("Re-salvando os pagamentos com cartões pra preencher data de depósito")
    for pagamento in PagamentoComCartao.objects.all():
        pagamento.data_do_deposito = pagamento._data_do_deposito()
        Model.save(pagamento)
예제 #7
0
def rename_all_files():
    """
    Rename the data files according to the scheme:
    yyyy/mm/dd/id.h5
    """
    for curve in CurveDB.objects.all():
        full_name_old = curve.get_full_filename()
        new_name = osp.join(
                    curve.params["date"].strftime('%Y/%m/%d'),
                    str(curve.id) + '.h5')
        curve.data_file = new_name
        if not osp.exists(full_name_old):
            print 'file ' + full_name_old + " doesn't exist"
        else:
            shutil.move(full_name_old, curve.get_full_filename())
        Model.save(curve)
        
예제 #8
0
파일: daemon.py 프로젝트: Smarsh/norc
 def save(self, *args, **kwargs):
     """Overwrites Model.save().
     
     We have to be very careful to never overwrite a request, so
     often the request must be read from the database prior to saving.
     The safe parameter being set to True enables this behavior.
     
     """
     if kwargs.pop('safe', False):
         self.request = type(self).objects.get(id=self.id).request
     return Model.save(self, *args, **kwargs)
예제 #9
0
def _django_save(self, *args, **kwargs):
    return Model.save(self, *args, **kwargs)