15/08
This commit is contained in:
parent
2e886b15d4
commit
e01e7b624e
8 changed files with 311 additions and 9 deletions
7
charts/forms.py
Normal file
7
charts/forms.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from .models import *
|
||||
from django import forms
|
||||
|
||||
class CoinForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Coin
|
||||
fields = ['name', 'date', 'priceusd', 'pricebtc', 'inflation', 'transactions', 'hashrate', 'supply', 'fee', 'revenue', 'blocksize', 'difficulty']
|
|
@ -19,6 +19,7 @@ class Coin(models.Model):
|
|||
revenue = models.FloatField(default="0")
|
||||
blocksize = models.FloatField(default="0")
|
||||
difficulty = models.FloatField(default="0")
|
||||
|
||||
def __str__(self):
|
||||
return self.priceusd
|
||||
|
||||
|
|
204
charts/templates/charts/add_coin.html
Normal file
204
charts/templates/charts/add_coin.html
Normal file
|
@ -0,0 +1,204 @@
|
|||
{% extends "users/base.html" %}
|
||||
{% block header %}
|
||||
|
||||
<title>Moneroj.net - New Article</title>
|
||||
|
||||
<style>
|
||||
.form button {
|
||||
font-family: "Roboto", Sans-serif;
|
||||
outline: 0;
|
||||
background: #ff4d21;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
cursor: pointer
|
||||
}
|
||||
|
||||
.form button:hover {
|
||||
background: #d53b14;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<br><br><br>
|
||||
<div class="container">
|
||||
|
||||
{% if message %}
|
||||
<div class="alert alert-warning">
|
||||
<strong>
|
||||
<center>{{ message }}</center>
|
||||
</strong>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h2>Add a new coin:</h2><br>
|
||||
<form class="needs-validation form" action="{% url 'charts:add_coin' %}" method='POST' novalidate>
|
||||
{% csrf_token %}
|
||||
<div class="form-row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" class="form-control" name="name" id="id_name" placeholder="Example: xmr" required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="date">Date:</label>
|
||||
<input type="date" class="form-control" name="date" id="id_date" placeholder="Example: 2022-01-01" required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="priceusd">Price USD:</label>
|
||||
<input type="number" class="form-control" name="priceusd" id="id_priceusd" placeholder="Example: 200,00"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="pricebtc">Price BTC:</label>
|
||||
<input type="number" class="form-control" name="pricebtc" id="id_pricebtc" placeholder="Example: 0,016"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="inflation">Inflation:</label>
|
||||
<input type="number" class="form-control" name="inflation" id="id_inflation" placeholder="Example: 0,86%"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="transactions">Transactions:</label>
|
||||
<input type="number" class="form-control" name="transactions" id="id_transactions" placeholder="Example: 40000"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="hashrate">Hashrate:</label>
|
||||
<input type="number" class="form-control" name="hashrate" id="id_hashrate" placeholder="Example: 150000000"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="supply">Supply:</label>
|
||||
<input type="number" class="form-control" name="supply" id="id_supply" placeholder="Example: 21000000" required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="difficulty">Difficulty:</label>
|
||||
<input type="text" class="form-control" name="difficulty" id="id_difficulty" placeholder="Example: 00000000"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="fee">Fee:</label>
|
||||
<input type="number" class="form-control" name="fee" id="id_fee" placeholder="Example: 150 xmr" required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="revenue">Revenue:</label>
|
||||
<input type="number" class="form-control" name="revenue" id="id_revenue" placeholder="Example: 150 xmr"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="blocksize">Blocksize:</label>
|
||||
<input type="number" class="form-control" name="blocksize" id="id_blocksize" placeholder="Example: 15 kb"
|
||||
required>
|
||||
<div class="valid-tooltip">
|
||||
OK
|
||||
</div>
|
||||
<div class="invalid-tooltip">
|
||||
This field is required
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label for="text">Save:</label>
|
||||
<button class="" type="submit">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<br><br>
|
||||
</div>
|
||||
|
||||
|
||||
<br><br><br>
|
||||
|
||||
{% endblock %}
|
|
@ -109,6 +109,7 @@ urlpatterns = [
|
|||
path('importer/', views.importer, name='importer'),
|
||||
path('reset/<str:symbol>/', views.reset, name='reset'),
|
||||
path('update/<str:date_from>/<str:date_to>/', views.update_database_admin, name='update'),
|
||||
path('add_coin/', views.add_coin, name="add_coin"),
|
||||
|
||||
# URLs to old functions in case they need to be restablished
|
||||
# Everyone can use these, but they are hidden
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.urls import reverse
|
|||
import requests
|
||||
import json
|
||||
from .models import *
|
||||
from .forms import *
|
||||
from users.models import PageViews
|
||||
from users.views import update_visitors
|
||||
import datetime
|
||||
|
@ -35,6 +36,53 @@ api = PushshiftAPI()
|
|||
# Useful functions for admins
|
||||
###########################################
|
||||
|
||||
# Add manually a new entrance for coin
|
||||
# To be used when there's a problem with the API
|
||||
@login_required
|
||||
def add_coin(request):
|
||||
if request.user.username != "Administrador" and request.user.username != "Morpheus":
|
||||
return render(request, 'users/error.html')
|
||||
|
||||
if request.method != 'POST':
|
||||
#create new page with blank form
|
||||
form = CoinForm()
|
||||
else:
|
||||
#process data and submit article
|
||||
form = CoinForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
add_coin = form.save(commit=False)
|
||||
|
||||
try:
|
||||
day = datetime.datetime.strftime(add_coin.date, '%Y-%m-%d')
|
||||
coin = Coin.objects.filter(name=add_coin.name).get(date=day)
|
||||
coin.delete()
|
||||
print('coin found and deleted')
|
||||
except:
|
||||
print('coin not found')
|
||||
pass
|
||||
|
||||
add_coin.stocktoflow = (100/add_coin.inflation)**1.65
|
||||
add_coin.save()
|
||||
print('coin saved')
|
||||
message = 'Coin added to the database!'
|
||||
|
||||
print(str(add_coin.name) + ' ' +str(add_coin.date) + ' ' +str(add_coin.priceusd) + ' ' +str(add_coin.pricebtc) + ' ' +str(add_coin.inflation) + ' ' +str(add_coin.name) + ' ' +str(add_coin.transactions) + ' ' +str(add_coin.hashrate) + ' ' +str(add_coin.stocktoflow) + ' ' +str(add_coin.supply) + ' ' + ' ' +str(add_coin.fee) + ' ' + ' ' +str(add_coin.revenue) )
|
||||
|
||||
print('updating p2pool')
|
||||
update_p2pool()
|
||||
|
||||
print('updating database')
|
||||
update_database(day, day)
|
||||
context = {'form': form, 'message': message}
|
||||
return render(request, 'charts/add_coin.html', context)
|
||||
else:
|
||||
message = 'An error has happened. Try again.'
|
||||
context = {'form': form, 'message': message}
|
||||
return render(request, 'charts/add_coin.html', context)
|
||||
|
||||
context = {'form': form}
|
||||
return render(request, 'charts/add_coin.html', context)
|
||||
|
||||
# Get all history for metrics of a certain coin named as 'symbol'
|
||||
# Only authorized users can download all price data via URL request
|
||||
@login_required
|
||||
|
@ -4128,7 +4176,7 @@ def sfmodel(request):
|
|||
yesterday = date.today() - timedelta(1)
|
||||
start_time = datetime.datetime.strftime(date.today() - timedelta(5), '%Y-%m-%d')
|
||||
try:
|
||||
coin = Coin.objects.filter(name='xmr').get(date=yesterday)
|
||||
coin = Coin.objects.filter(name='btc').get(date=yesterday)
|
||||
#coin_aux = Coin.objects.filter(name='btc').get(date=yesterday)
|
||||
if coin: #and coin_aux:
|
||||
print('coin found yesterday')
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
{% if user.username == 'Administrador' or user.username == 'Morpheus' %}
|
||||
<a class="nav-link" href="{% url 'articles:write' %}">Write / Review</a>
|
||||
<a class="nav-link" href="{% url 'users:users' %}">Users</a>
|
||||
<a class="nav-link" href="{% url 'users:users' %}">Control Panel</a>
|
||||
<a class="nav-link" href="{% url 'users:logout' %}">Logout</a>
|
||||
{% endif %}
|
||||
<a class="nav-link" href="{% url 'charts:about' %}">About</a>
|
||||
|
|
|
@ -2,12 +2,48 @@
|
|||
{% block header %}
|
||||
|
||||
<title>Moneroj.net - Users</title>
|
||||
<style>
|
||||
.break {
|
||||
word-break: break-all;
|
||||
}
|
||||
<style>
|
||||
.form {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background: #313030;
|
||||
margin: 20px 20px 20px 20px;
|
||||
max-width: 100%;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
border-radius: 20px
|
||||
}
|
||||
|
||||
.form button {
|
||||
font-family: "Roboto", Sans-serif;
|
||||
outline: 0;
|
||||
background: #ff4d21;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
cursor: pointer
|
||||
}
|
||||
|
||||
.form button:hover,
|
||||
.form button:active {
|
||||
background: #db3b13
|
||||
}
|
||||
|
||||
.form .message {
|
||||
margin: 10px 0 0;
|
||||
color: rgb(255, 255, 255);
|
||||
font-size: 16px
|
||||
}
|
||||
|
||||
.form .message a {
|
||||
color: #ff4d21;
|
||||
text-decoration: none
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
|
@ -15,10 +51,15 @@
|
|||
<section id="Subscribe" class="section-bg">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-xl-12 d-flex flex-column justify-content-center">
|
||||
<div class="col-xl-8 d-flex flex-column justify-content-center">
|
||||
<h1>Control Panel</h1>
|
||||
<h3>Edit user's profiles and access.</h3>
|
||||
</div>
|
||||
<div class="col-xl-3 form">
|
||||
<h1><i class="bx bx-pen" style="color: #ffffff"></i></h1>
|
||||
<p class="message">Problem with the API?</p><br>
|
||||
<a href="{% url 'charts:add_coin' %}"><button type="submit">Add a coin</button></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -169,4 +169,4 @@ def edit_user(request, identification, type):
|
|||
profile.type = type
|
||||
profile.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('users:users'))
|
||||
return HttpResponseRedirect(reverse('users:users'))
|
||||
|
|
Loading…
Reference in a new issue