from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
from telemeta.models import *
from telemeta.util.unaccent import unaccent
from teleforma.models import *
import codecs
import xlrd
-
class Command(BaseCommand):
help = "Import users from a XLS file (see an example in example/data/"
args = "path"
first_row = 2
+ admin_email = 'webmaster@parisson.com'
def import_user(self, row):
- last_name = row[0].value
- first_name = row[1].value
- print first_name, last_name
+ last_name = row[0].value
+ first_name = row[1].value
+ email = row[9].value
+ #FIXME:
+ email = self.admin_email
+ username = slugify(first_name)[0] + '.' + slugify(last_name)
+
+ #FIXME: not for prod
+ user = User.objects.get(username=username)
+ user.delete()
+
+ user, created = User.objects.get_or_create(username=username, first_name=first_name,
+ last_name=last_name, email=email)
+
+
+ if created:
+ student = Student.objects.filter(user=user)
+ if not student:
+ student = Student(user=user)
+ student.iej, c = IEJ.objects.get_or_create(name=row[2].value)
+ student.training, c = Training.objects.get_or_create(code=row[3].value)
+ student.procedure, c = Procedure.objects.get_or_create(code=row[4].value)
+ student.written_speciality, c = Speciality.objects.get_or_create(code=row[5].value)
+ student.oral_speciality, c = Speciality.objects.get_or_create(code=row[6].value)
+ student.oral_1, c = Oral.objects.get_or_create(code=row[7].value)
+ student.oral_2, c = Oral.objects.get_or_create(code=row[8].value)
+ student.category, c = Category.objects.get_or_create(name=row[15].value)
+ address = row[10].value
+ p_code = row[11].value
+ city = row[12].value
+ tel = row[13].value
+ date = row[14].value
+
+ student.save()
+ print 'imported: ' + first_name + ' ' + last_name + ' ' + username
+
+
def handle(self, *args, **options):
file = args[0]
for i in range(self.first_row, len(col)):
self.import_user(sheet.row(i))
- print "Done, imported %s users" % str(i)
db_table = app_label + '_' + 'iej'
verbose_name = _('IEJ')
verbose_name_plural = _('IEJ')
+ ordering = ['name']
class Training(Model):
def __unicode__(self):
- return self.name
+ return self.code
class Meta:
db_table = app_label + '_' + 'training'
code = CharField(_('code'), max_length=255)
def __unicode__(self):
- return self.name
+ return self.code
class Meta:
db_table = app_label + '_' + 'procedure'
code = CharField(_('code'), max_length=255)
def __unicode__(self):
- return self.name
+ return self.code
class Meta:
db_table = app_label + '_' + 'speciality'
code = CharField(_('code'), max_length=255)
def __unicode__(self):
- return self.name
+ return self.code
class Meta:
db_table = app_label + '_' + 'oral'
{% if user.is_authenticated %}
<li><a href="/messages" class="green">{% trans "Messages" %}{% if postman_unread_count %} ({{ postman_unread_count }}){% endif %}</a></li>
- <li><a href="{% url telemeta-users %}" class="yellow">{% trans "Users" %}</a></li>
+ <li><a href="{% url teleforma-users %}" class="yellow">{% trans "Users" %}</a></li>
<li><a href="{% url telemeta-search-criteria %}" class="orange">{% trans "Advanced search" %}</a></li>
{% load telemeta_utils %}
{% load teleforma_tags %}
+{% if is_paginated %}
+<div class="pagination">
+<span class="page-links">
+{% if page_obj.has_previous %}
+<a href="{% url teleforma-users %}?page={{ page_obj.previous_page_number }}" class="component_icon button icon_previous">{% trans "Previous" %}</a>
+{% endif %}
+<span class="page-current">
+{% trans "Page" %} {{ page_obj.number }} {%trans "of" %} {{ page_obj.paginator.num_pages }}.
+</span>
+{% if page_obj.has_next %}
+<a href="{% url teleforma-users %}?page={{ page_obj.next_page_number }}" class="component_icon button icon_next">{% trans "Next" %}</a>
+{% endif %}
+</span>
+</div>
+{% endif %}
+
<div id="users">
<table class="listing" width="100%">
<thead>
- <tr><th>{% trans "User"%}</th>
+ <tr><th>{% trans "Last Name"%}</th>
<th>{% trans "First Name"%}</th>
- <th>{% trans "Last Name"%}</th>
+ <th>{% trans "User"%}</th>
<th>{% trans "Training"%}</th>
<th>{% trans "IEJ"%}</th>
<th>{% trans "Procedure"%}</th>
<th>{% trans "Written spe"%}</th>
<th>{% trans "Oral 1"%}</th>
<th>{% trans "Oral 2"%}</th>
- <th>{% trans "Synthesis note"%}</th>
+ <th>{% trans "Synthesis"%}</th>
<th>{% trans "Messages"%}</th>
</tr>
</thead>
<tbody id="spacing">
{% for user in users %}
<tr>
- <td><a href="{% url telemeta-profile-detail user.username %}">{{user.username}}</a></td>
- <td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
+ <td>{{ user.first_name }}</td>
+ <td><a href="{% url telemeta-profile-detail user.username %}">{{user.username}}</a></td>
+
{% if user.student.get %}
{% with user.student.get as student %}
- <td>{{ student.training }}</td>
- <td>{{ student.iej }}</td>
- <td>{{ student.procedure }}</td>
- <td>{{ student.oral_speciality }}</td>
- <td>{{ student.written_speciality }}</td>
- <td>{{ student.oral_1 }}</td>
- <td>{{ student.oral_2 }}</td>
+ <td>{{ student.training.code }}</td>
+ <td>{{ student.iej.name }}</td>
+ <td>{{ student.procedure.code }}</td>
+ <td>{{ student.oral_speciality.code }}</td>
+ <td>{{ student.written_speciality.code }}</td>
+ <td>{{ student.oral_1.code }}</td>
+ <td>{{ student.oral_2.code }}</td>
<td></td>
{% endwith %}
{% elif user.professor.get %}
--- /dev/null
+{% extends "telemeta/base.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
+
+{% block head_title %}{% trans "Users" %} - {{ block.super }}{% endblock %}
+
+{% block title %}
+ <img src="{% url telemeta-images "user_red.png" %}" alt="user" style="vertical-align:middle" /> {% trans "Users" %}
+{% endblock %}
+
+{% block content %}
+ {% if users %}
+ {% include "telemeta/inc/user_list.html" %}
+ {% else %}
+ <p class="help">{% trans "No users" %}</p>
+ {% endif %}
+{% endblock %}
# Postman
url(r'^messages/', include('postman.urls')),
+ url(r'^all_users/$', UsersView.as_view(), name="teleforma-users"),
# CSS+Images (FIXME: for developement only)
url(r'^teleforma/css/(?P<path>.*)$', 'django.views.static.serve',
from django.contrib.auth.forms import UserChangeForm
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.syndication.views import Feed
+from django.core.paginator import Paginator
from teleforma.models import *
from telemeta.views.base import *
context['room'] = media.course.chat_room
return context
+class UsersView(ListView):
+
+ model = User
+ template_name='telemeta/users.html'
+ context_object_name = 'users'
+ paginate_by = 12
+
+ def get_queryset(self):
+ return User.objects.all().order_by('last_name')