Exemple #1
0
def company_context(request):
    """Context processor referenced in settings.
    This puts the current company ID into any request context, 
    thus allowing templates to refer to it

    This is not a view.
    """
    
    company_id = utils.get_company(request)
    data = {'company_id': company_id}
    if company_id:
        try:
            company = Company.objects.get(pk=company_id)
            data.update({'company':company})
        except Company.DoesNotExist:
            pass 
    return data
Exemple #2
0
def company_context(request):
    """Context processor referenced in settings.
    This puts the current company ID into any request context, 
    thus allowing templates to refer to it

    This is not a view.
    """

    company_id = utils.get_company(request)
    data = {'company_id': company_id}
    if company_id:
        try:
            company = Company.objects.get(pk=company_id)
            data.update({'company': company})
        except Company.DoesNotExist:
            pass
    return data
Exemple #3
0
def upload_file(request, **config):
    file_type = config['file_type']

    context = {'file_type': file_type,}     
    form = FileForm(request.POST, request.FILES)

    if form.is_valid():
        upload = request.FILES.values()[0]
        file_name = upload._name
        file_name_with_timestamp = save_file(upload)
        company = utils.get_company(request)

        model = config.pop('model')
        unique = config.pop('unique')
        name_cleaner_path = config.pop('name_cleaner')
        value_cleaner_path = config.pop('value_cleaner')
        exclude_path = config.pop('exclude')
        post_process_path = config.pop('post_process')



        #result is zero if it was able to start the background task successfully.
        result, out, err = process_incoming_file(model, unique, name_cleaner, value_cleaner, exclude, post_process,
                                                 file_type=config['file_type'],
                                                 file_name=file_name_with_timestamp,
                                                 company=company,
                                                 task_title="%s data for %s" % (file_type, company),
                                                 task_success_url=reverse('upload_complete'),
                                                 )

        if result != 0:
            context.update({'file_name': file_name, 'success': False, 'out': out, 'err': err})
            messages.error(request, 'Could not process the file provided, please see below')
            return render(request, 'uploaded.html', context)
        else:
            return HttpResponseRedirect(reverse('task_result', kwargs={'pid':out,}))
    else:
        context.update({'file_name': file_name, 'success': False, 'out': out, 'err': err})
        messages.error(request, 'Could not process the file provided, please see below')
        return render(request, 'uploaded.html', context)
Exemple #4
0
def upload_file(request, **config):
    file_type = config['file_type']

    context = {
        'file_type': file_type,
    }
    form = FileForm(request.POST, request.FILES)

    if form.is_valid():
        upload = request.FILES.values()[0]
        file_name = upload._name
        file_name_with_timestamp = save_file(upload)
        company = utils.get_company(request)

        model = config.pop('model')
        unique = config.pop('unique')
        name_cleaner = config.pop('name_cleaner')
        value_cleaner = config.pop('value_cleaner')
        exclude = config.pop('exclude')
        post_process = config.pop('post_process')

        #result is zero if it was able to start the background task successfully.
        result, out, err = process_incoming_file(
            model,
            unique,
            name_cleaner,
            value_cleaner,
            exclude,
            post_process,
            file_type=config['file_type'],
            file_name=file_name_with_timestamp,
            company=company,
            task_title="%s data for %s" % (file_type, company),
            task_success_url=reverse('upload_complete'),
        )

        if result != 0:
            context.update({
                'file_name': file_name,
                'success': False,
                'out': out,
                'err': err
            })
            messages.error(
                request,
                'Could not process the file provided, please see below')
            return render_to_response('uploaded.html',
                                      context,
                                      context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect(
                reverse('task_result', kwargs={
                    'pid': out,
                }))
    else:
        context.update({
            'file_name': file_name,
            'success': False,
            'out': out,
            'err': err
        })
        messages.error(
            request, 'Could not process the file provided, please see below')
        return render_to_response('uploaded.html',
                                  context,
                                  context_instance=RequestContext(request))
Exemple #5
0
def add_datauser(request):

	errors={}

	if request.POST:
		
		companies = {}
		storage = ""
		for i in request.POST.keys():
			if ("food" in i) or ("weapon" in i):
				quality_v = i[len(i)-1:]
				key = i[:len(i)-1]

				util.set_dict(companies,key,quality_v,request.POST[i])

		if "q_storage" in request.POST:
			storage = request.POST["q_storage"]
		name = request.POST["name"]
		er = request.POST["url_or_id"]
		er_id =0 
		url_citizen = ""
		error = False
		val = URLValidator()
		try:
		    val(er)
		    if er.index("erepublik.com/en/citizen/profile/") > -1:
		    	url_citizen = er
		    	er_id = er.split("/").pop()
		except Exception, e:
			errors['url'] = "url invalid"

		if util.is_int(er) and int(er) >0:
			er_id = er
			url_citizen = "http://www.erepublik.com/en/citizen/profile/"+er_id
		else:
			errors['id citizen'] = "id invalid"

		if er_id == 0 and len(url_citizen)>0:
			error = True

		else:
			error = False
			errors ={}

		if not error:
			try:

				cit=Citizen(name=name,citizen_id_er=er_id,url_citizen=url_citizen)
				cit.save()
				
				Tg = TraningGround(owner_citizen=cit)
				Tg.weights_room    = request.POST['TG1']
				Tg.climbing_center = request.POST['TG2']
				Tg.shooting_range  = request.POST['TG3']
				Tg.special_forces  = request.POST['TG4']
				Tg.save()

				sto=Storage(owner_citizen=cit)

				if(storage <> "" and  util.is_int(storage)):
					sto.quantity=int(storage)
			
				sto.save()
				for key in companies:
					company = util.get_company(companies[key])
					company.owner_citizen = cit
					company.save()
				
	
			except DatabaseError as e:
				transaction.rollback()
				errors[e.errno]=e.strerror
			except ValidationError as e:
				transaction.rollback()
				errors[e.errno]=e.strerror